Documentation ¶
Overview ¶
pug.go - template engine. Package implements pug-lang templates for generating Go html/template output.
Index ¶
- Variables
- func ByPrint(in []byte) []byte
- func Config(c ReplaceTokens)
- func Format(r io.Reader, w io.Writer)
- func New(name string) *tree
- func PHPformat(in []byte) []byte
- func Parse(fname string, text []byte) (string, error)
- func ParseFile(fname string) (string, error)
- func ParseFileFromFileSystem(fname string, fs http.FileSystem) (str string, err error)
- func ParseWithFileSystem(fname string, text []byte, fs http.FileSystem) (str string, err error)
- func PrPrint(in string) string
- func Print(r io.Reader) []byte
- func UseGoFilter() *goFilter
- type ReplaceTokens
Constants ¶
This section is empty.
Variables ¶
var NewStr = []byte("\n")
NewStr should be "\n" or "\r\n" for windows
var ReadFunc = os.ReadFile
var TabSize = 4
var TabStr = []byte(" ")
TabStr - tab size
Functions ¶
func Config ¶
func Config(c ReplaceTokens)
Config is responsible for configuring the behavior of the Pug template engine. It tells the engine how to generate Go code based on the Pug templates. parameter c of type pug.ReplaceTokens holds a set of replacement patterns and settings that control the code generation process. GolangMode: true: Indicates that the engine should generate Go code. In essence, pug.Config(golang) sets up the rules and patterns that the Pug template engine will follow when it parses the .pug templates and generates the corresponding Go code.
func Parse ¶
Parse parses the template definition string to construct a representation of the template for execution.
Trivial usage:
package main import ( "fmt" "html/template" "net/http" "github.com/shaban/pug" ) func handler(w http.ResponseWriter, r *http.Request) { pugTpl, _ := pug.Parse("pug", []byte("doctype 5\n html: body: p Hello #{.Word}!")) goTpl, _ := template.New("html").Parse(pugTpl) goTpl.Execute(w, struct{ Word string }{"pug"}) } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }
Output:
<!DOCTYPE html><html><body><p>Hello pug!</p></body></html>
func ParseFileFromFileSystem ¶
func ParseFileFromFileSystem(fname string, fs http.FileSystem) (str string, err error)
ParseFileFromFileSystem parse template file in context of a http.FileSystem (supports embedded files)
func ParseWithFileSystem ¶
ParseWithFileSystem parse in context of a http.FileSystem (supports embedded files)
Types ¶
type ReplaceTokens ¶
type ReplaceTokens struct { GolangMode bool TagBgn string TagEnd string TagVoid string TagArgEsc string TagArgUne string TagArgStr string TagArgAdd string TagArgBgn string TagArgEnd string CondIf string CondUnless string CondCase string CondWhile string CondFor string CondEnd string CondForIf string CodeForElse string CodeLongcode string CodeBuffered string CodeUnescaped string CodeElse string CodeElseIf string CodeCaseWhen string CodeCaseDef string CodeMixBlock string TextStr string TextComment string MixinBgn string MixinEnd string MixinVarBgn string MixinVar string MixinVarRest string MixinVarEnd string MixinVarBlockBgn string MixinVarBlock string MixinVarBlockEnd string }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Code generated by "pug.go"; DO NOT EDIT.
|
Code generated by "pug.go"; DO NOT EDIT. |