Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 4 days ago
JSON representation

HTML templates for go

Awesome Lists containing this project

README

        

# snowmark - HTML templates for Go.

[![Build Status](https://github.com/sangupta/snowmark/actions/workflows/unittest.yml/badge.svg?branch=main)](https://github.com/sangupta/snowmark/actions)
[![Code Coverage](https://codecov.io/gh/sangupta/snowmark/branch/main/graphs/badge.svg?branch=main)](https://codecov.io/gh/sangupta/snowmark)
[![go.mod version](https://img.shields.io/github/go-mod/go-version/sangupta/snowmark.svg)](https://github.com/sangupta/snowmark)
![GitHub](https://img.shields.io/github/license/sangupta/snowmark)
[![Go Report Card](https://goreportcard.com/badge/github.com/sangupta/snowmark)](https://goreportcard.com/report/github.com/sangupta/snowmark)
[![PkgGoDev](https://pkg.go.dev/badge/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.