html

package
v0.0.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package html provides a HTML renderer.

Index

Constants

View Source
const (
	Extension      = ".htm"
	BlocksPrefix   = "blocks/"
	PartialsPrefix = "partials/"
	LayoutsPrefix  = "layouts/"
	PagesPrefix    = "pages/"

	DefaultLanguage     = "en"
	DefaultLayout       = "default"
	DefaultRobotsIndex  = true
	DefaultRobotsFollow = true
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	// contains filtered or unexported fields
}

Block represents a block in a template.

func NewBlock

func NewBlock(set *pongo2.TemplateSet, name string, content []byte, minify bool) (b *Block, err error)

NewBlock creates a new Block from the given content.

func (*Block) Render

func (b *Block) Render(writer io.Writer, variables pongo2.Context) error

Render renders the block with the given variables.

type Blocks

type Blocks map[string]*Block

type Html

type Html struct {
	*Options
	Blocks   Blocks
	Partials Partials
	Layouts  Layouts
	Pages    Pages
	// contains filtered or unexported fields
}

Html represents a HTML renderer.

func NewRender

func NewRender(options *Options) *Html

NewRender creates a new Html from the given directory.

func (*Html) Load

func (h *Html) Load() error

Load loads all templates from the given directory.

func (*Html) Render

func (h *Html) Render(writer io.Writer, template string, variables any, l ...string) error

Render renders the given template with the given variables.

type Layout

type Layout struct {
	Variables pongo2.Context `yaml:"Variables"`
	// contains filtered or unexported fields
}

Layout represents a layout in a template.

func NewLayout

func NewLayout(set *pongo2.TemplateSet, name string, content []byte, minify bool) (l *Layout, err error)

NewLayout creates a new Layout from the given content.

func (*Layout) Render

func (l *Layout) Render(writer io.Writer, variables pongo2.Context) error

Render renders the layout with the given page and variables.

type Layouts

type Layouts map[string]*Layout

type Option

type Option func(o *Options)

Option represents the service option.

func WithCache

func WithCache(value bool) Option

WithCache sets the cache for the options.

func WithDebug

func WithDebug(value bool) Option

WithDebug sets the debug for the options.

func WithDirectory

func WithDirectory(value string) Option

WithDirectory sets the directory for the options.

func WithFilters

func WithFilters(value map[string]pongo2.FilterFunction) Option

WithFilters sets the filters for the options.

func WithMinify

func WithMinify(value bool) Option

WithMinify sets the minify for the options.

func WithVariables

func WithVariables(value pongo2.Context) Option

WithVariables sets the variables for the options.

type Options

type Options struct {
	Directory string         `json:"directory" yaml:"Directory"`
	Debug     bool           `json:"debug"     yaml:"Debug"`
	Minify    bool           `json:"minify"    yaml:"Minify"`
	Cache     bool           `json:"cache"     yaml:"Cache"`
	Variables pongo2.Context `json:"variables" yaml:"Variables"`
	// contains filtered or unexported fields
}

Options represents a HTML renderer configuration.

func NewOptions

func NewOptions(options ...Option) *Options

NewOptions creates a new options.

type Page

type Page struct {
	Title                  string         `yaml:"Title"`
	Description            string         `yaml:"Description"`
	Keywords               []string       `yaml:"Keywords"`
	Language               string         `yaml:"Language"`
	Path                   string         `yaml:"Path"`
	Layout                 string         `yaml:"Layout"`
	Author                 string         `yaml:"Author"`
	RobotsIndex            bool           `yaml:"RobotsIndex"`
	RobotsFollow           bool           `yaml:"RobotsFollow"`
	Draft                  bool           `yaml:"Draft"`
	Static                 bool           `yaml:"Static"`
	SitemapChangeFrequency string         `yaml:"SitemapChangeFrequency"`
	SitemapPriority        float64        `yaml:"SitemapPriority"`
	CreatedAt              time.Time      `yaml:"CreatedAt"`
	UpdatedAt              time.Time      `yaml:"UpdatedAt"`
	Variables              pongo2.Context `yaml:"Variables"`
	// contains filtered or unexported fields
}

Page represents a page in a template.

func NewPage

func NewPage(set *pongo2.TemplateSet, name string, content []byte, minify bool) (p *Page, err error)

NewPage creates a new Page from the given content.

func (*Page) Render

func (p *Page) Render(writer io.Writer, variables pongo2.Context) error

Render renders the page with the given variables.

type Pages

type Pages map[string]*Page

type Partial

type Partial struct {
	// contains filtered or unexported fields
}

Partial represents a partial in a template.

func NewPartial

func NewPartial(set *pongo2.TemplateSet, name string, content []byte, minify bool) (p *Partial, err error)

NewPartial creates a new Partial from the given content.

func (*Partial) Render

func (p *Partial) Render(writer io.Writer, variables pongo2.Context) error

Render renders the partial with the given variables.

type Partials

type Partials map[string]*Partial

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL