jade

package module
Version: v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2016 License: BSD-3-Clause Imports: 9 Imported by: 1

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:

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

mixin withGo
  |Generating Go html/template output.

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>
            {{ template "withGo" }}
        </div>
    </body>
</html>

{{ define "withGo" }}
  Generating Go html/template output.
{{ end }}
Example usage
package main

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

func main() {
    tpl, err := jade.Parse("name_of_tpl", "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>
Installation
$ 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 (
	// Pretty print if true
	PrettyOutput = true

	// Output indent strring for pretty print
	OutputIndent = "    "

	// Tabulation size of parse file
	TabSize = 4

	// Left go-template delim
	LeftDelim = "{{"

	// Right go-template delim
	RightDelim = "}}"
)

Functions

func Parse

func Parse(name, text string) (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

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL