tylermmorton / tmpl Goto Github PK
View Code? Open in Web Editor NEW`tmpl` is a wrapper around Go's html/template package that offers two-way static typing, template nesting and convenient workflow tooling for web developers.
License: MIT License
`tmpl` is a wrapper around Go's html/template package that offers two-way static typing, template nesting and convenient workflow tooling for web developers.
License: MIT License
Following the installation instructions from the README, I get the following error when installing the scaffolding utilities:
$ go version
go version go1.20.4 linux/amd64
$ go get github.com/tylermmorton/tmpl
go: downloading github.com/tylermmorton/tmpl v0.0.0-20230530043024-d2f4228318c2
go: added github.com/tylermmorton/tmpl v0.0.0-20230530043024-d2f4228318c2
$ go install github.com/tylermmorton/tmpl/cmd/tmpl
../../go/pkg/mod/github.com/tylermmorton/[email protected]/cmd/tmpl/cmd/bind.go:18:2: missing go.sum entry for module providing package github.com/spf13/cobra (imported by github.com/tylermmorton/tmpl/cmd/tmpl/cmd); to add:
go get github.com/tylermmorton/tmpl/cmd/tmpl/[email protected]
Hello
I have a problem when i'm using embed structs. Let me explain.
I have this code :
type TemplateReader struct {
filename string
}
func (t TemplateReader) TemplateText() string {
fileContent, err := os.ReadFile(t.filename)
if err != nil {
return "template not found: " + t.filename
}
return string(fileContent)
}
type Layout struct {
Class string
Body Test `tmpl:"body"`
TemplateReader
}
type Test struct {
}
func (*Test) TemplateText() string {
fileContent, err := os.ReadFile("feature/authentication/login/template/login.html")
if err != nil {
return "template not found: login"
}
return string(fileContent)
}
t := &Test{}
body := &Layout{
"main-register",
*t,
TemplateReader{
filename: "template/base.html",
},
}
ta := tmpl.MustCompile(body, compilerOption)
result, err := ta.RenderToString(body)
With this code, the template is not found, its output template not found:
without the template name.
When i'm calling directly fmt.Printf("%+v\n", body.TemplateText())
the template is found.
It would be useful to update the tmpl:bind
utility to support multiple template files, either via glob or comma-separated lists.
func (t *DotContext) TemplateText() string {
// TODO update tmpl:bind to generate something like this
var files = []string{ ... }
var buf = &bytes.Buffer{}
for _, file := range files {
byt, err := os.ReadFile(file)
if err != nil {
panic(err)
}
buf.Write(byt)
}
return buf.String()
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.