ghompl
Go HTML templating in code using functions
What? Why?
I was using the html/template
package for one of my projects but it got dirty really quickly once doing nested templates, so this is an attempt to make those problems disappear.
This implementation is very concise at ~100 SLoC, out of which half are there just for user convenience.
How?
Everything is Go code.
- Import ghompl
import . "github.com/jerwuqu/ghompl"
- Create elements
myDiv := E("div")
- Attach attributes
myDiv.Attrs["id"] = "my-div"
- Append some text
myDiv.Append(T("Hello!"))
- Or do it all at once
myDiv := EAT("div", A{"id": "my-div"}, "Hello!")
EAT
???
E
= Element
A
= Attributes
T
= Text
Skim through the implementation to see all possible combinations and/or the tests for examples of usage.
Tests?
go test github.com/jerwuqu/ghompl/test
License?
GNU GPL v3.0