html: github.com/101loops/html Index | Files

package html

import "github.com/101loops/html"

Index

Package Files

error.go funcs.go load.go parse.go set.go view.go

type Config Uses

type Config struct {

    // Directories define the file paths to search for templates,
    // ordered by descending priority.
    Directories []string

    // AutoReload is whether the templates should be reloaded on rendering.
    // This is useful in development, but should be disabled in production.
    AutoReload bool

    // DelimLeft is the delimiter that marks the start of a template action.
    DelimLeft string

    // DelimRight is the delimiter that marks the stop of a template action.
    DelimRight string
}

Config controls the behaviour of the template loading and rendering.

type Loader Uses

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

Loader collects the available template sources. It creates new sets and triggers the template parsing.

func NewLoader Uses

func NewLoader(conf Config) (l *Loader, err error)

NewLoader creates a new loader. It scans the provided source directories and collects all available template sources.

func (*Loader) AddFile Uses

func (l *Loader) AddFile(name, filePath string) *Loader

AddFile adds a file-based template source. It overwrites any existing source with the same name.

func (*Loader) AddText Uses

func (l *Loader) AddText(name string, content string) *Loader

AddText adds a text-based template source. It overwrites any existing source with the same name.

func (*Loader) NewSet Uses

func (l *Loader) NewSet() *Set

NewSet returns a new initialized set.

func (*Loader) Sources Uses

func (l *Loader) Sources() []*Source

Sources returns the sources found by scanning the provided directories.

type Set Uses

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

Set is a collection of template sources. It allows to create a View from its sources.

func (*Set) Add Uses

func (s *Set) Add(files ...string) *Set

Add appends a template source, identified by its file path, to the set. A copy of the set is returned.

func (*Set) AddFunc Uses

func (s *Set) AddFunc(name string, fn interface{}) *Set

AddFunc appends a named function to the set's function map. It is legal to overwrite elements of the map. A copy of the set is returned.

func (*Set) AddFuncs Uses

func (s *Set) AddFuncs(funcMap map[string]interface{}) *Set

AddFuncs appends the functions of the passed-in function map to the set's function map. It is legal to overwrite elements of the map. A copy of the set is returned.

func (*Set) AddSet Uses

func (s *Set) AddSet(set *Set) *Set

AddSet appends the template sources of another set to this one. A copy of the set is returned.

func (*Set) AddSets Uses

func (s *Set) AddSets(sets ...*Set) *Set

AddSets appends the template sources of other sets to this one. It returns a copy of the Set.

func (*Set) Funcs Uses

func (s *Set) Funcs() map[string]interface{}

Funcs returns a copy of the set's function map.

func (*Set) Set Uses

func (s *Set) Set(name, file string) *Set

Set appends a template source, identified by its file path and name, to the set. A copy of the set is returned.

func (*Set) Sources Uses

func (s *Set) Sources() []Source

Sources returns a copy of the set's template sources.

func (*Set) View Uses

func (s *Set) View() (*View, error)

View creates a new view from the set's template sources. If an error occurs, the returned view is nil.

func (*Set) ViewMust Uses

func (s *Set) ViewMust() *View

ViewMust creates a new view from the set's template sources. It panics if an error occurs.

type Source Uses

type Source struct {
    Content  string
    FilePath string
    Name     string
}

Source is a template data source. It contains an optional path to the source's file source.

type View Uses

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

A View can be rendered to HTML text.

func (*View) HTML Uses

func (v *View) HTML(data ...interface{}) (string, error)

HTML applies the parsed template to the specified data object, returning the result as a text.

func (*View) Write Uses

func (v *View) Write(wr io.Writer, data ...interface{}) error

Write applies the parsed template to the specified data object, writing the output to wr.

Package html imports 10 packages (graph). Updated 2018-02-17. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).