views

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

README

views


    v := views.New(views.Config{
		Dir:        "./examples",
		Extensions: []string{".tmpl"},
		Compress:   true,
		Dev:        false,
	})

	v.Func(template.FuncMap{
		"tolower": strings.ToLower,
	})

	if err := v.Load(); err != nil {
		log.Fatalln("views load", err)
	}

	if err := v.Execute(os.Stdout, "child.tmpl", nil); err != nil {
		log.Fatalln("views Execute", err)
	}


PASS
coverage: 83.8% of statements
ok      views   0.279s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	//Dir specifies the path to the directory with templates
	Dir string

	//Extensions specifies what file extensions the templates have
	Extensions []string

	//Compress specifies whether to compress templates
	//true - compresses templates during parsing
	//false - does not compress templates
	Compress bool

	//Dev enable/disable development mode
	//true  - parses templates every time
	//false - parses templates once at the very beginning
	Dev bool
}

type Views

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

func New

func New(cfg Config) *Views

func (*Views) Execute

func (v *Views) Execute(wr io.Writer, name string, data interface{}) error

func (*Views) Func

func (v *Views) Func(fn template.FuncMap)

func (*Views) Load

func (v *Views) Load() error

Jump to

Keyboard shortcuts

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