snowmark
is a library for HTML templates that uses HTML
custom tags and custom attributes instead of confusing markup
intertwined within HTML. It is very similar to Java Server
Pages but uses string
manipulation to merge templates. In
some ways snowmark
is also similar to Velocity
templates
except using custom tags.
- Merge HTML templates with custom model
- Bring your own custom tags
- Attribute expressions
- Standard tag library includes:
- Get variable
- Set variable (global or in block)
- If-then
Let's use the following example HTML template that we want to merge with our own data model:
<html>
<head>
<title>
<test:get var="pageTitle" />
</title>
</head>
</html>
The data model to be used represented as JSON is:
{
"pageTitle" : "Hello World"
}
The following code allows us to do the same:
// parse HTML doc
template := "<html><head><title><get var='pageTitle' /></title></head></html>"
// create the model
model := snowmark.NewModel()
model.Put("pageTitle", "Hello World")
// create a page processor
processor := snowmark.NewHtmlPageProcessor()
// add all your custom tags
// you have the choice to name each tag differently
processor.AddCustomTag("test:get", snowmark.GetVariableTag)
// call merge
html, _ := processor.MergeHtml(template, model)
fmt.Println(html)
-
To build the Go docs locally:
$ godoc -http=:6060
- Open http://localhost:6060/pkg/github.com/sangupta/snowmark
-
To run all tests along with code coverage report
$ go test ./... -v -coverprofile coverage.out
$ go tool cover -html=coverage.out
- Version 0.1.0
- Initial release
MIT License. Copyright (C) 2022, Sandeep Gupta.