ace

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2016 License: MIT Imports: 8 Imported by: 491

README

Ace - HTML template engine for Go

wercker status GoDoc

Overview

Ace is an HTML template engine for Go. This is inspired by Slim and Jade. This is a refinement of Gold.

Example

= doctype html
html lang=en
  head
    title Hello Ace
    = css
      h1 { color: blue; }
  body
    h1 {{.Msg}}
    #container.wrapper
      p..
        Ace is an HTML template engine for Go.
        This engine simplifies HTML coding in Go web application development.
    = javascript
      console.log('Welcome to Ace');

becomes

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Hello Ace</title>
    <style type="text/css">
      h1 { color: blue; }
    </style>
  </head>
  <body>
    <h1>Hello Ace</h1>
    <div id="container" class="wrapper">
      <p>
        Ace is an HTML template engine for Go.<br>
        This engine simplifies HTML coding in Go web application development.
      </p>
    </div>
    <script type="text/javascript">
      console.log('Welcome to Ace');
    </script>
  </body>
</html>

Features

Making Use of the Go Standard Template Package

Ace fully utilizes the strength of the html/template package. You can embed actions of the template package in Ace templates. Ace also uses nested template definitions of the template package and Ace templates can pass pipelines (parameters) to other templates which they include.

Simple Syntax

Ace has a simple syntax and this makes template files simple and light.

Caching Function

Ace has a caching function which caches the result data of the templates parsing process. You can omit the templates parsing process and save template parsing time by using this function.

Binary Template Load Function

Ace has a binary template load function which loads Ace templates from binary data in memory instead of template files on disk. You can compile your web application into one binary file by using this function. go-bindata is the best for generating binary data from template files.

Getting Started

Please check the following documentation.

  • Getting Started - shows the getting started guide.
  • Examples - shows the examples of the web applications which use the Ace template engine.

Documentation

You can get the documentation about Ace via the following channels:

  • Documentation - includes the getting started guide and the syntax documentation.
  • GoDoc - includes the API documentation.

Discussion & Contact

You can discuss Ace and contact the Ace development team via the following channels:

Contributions

Any contributions are welcome. Please feel free to create an issue or send a pull request.

Renderers for web frameworks

Tools

  • vim-ace - Vim syntax highlighting for Ace templates
  • ace-tmbundle - TextMate/Sublime syntax highlighting for Ace templates
  • atom-ace - Atom Editor syntax highlighting for Ace templates

Projects using Ace

Here is the list of the projects using Ace. Please feel free to add your awesome project to the list!

Documentation

Overview

Package ace provides an HTML template engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileResult

func CompileResult(name string, rslt *result, opts *Options) (*template.Template, error)

CompileResult compiles the parsed result to the template.Template.

func CompileResultWithTemplate added in v0.0.5

func CompileResultWithTemplate(t *template.Template, rslt *result, opts *Options) (*template.Template, error)

CompileResultWithTemplate compiles the parsed result and associates it with t.

func FlushCache added in v0.0.5

func FlushCache()

FlushCache clears all cached templates.

func Load added in v0.0.4

func Load(basePath, innerPath string, opts *Options) (*template.Template, error)

Load loads and returns an HTML template. Each Ace templates are parsed only once and cached if the "DynamicReload" option are not set.

func NewSource

func NewSource(base, inner *File, includes []*File) *source

NewSource creates and returns source.

func ParseSource

func ParseSource(src *source, opts *Options) (*result, error)

ParseSource parses the source and returns the result.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

File represents a file.

func NewFile

func NewFile(path string, data []byte) *File

NewFile creates and returns a file.

type Formatter added in v0.0.5

type Formatter struct {
	// contains filtered or unexported fields
}

func (*Formatter) ClosingElement added in v0.0.5

func (f *Formatter) ClosingElement(bf *bytes.Buffer, e element) (int, error)

func (*Formatter) OpeningElement added in v0.0.5

func (f *Formatter) OpeningElement(bf *bytes.Buffer, e element) (int, error)

func (*Formatter) WritingTextValue added in v0.0.5

func (f *Formatter) WritingTextValue(bf *bytes.Buffer, e element) (int, error)

type Options

type Options struct {
	// Extension represents an extension of files.
	Extension string
	// DelimLeft represents a left delimiter for the html template.
	DelimLeft string
	// DelimRight represents a right delimiter for the html template.
	DelimRight string
	// AttributeNameClass is the attribute name for classes.
	AttributeNameClass string
	// NoCloseTagNames defines a set of tags which should not be closed.
	NoCloseTagNames []string
	// DynamicReload represents a flag which means whether Ace reloads
	// templates dynamically.
	// This option should only be true in development.
	DynamicReload bool
	// BaseDir represents a base directory of the Ace templates.
	BaseDir string
	// Indent string used for indentation.
	Indent string

	// Asset loads and returns the asset for the given name.
	// If this function is set, Ace load the template data from
	// this function instead of the template files.
	Asset func(name string) ([]byte, error)
	// FuncMap represents a template.FuncMap which is set to
	// the result template.
	FuncMap template.FuncMap
	// contains filtered or unexported fields
}

Options represents options for the template engine.

func InitializeOptions added in v0.0.5

func InitializeOptions(opts *Options) *Options

InitializeOptions initializes the options.

func (*Options) AddNoCloseTagName added in v0.0.5

func (opts *Options) AddNoCloseTagName(name string)

AddNoCloseTagName appends name to .NoCloseTagNames set.

func (*Options) DeleteNoCloseTagName added in v0.0.5

func (opts *Options) DeleteNoCloseTagName(name string)

DeleteNoCloseTagName deletes name from .NoCloseTagNames set.

Jump to

Keyboard shortcuts

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