https://github.com/sangupta/snowmark
HTML templates for go
https://github.com/sangupta/snowmark
custom-tags go golang html-template-engine template-engine
Last synced: 6 months ago
JSON representation
HTML templates for go
- Host: GitHub
- URL: https://github.com/sangupta/snowmark
- Owner: sangupta
- License: mit
- Created: 2022-07-24T07:41:32.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-25T01:22:26.000Z (about 3 years ago)
- Last Synced: 2025-01-02T11:12:28.467Z (over 1 year ago)
- Topics: custom-tags, go, golang, html-template-engine, template-engine
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# snowmark - HTML templates for Go.
[](https://github.com/sangupta/snowmark/actions)
[](https://codecov.io/gh/sangupta/snowmark)
[](https://github.com/sangupta/snowmark)

[](https://goreportcard.com/report/github.com/sangupta/snowmark)
[](https://pkg.go.dev/github.com/sangupta/snowmark)
`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.
# Table of contents
- [Features](#features)
- [API](#api)
- [Usage Example](#usage-example)
- [Hacking](#hacking)
- [Changelog](#changelog)
- [License](#license)
# Features
* 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
# API
# Usage Example
Let's use the following example HTML template that we want to
merge with our own data model:
```html
```
The data model to be used represented as JSON is:
```json
{
"pageTitle" : "Hello World"
}
```
The following code allows us to do the same:
```go
// parse HTML doc
template := ""
// 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)
```
# Hacking
* 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`
# Changelog
* **Version 0.1.0**
- Initial release
# License
MIT License. Copyright (C) 2022, Sandeep Gupta.