Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wlbr/templify
A tool to be used with 'go generate' to embed external template files into Go code.
https://github.com/wlbr/templify
code-generation go-generate go-template
Last synced: about 2 months ago
JSON representation
A tool to be used with 'go generate' to embed external template files into Go code.
- Host: GitHub
- URL: https://github.com/wlbr/templify
- Owner: wlbr
- License: mit
- Created: 2016-05-22T16:42:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-08-16T20:22:50.000Z (over 3 years ago)
- Last Synced: 2024-07-31T20:52:48.874Z (4 months ago)
- Topics: code-generation, go-generate, go-template
- Language: Go
- Size: 1.17 MB
- Stars: 30
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-go - templify - Embed external template files into Go code to create single file binaries. (Resource Embedding / HTTP Clients)
- zero-alloc-awesome-go - templify - Embed external template files into Go code to create single file binaries. (Resource Embedding / HTTP Clients)
- awesome-go - templify - A tool to be used with 'go generate' to embed external template files into Go code. - ★ 15 (Resource Embedding)
- awesome-go-extra - templify - 05-22T16:42:47Z|2021-08-16T20:22:50Z| (Resource Embedding / HTTP Clients)
- awesome-go-zh - templify
README
# templify
A tool to be used with 'go generate' to embed external template files into Go code.## Scenario
An often used scenario in developing go applications is to generate text (e.g. html pages)
using the Go template packages. You have two choices: either editing the template in a
dedicated file and to read this file at runtime from your application. Or you add a
"big" string containing the template to the source of your app and parse this string to
create the template.If you want to create a single file application, then the more handy solution with a
dedicated file is not desirable. On the other hand to edit a complex html template within
a Go string in the source is very uncomfortable.templify allows you to edit your template in an extra file and to generate an Go source
file containing the embedded string.## Installation
`go get github.com/wlbr/templify`## Usage
Simply add a line`//go:generate templify mytemplate.file`
for each template you want to embed. Every time you run a `go generate` in the
corresponding folder, the file `mytemplate.go` will be created. It contains a
function `mytemplateTemplate` returning the template string.You may use `templify mytemplate.file` directly on the command line.
## Switches
Usage of templify: `templify [switches] templatefilename`
-e
export the generated, the template returning function. Default (false) means the function will not be exported.
-f
no formatting of the generated source. Default false means source will be formatted with gofmt.
-n string
name of generated, the template returning function. Its name will have 'Template' attached. Will be set to $(basename -s .ext outputfile) if empty (default).
-o string
name of output file. Defaults to name of template file excluding extension + '.go'.
-p string
name of package to be used in generated code (default "main").
-t string
name of alternate code generation template file. If empty (default), then the embedded template will be used. Template variables supplied are: .Name, .Package, .Content
## Code
* Documentation: https://godoc.org/github.com/wlbr/templify
* Lint: http://go-lint.appspot.com/github.com/wlbr/templify
* Continous Integration: [![Travis Status](https://api.travis-ci.com/wlbr/templify.svg?branch=master)](https://travis-ci.com/wlbr/templify)
* Test Coverage: [![Coverage Status](https://coveralls.io/repos/github/wlbr/templify/badge.svg?branch=master)](https://coveralls.io/github/wlbr/templify?branch=master)
* Metrics: [![GoReportCard](https://goreportcard.com/badge/github.com/wlbr/templify)](https://goreportcard.com/report/github.com/wlbr/templify)