Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/veonik/go-stickgen
Generates Go code for stick templates.
https://github.com/veonik/go-stickgen
Last synced: about 2 months ago
JSON representation
Generates Go code for stick templates.
- Host: GitHub
- URL: https://github.com/veonik/go-stickgen
- Owner: veonik
- License: mit
- Created: 2016-04-11T13:48:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-03T05:18:11.000Z (over 5 years ago)
- Last Synced: 2024-04-15T04:34:18.181Z (9 months ago)
- Language: Go
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-stickgen
[![GoDoc](https://godoc.org/github.com/veonik/go-stickgen?status.svg)](https://godoc.org/github.com/veonik/go-stickgen)
Generates Go code for stick templates.
> This project is currently in a proof-of-concept state, and is under early development.
Installation
------------Install the stickgen library and command with:
```
go get -u github.com/veonik/go-stickgen/...
```Usage
-----```
Usage: stickgen [-path ] [-out ]
-out string
Output path (default "./generated")
-path string
Path to templates (default ".")
```### Usage as a library
Below is a simple example that uses the stickgen `Generator`.
```go
package mainimport (
"fmt""github.com/tyler-sommer/stick"
"github.com/veonik/go-stickgen"
)func main() {
loader := &stick.MemoryLoader{
Templates: map[string]string{
"layout.twig": `Hello, {% block name %}{% endblock %}!`,
"test.twig": `{% extends 'layout.twig' %}{% block name %}World{% endblock %}`,
},
}g := stickgen.NewGenerator("views", loader)
output, err := g.Generate("test.twig")
if err != nil {
fmt.Printf("An error occured: %s", err.Error())
return
}fmt.Println(output)
// Output:
// // Code generated by stickgen.
// // DO NOT EDIT!
//
// package views
//
// import (
// "github.com/tyler-sommer/stick"
// "io"
// "fmt"
// )
//
// func blockTestTwigName(env *stick.Env, output io.Writer, ctx map[string]stick.Value) {
// // line 1, offset 43 in test.twig
// fmt.Fprint(output, `World`)
// }
//
// func TemplateTestTwig(env *stick.Env, output io.Writer, ctx map[string]stick.Value) {
// // line 1, offset 0 in layout.twig
// fmt.Fprint(output, `Hello, `)
// // line 1, offset 10 in layout.twig
// blockTestTwigName(env, output, ctx)
// // line 1, offset 37 in layout.twig
// fmt.Fprint(output, `!`)
// }
}
```