Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eknkc/pug
Go port of Pug (jade) template engine
https://github.com/eknkc/pug
go pug tempalte
Last synced: 3 months ago
JSON representation
Go port of Pug (jade) template engine
- Host: GitHub
- URL: https://github.com/eknkc/pug
- Owner: eknkc
- License: mit
- Created: 2017-10-06T14:38:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-24T09:05:26.000Z (almost 7 years ago)
- Last Synced: 2024-10-01T06:35:31.270Z (3 months ago)
- Topics: go, pug, tempalte
- Language: Go
- Homepage:
- Size: 149 KB
- Stars: 45
- Watchers: 2
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pug
`import "github.com/eknkc/pug"`* [Overview](#pkg-overview)
* [Index](#pkg-index)
* [Subdirectories](#pkg-subdirectories)## Overview
Package pug.go is an elegant templating engine for Go Programming Language.
It is a port of Pug template engine, previously known as Jade.Pug.go compiles .pug templates to standard go templates (https://golang.org/pkg/html/template/) and returns a `*template.Template` instance.
While there is no JavaScript environment present, Pug.go provides basic expression support over go template syntax. Such as `a(href="/user/" + UserId)` would concatenate two strings. You can use arithmetic, logical and comparison operators as well as ternery if operator.
Please check *Pug Language Reference* for details: https://pugjs.org/api/getting-started.html.
Differences between Pug and Pug.go (items with checkboxes are planned, just not present yet)
- [ ] Multiline attributes are not supported
- [ ] `&attributes` syntax is not supported
- [ ] `case` statement is not supported
- [ ] Filters are not supported
- [ ] Mixin rest arguments are not supported.
- Mixin blocks are not supported. Go templates do not allow variable template includes so this is tricky.
- `while` loops are not supported as Go templates do not provide it. We could use recursive templates or channel range loops etc but that would be unnecessary complexity.
- Unbuffered code blocks are not possible as we don't have a JS environment. However it is possible to define variables using `- var x = "foo"` syntax as an exception.Apart from these missing features, everything in the language reference should be supported.
## Index
* [func CompileFile(filename string, options ...Options) (*template.Template, error)](#CompileFile)
* [func CompileString(input string, options ...Options) (*template.Template, error)](#CompileString)
* [func ParseFile(filename string, options ...Options) (string, error)](#ParseFile)
* [func ParseString(input string, options ...Options) (string, error)](#ParseString)
* [type Options](#Options)#### Package files
[doc.go](/src/github.com/eknkc/pug/doc.go) [pug.go](/src/github.com/eknkc/pug/pug.go)## func [CompileFile](/src/target/pug.go?s=1524:1605#L52)
``` go
func CompileFile(filename string, options ...Options) (*template.Template, error)
```
Parses and compiles the contents of supplied filename. Returns corresponding Go Template (html/templates) instance.
Necessary runtime functions will be injected and the template will be ready to be executed## func [CompileString](/src/target/pug.go?s=2010:2090#L63)
``` go
func CompileString(input string, options ...Options) (*template.Template, error)
```
Parses and compiles the supplied template string. Returns corresponding Go Template (html/templates) instance.
Necessary runtime functions will be injected and the template will be ready to be executed## func [ParseFile](/src/target/pug.go?s=2509:2576#L74)
``` go
func ParseFile(filename string, options ...Options) (string, error)
```
Parses the contents of supplied filename template and return the Go Template source You would not be using this unless debugging / checking the output.
Please use Compile method to obtain a template instance directly## func [ParseString](/src/target/pug.go?s=2865:2931#L80)
``` go
func ParseString(input string, options ...Options) (string, error)
```
Parses the supplied template string and return the Go Template source You would not be using this unless debugging / checking the output.
Please use Compile method to obtain a template instance directly## type [Options](/src/target/pug.go?s=108:838#L10)
``` go
type Options struct {
// Setting if pretty printing is enabled.
// Pretty printing ensures that the output html is properly indented and in human readable form.
// If disabled, produced HTML is compact. This might be more suitable in production environments.
// Default: false
PrettyPrint bool// A Dir implements FileSystem using the native file system restricted to a specific directory tree.
//
// While the FileSystem.Open method takes '/'-separated paths, a Dir's string value is a filename on the native file system, not a URL, so it is separated by filepath.Separator, which isn't necessarily '/'.
// By default, a os package is used but you can supply a different filesystem using this option
Dir compiler.Dir
}
```- - -
Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)