README

Jade.go - template engine for Go (golang)

Package jade (github.com/Joker/jade) implements Jade-lang templates for generating Go html/template output.
Now Jade-lang renamed to Pug template engine.

GoDoc Go Report Card

Jade syntax

example:

mixin withGo
  | Generating Go html/template output.

doctype html
html(lang="en")
  head
    title= .pageTitle
    script(type='text/javascript').
      if (foo) {
         bar(1 + 5)
      }
  body
    h1 Jade - template engine
    #container.col
      if .youAreUsingJade
        p You are amazing
      else
        p Get on it!
      p.
        Jade is #[a(terse)] and simple
        templating language with a
        #[strong focus] on performance
        and powerful features.
      + withGo

becomes

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>{{ .pageTitle }}</title>
        <script type='text/javascript'>
            if (foo) {
                bar(1 + 5)
            }
        </script>
    </head>
    <body>
        <h1>Jade - template engine</h1>
        <div id="container" class="col">
            {{ if .youAreUsingJade }}
                <p>You are amazing</p>
            {{ else }}
                <p>Get on it!</p>
            {{ end }}
            <p>
                Jade is <a terse="terse"></a> and simple
                templating language with a
                <strong>focus</strong> on performance
                and powerful features.
            </p>
            Generating Go html/template output.
        </div>
    </body>
</html>
Example usage
package main

import (
    "fmt"
    "github.com/Joker/jade"
)

func main() {
    tpl, err := jade.Parse("name_of_tpl", "doctype 5\n html: body: p Hello world!")
    if err != nil {
        fmt.Printf("Parse error: %v", err)
        return
    }

    fmt.Printf( "Output:\n\n%s", tpl  )
}

Output:

<!DOCTYPE html><html><body><p>Hello world!</p></body></html>
Installation
$ go get github.com/Joker/hpp
$ go get github.com/Joker/jade

Documentation

Overview

Jade.go - template engine. Package implements Jade-lang templates for generating Go html/template output.

Index

Constants

This section is empty.

Variables

View Source
var TabSize = 4

Functions

func Parse

func Parse(name string, text []byte) (string, error)

Parse parses the template definition string to construct a representation of the template for execution.

Trivial usage:

package main

import (
	"fmt"
	"github.com/Joker/jade"
)

func main() {
	tpl, err := jade.Parse("tpl_name", "doctype 5: html: body: p Hello world!")
	if err != nil {
		fmt.Printf("Parse error: %v", err)
		return
	}

	fmt.Printf( "Output:\n\n%s", tpl  )
}

Output:

<!DOCTYPE html><html><body><p>Hello world!</p></body></html>

func ParseFile

func ParseFile(filename string) (string, error)

ParseFile parse the jade template file in given filename

Types

type BlockNode

type BlockNode struct {
	NodeType
	Pos

	Name string
	// contains filtered or unexported fields
}

func (*BlockNode) Copy

func (t *BlockNode) Copy() Node

func (*BlockNode) String

func (t *BlockNode) String() string

func (*BlockNode) WriteIn

func (t *BlockNode) WriteIn(b io.Writer)

type CodeNode

type CodeNode struct {
	NodeType
	Pos

	Code []byte // The text; may span newlines.
	// contains filtered or unexported fields
}

func (*CodeNode) Copy

func (t *CodeNode) Copy() Node

func (*CodeNode) String

func (t *CodeNode) String() string

func (*CodeNode) WriteIn

func (t *CodeNode) WriteIn(b io.Writer)

type CondNode

type CondNode struct {
	NodeType
	Pos

	Nodes []Node
	// contains filtered or unexported fields
}

func (*CondNode) Copy

func (l *CondNode) Copy() Node

func (*CondNode) CopyCond

func (l *CondNode) CopyCond() *CondNode

func (*CondNode) String

func (l *CondNode) String() string

func (*CondNode) WriteIn

func (l *CondNode) WriteIn(b io.Writer)

type DoctypeNode

type DoctypeNode struct {
	NodeType
	Pos
	// contains filtered or unexported fields
}

func (*DoctypeNode) Copy

func (d *DoctypeNode) Copy() Node

func (*DoctypeNode) String

func (d *DoctypeNode) String() string

func (*DoctypeNode) WriteIn

func (d *DoctypeNode) WriteIn(b io.Writer)

type ListNode

type ListNode struct {
	NodeType
	Pos

	Nodes []Node // The element nodes in lexical order.
	// contains filtered or unexported fields
}

ListNode holds a sequence of nodes.

func (*ListNode) Copy

func (l *ListNode) Copy() Node

func (*ListNode) CopyList

func (l *ListNode) CopyList() *ListNode

func (*ListNode) String

func (l *ListNode) String() string

func (*ListNode) WriteIn

func (l *ListNode) WriteIn(b io.Writer)

type MixinNode

type MixinNode struct {
	NodeType
	Pos

	Nodes     []Node
	AttrName  []string
	AttrCode  []string
	AttrRest  []string
	MixinName string
	// contains filtered or unexported fields
}

func (*MixinNode) Copy

func (l *MixinNode) Copy() Node

func (*MixinNode) CopyMixin

func (l *MixinNode) CopyMixin() *MixinNode

func (*MixinNode) String

func (l *MixinNode) String() string

func (*MixinNode) WriteIn

func (l *MixinNode) WriteIn(b io.Writer)

type Node

type Node interface {
	Type() NodeType
	String() string
	WriteIn(io.Writer)
	// Copy does a deep copy of the Node and all its components.
	// To avoid type assertions, some XxxNodes also have specialized
	// CopyXxx methods that return *XxxNode.
	Copy() Node
	Position() Pos // byte position of start of node in full original input string
	// contains filtered or unexported methods
}

A Node is an element in the parse tree. The interface is trivial. The interface contains an unexported method so that only types local to this package can satisfy it.

type NodeType

type NodeType int

NodeType identifies the type of a parse tree node.

const (
	NodeText NodeType = iota
	NodeList
	NodeTag
	NodeCode
	NodeCond
	NodeString
	NodeDoctype
	NodeMixin
	NodeBlock
)

func (NodeType) String

func (i NodeType) String() string

func (NodeType) Type

func (t NodeType) Type() NodeType

Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes.

type Pos

type Pos int

Pos represents a byte position in the original input text from which this template was parsed.

func (Pos) Position

func (p Pos) Position() Pos

type TagNode

type TagNode struct {
	NodeType
	Pos

	Nodes    []Node
	AttrName []string
	AttrCode []string
	AttrUesc []bool
	TagName  string
	// contains filtered or unexported fields
}

func (*TagNode) Copy

func (l *TagNode) Copy() Node

func (*TagNode) CopyTag

func (l *TagNode) CopyTag() *TagNode

func (*TagNode) String

func (l *TagNode) String() string

func (*TagNode) WriteIn

func (l *TagNode) WriteIn(b io.Writer)

type TextNode

type TextNode struct {
	NodeType
	Pos

	Text []byte // The text; may span newlines.
	// contains filtered or unexported fields
}

func (*TextNode) Copy

func (t *TextNode) Copy() Node

func (*TextNode) String

func (t *TextNode) String() string

func (*TextNode) WriteIn

func (t *TextNode) WriteIn(b io.Writer)

type Tree

type Tree struct {
	Name string    // name of the template represented by the tree.
	Root *ListNode // top-level root of the tree.
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed template.

func New

func New(name string) *Tree

New allocates a new parse tree with the given name.

func (*Tree) Copy

func (t *Tree) Copy() *Tree

Copy returns a copy of the Tree. Any parsing state is discarded.

func (*Tree) Parse

func (t *Tree) Parse(text []byte) (tree *Tree, err error)

func (*Tree) WriteIn

func (t *Tree) WriteIn(b io.Writer)

Directories

Path Synopsis