https://github.com/z3ntl3/recursive-parser
Enhances Go's html/template by enabling recursive parsing of deeply nested view directories.
https://github.com/z3ntl3/recursive-parser
go parse parser template templates templating
Last synced: about 1 year ago
JSON representation
Enhances Go's html/template by enabling recursive parsing of deeply nested view directories.
- Host: GitHub
- URL: https://github.com/z3ntl3/recursive-parser
- Owner: Z3NTL3
- License: gpl-3.0
- Created: 2025-05-09T09:22:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-11T09:16:10.000Z (about 1 year ago)
- Last Synced: 2025-05-13T00:55:28.035Z (about 1 year ago)
- Topics: go, parse, parser, template, templates, templating
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# recursive-parser
Extends [html/template](https://pkg.go.dev/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
```go
// 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())
```