Giter Site home page Giter Site logo

tylermmorton / tmpl Goto Github PK

View Code? Open in Web Editor NEW
44.0 44.0 0.0 151 KB

`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

Go 100.00%
golang html templates web

tmpl's People

Contributors

tylermmorton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tmpl's Issues

Error when installing scaffolding utilities

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]

Embed structs seems not working

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.

tmpl:bind - multiple template files

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()
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.