recursive_parser

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

README

recursive-parser

Extends html/template by adding the ability to recursively parse dirs and files that are deeply nested within each other. In contrast to the default parsers: they cannot work with views nested in deep folder hierarchies.

Usage
// provide your views folder
p := recursive_parser.New(path.Join(cwd, "views"))

// name the root template
temp := template.New("views")

// walk recursively and use temp as root template to build upon
if err := p.Walk(temp); err != nil {
    t.Fatal(err)
}

var out bytes.Buffer // where to write

// execute `hello.html`, injecting it with data props and writing output to `out`
if err := temp.ExecuteTemplate(&out, "hello.html", map[string]string{"title": "yolo"}); err != nil {
    t.Fatal(err)
}

// flush the output as string
fmt.Printf("executed temp:\n%s\n", out.String())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

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

func New

func New(path string) *Parser

func (*Parser) Walk

func (p *Parser) Walk(root *template.Template) error

Jump to

Keyboard shortcuts

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