pax_global_header 0000666 0000000 0000000 00000000064 12746334030 0014514 g ustar 00root root 0000000 0000000 52 comment=ea038f4770b6746c3f8f84f14fa60d9fe1205b56
ace-0.0.5/ 0000775 0000000 0000000 00000000000 12746334030 0012246 5 ustar 00root root 0000000 0000000 ace-0.0.5/.gitignore 0000664 0000000 0000000 00000000403 12746334030 0014233 0 ustar 00root root 0000000 0000000 # Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
ace-0.0.5/LICENSE 0000664 0000000 0000000 00000002067 12746334030 0013260 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2014 Keiji Yoshida
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. ace-0.0.5/README.md 0000664 0000000 0000000 00000010130 12746334030 0013520 0 ustar 00root root 0000000 0000000 # Ace - HTML template engine for Go
[](https://app.wercker.com/project/bykey/8d3c657bcae7f31d10c8f88bbfa966d8)
[](http://godoc.org/github.com/yosssi/ace)
## Overview
Ace is an HTML template engine for Go. This is inspired by [Slim](http://slim-lang.com/) and [Jade](http://jade-lang.com/). This is a refinement of [Gold](http://gold.yoss.si/).
## Example
```ace
= 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
```html
Hello Ace
Hello Ace
Ace is an HTML template engine for Go.
This engine simplifies HTML coding in Go web application development.
```
## Features
### Making Use of the Go Standard Template Package
**Ace fully utilizes the strength of the [html/template](http://golang.org/pkg/html/template/) package.** You can embed [actions](http://golang.org/pkg/text/template/#hdr-Actions) of the template package in Ace templates. Ace also uses [nested template definitions](http://golang.org/pkg/text/template/#hdr-Nested_template_definitions) of the template package and Ace templates can pass [pipelines](http://golang.org/pkg/text/template/#hdr-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](https://github.com/jteeuwen/go-bindata) is the best for generating binary data from template files.
## Getting Started
Please check the following documentation.
* [Getting Started](documentation/getting-started.md) - shows the getting started guide.
* [Examples](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](documentation) - includes the getting started guide and the syntax documentation.
* [GoDoc](https://godoc.org/github.com/yosssi/ace) - includes the API documentation.
## Discussion & Contact
You can discuss Ace and contact the Ace development team via the following channels:
* [GitHub Issues](https://github.com/yosssi/ace/issues)
* [Gitter (Chat)](https://gitter.im/yosssi/ace)
## Contributions
**Any contributions are welcome.** Please feel free to [create an issue](https://github.com/yosssi/ace/issues/new) or [send a pull request](https://github.com/yosssi/ace/compare/).
## Renderers for web frameworks
* [Martini Acerender](https://github.com/yosssi/martini-acerender) - For [Martini](http://martini.codegangsta.io/)
## Tools
* [vim-ace](https://github.com/yosssi/vim-ace) - Vim syntax highlighting for Ace templates
* [ace-tmbundle](https://github.com/yosssi/ace-tmbundle) - TextMate/Sublime syntax highlighting for Ace templates
* [atom-ace](https://github.com/pariz/atom-ace) - Atom Editor syntax highlighting for Ace templates
## Projects using Ace
[Here](documentation/projects-using-ace.md) is the list of the projects using Ace. Please feel free to add your awesome project to the list!
ace-0.0.5/ace.go 0000664 0000000 0000000 00000002645 12746334030 0013334 0 ustar 00root root 0000000 0000000 package ace
import (
"html/template"
"sync"
)
var cache = make(map[string]template.Template)
var cacheMutex = new(sync.RWMutex)
// Load loads and returns an HTML template. Each Ace templates are parsed only once
// and cached if the "DynamicReload" option are not set.
func Load(basePath, innerPath string, opts *Options) (*template.Template, error) {
// Initialize the options.
opts = InitializeOptions(opts)
name := basePath + colon + innerPath
if !opts.DynamicReload {
if tpl, ok := getCache(name); ok {
return &tpl, nil
}
}
// Read files.
src, err := readFiles(basePath, innerPath, opts)
if err != nil {
return nil, err
}
// Parse the source.
rslt, err := ParseSource(src, opts)
if err != nil {
return nil, err
}
// Compile the parsed result.
tpl, err := CompileResult(name, rslt, opts)
if err != nil {
return nil, err
}
if !opts.DynamicReload {
setCache(name, *tpl)
}
return tpl, nil
}
// getCache returns the cached template.
func getCache(name string) (template.Template, bool) {
cacheMutex.RLock()
tpl, ok := cache[name]
cacheMutex.RUnlock()
return tpl, ok
}
// setCache sets the template to the cache.
func setCache(name string, tpl template.Template) {
cacheMutex.Lock()
cache[name] = tpl
cacheMutex.Unlock()
}
// FlushCache clears all cached templates.
func FlushCache() {
cacheMutex.Lock()
cache = make(map[string]template.Template)
cacheMutex.Unlock()
}
ace-0.0.5/action.go 0000664 0000000 0000000 00000001474 12746334030 0014060 0 ustar 00root root 0000000 0000000 package ace
import (
"bytes"
"io"
"strings"
)
// action represents an action.
type action struct {
elementBase
}
// WriteTo writes data to w.
func (e *action) WriteTo(w io.Writer) (int64, error) {
var bf bytes.Buffer
// Write the action
bf.WriteString(strings.TrimSpace(e.ln.str))
// Write the children's HTML.
if i, err := e.writeChildren(&bf); err != nil {
return i, err
}
// Write the buffer.
i, err := w.Write(bf.Bytes())
return int64(i), err
}
func (e *action) IsBlockElement() bool {
return e.parent.IsBlockElement()
}
func (e *action) IsControlElement() bool {
return true
}
// newAction creates and returns an action.
func newAction(ln *line, rslt *result, src *source, parent element, opts *Options) *action {
return &action{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
}
ace-0.0.5/cmd/ 0000775 0000000 0000000 00000000000 12746334030 0013011 5 ustar 00root root 0000000 0000000 ace-0.0.5/cmd/ace/ 0000775 0000000 0000000 00000000000 12746334030 0013541 5 ustar 00root root 0000000 0000000 ace-0.0.5/cmd/ace/main.go 0000664 0000000 0000000 00000003505 12746334030 0015017 0 ustar 00root root 0000000 0000000 package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/yosssi/ace"
"github.com/yosssi/gohtml"
)
var (
noFormat bool
lineNo bool
)
func compileResultFromStdin() (string, error) {
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return "", err
}
name, baseFile := "stdin", "stdin.ace"
base := ace.NewFile(baseFile, b)
inner := ace.NewFile("", []byte{})
src := ace.NewSource(base, inner, []*ace.File{})
rslt, err := ace.ParseSource(src, nil)
if err != nil {
return "", err
}
tpl, err := ace.CompileResult(name, rslt, nil)
if err != nil {
return "", err
}
return tpl.Lookup(name).Tree.Root.String(), nil
}
func compileResultFromFile(baseFile, innerFile string) (string, error) {
base := baseFile[:len(baseFile)-len(filepath.Ext(baseFile))]
var inner string
if len(innerFile) > 0 {
inner = innerFile[:len(innerFile)-len(filepath.Ext(innerFile))]
}
name := base + ":" + inner
tpl, err := ace.Load(base, inner, nil)
if err != nil {
return "", err
}
return tpl.Lookup(name).Tree.Root.String(), nil
}
func main() {
flag.BoolVar(&noFormat, "no-format", false, "output HTML without format")
flag.BoolVar(&lineNo, "lineno", false, "output formatted HTML with line numbers")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage:\n %s [options] [base.ace] [inner.ace]\n\nOptions:\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
var (
compiled string
err error
)
baseFile := flag.Arg(0)
if len(baseFile) == 0 {
compiled, err = compileResultFromStdin()
} else {
compiled, err = compileResultFromFile(baseFile, flag.Arg(1))
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if noFormat {
fmt.Println(compiled)
} else {
if lineNo {
fmt.Println(gohtml.FormatWithLineNo(compiled))
} else {
fmt.Println(gohtml.Format(compiled))
}
}
}
ace-0.0.5/comment.go 0000664 0000000 0000000 00000000767 12746334030 0014251 0 ustar 00root root 0000000 0000000 package ace
import "io"
// comment represents a comment.
type comment struct {
elementBase
}
// Do nothing.
func (e *comment) WriteTo(w io.Writer) (int64, error) {
return 0, nil
}
// ContainPlainText returns true.
func (e *comment) ContainPlainText() bool {
return true
}
// newComment creates and returns a comment.
func newComment(ln *line, rslt *result, src *source, parent element, opts *Options) *comment {
return &comment{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
}
ace-0.0.5/compile.go 0000664 0000000 0000000 00000004325 12746334030 0014231 0 ustar 00root root 0000000 0000000 package ace
import (
"bytes"
"fmt"
"html/template"
)
// Actions
const (
actionDefine = `%sdefine "%s"%s`
actionEnd = "%send%s"
actionTemplate = `%stemplate "%s"%s`
actionTemplateWithPipeline = `%stemplate "%s" %s%s`
)
// PreDefinedFuncs
const (
preDefinedFuncNameHTML = "HTML"
)
// CompileResult compiles the parsed result to the template.Template.
func CompileResult(name string, rslt *result, opts *Options) (*template.Template, error) {
// Initialize the options.
opts = InitializeOptions(opts)
// Create a template.
t := template.New(name)
return CompileResultWithTemplate(t, rslt, opts)
}
// CompileResultWithTemplate compiles the parsed result and associates it with t.
func CompileResultWithTemplate(t *template.Template, rslt *result, opts *Options) (*template.Template, error) {
// Initialize the options.
opts = InitializeOptions(opts)
var err error
// Create a buffer.
baseBf := bytes.NewBuffer(nil)
innerBf := bytes.NewBuffer(nil)
includeBfs := make(map[string]*bytes.Buffer)
// Write data to the buffer.
for _, e := range rslt.base {
if _, err := e.WriteTo(baseBf); err != nil {
return nil, err
}
}
for _, e := range rslt.inner {
if _, err = e.WriteTo(innerBf); err != nil {
return nil, err
}
}
for path, elements := range rslt.includes {
bf := bytes.NewBuffer(nil)
// Write a define action.
bf.WriteString(fmt.Sprintf(actionDefine, opts.DelimLeft, path, opts.DelimRight))
for _, e := range elements {
if _, err = e.WriteTo(bf); err != nil {
return nil, err
}
}
// Write an end action.
bf.WriteString(fmt.Sprintf(actionEnd, opts.DelimLeft, opts.DelimRight))
includeBfs[path] = bf
}
// Set Delimiters.
t.Delims(opts.DelimLeft, opts.DelimRight)
// Set FuncMaps.
t.Funcs(template.FuncMap{
preDefinedFuncNameHTML: func(s string) template.HTML {
return template.HTML(s)
},
})
t.Funcs(opts.FuncMap)
// Parse a string to the template.
t, err = t.Parse(baseBf.String())
if err != nil {
return nil, err
}
t, err = t.Parse(innerBf.String())
if err != nil {
return nil, err
}
for _, bf := range includeBfs {
t, err = t.Parse(bf.String())
if err != nil {
return nil, err
}
}
return t, nil
}
ace-0.0.5/compile_test.go 0000664 0000000 0000000 00000004542 12746334030 0015271 0 ustar 00root root 0000000 0000000 package ace
import (
"testing"
)
func TestLineCompile(t *testing.T) {
for i, this := range []struct {
template string
expect string
}{
{
template: `a href=./foo foo`,
expect: `foo`,
},
{
template: `span.color-red red`,
expect: `red`,
},
{
template: `span#ref1 text`,
expect: `text`,
},
{
template: `span#ref1.color-red.text-big text`,
expect: `text`,
},
{
template: `span.color-red#ref1.text-big text`,
expect: `text`,
},
{
template: `#ref1 text`,
expect: `
",
},
} {
name, filepath := "dummy", "dummy.ace"
base := NewFile(filepath, []byte(this.template))
inner := NewFile("", []byte{})
src := NewSource(base, inner, []*File{})
rslt, err := ParseSource(src, nil)
if err != nil {
t.Errorf("[%d] failed: %s", i, err)
continue
}
tpl, err := CompileResult(name, rslt, nil)
if err != nil {
t.Errorf("[%d] failed: %s", i, err)
continue
}
compiled := tpl.Lookup(name).Tree.Root.String()
if compiled != this.expect {
t.Errorf("[%d] Compiler didn't return an expected value, got %v but expected %v", i, compiled, this.expect)
}
}
}
ace-0.0.5/doc.go 0000664 0000000 0000000 00000000075 12746334030 0013344 0 ustar 00root root 0000000 0000000 // Package ace provides an HTML template engine.
package ace
ace-0.0.5/documentation/ 0000775 0000000 0000000 00000000000 12746334030 0015117 5 ustar 00root root 0000000 0000000 ace-0.0.5/documentation/README.md 0000664 0000000 0000000 00000000225 12746334030 0016375 0 ustar 00root root 0000000 0000000 # Documentation
* [Getting Started](getting-started.md)
* [Syntax](syntax.md)
* [Options](options.md)
* [Projects using Ace](projects-using-ace.md)
ace-0.0.5/documentation/getting-started.md 0000664 0000000 0000000 00000003543 12746334030 0020553 0 ustar 00root root 0000000 0000000 # Getting Started
This document explains a basic usage of Ace by showing a simple example.
## 1. Create Ace templates
Create the following Ace templates.
base.ace
```ace
= doctype html
html lang=en
head
meta charset=utf-8
title Ace example
= css
h1 { color: blue; }
body
h1 Base Template : {{.Msg}}
#container.wrapper
= yield main
= yield sub
= include inc .Msg
= javascript
alert('{{.Msg}}');
```
inner.ace
```ace
= content main
h2 Inner Template - Main : {{.Msg}}
= content sub
h3 Inner Template - Sub : {{.Msg}}
```
inc.ace
```ace
h4 Included Template : {{.}}
```
## 2. Create a web application
Create the following web application.
main.go
```go
package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("base", "inner", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, map[string]string{"Msg": "Hello Ace"}); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
```
## 3. Check the result.
Run the above web application and access [localhost:8080](http://localhost:8080). The following HTML will be rendered.
```html
Ace example
Base Template : Hello Ace
Inner Template - Main : Hello Ace
Inner Template - Sub : Hello Ace
Included Template : Hello Ace
```
ace-0.0.5/documentation/options.md 0000664 0000000 0000000 00000001406 12746334030 0017135 0 ustar 00root root 0000000 0000000 # Options
Here is a sample Go code which calls an Ace template engine.
```go
package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("base", "inner", nil)
if err != nil {
panic(err)
}
if err := tpl.Execute(w, map[string]string{"Msg": "Hello Ace"}); err != nil {
panic(err)
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
```
You can pass parsing options to the Ace template engine via `ace.Load`'s third argument.
```go
tpl, err := ace.Load("base", "inner", &ace.Options{DynamicReload: true})
```
Please check [GoDoc](https://godoc.org/github.com/yosssi/ace#Options) for more detail about options.
ace-0.0.5/documentation/projects-using-ace.md 0000664 0000000 0000000 00000000775 12746334030 0021154 0 ustar 00root root 0000000 0000000 # Projects using Ace
* [Ace Proxy](https://github.com/yosssi/ace-proxy) - Proxy for the Ace template engine
* [ace.yoss.si](https://github.com/yosssi/ace.yoss.si) - Website of Ace
* [Martini Acerender](https://github.com/yosssi/martini-acerender) - Martini middleware/handler for parsing Ace templates and rendering HTML
* [Hugo](https://github.com/spf13/hugo) - Static Site Generator written in Go
* [ace-util](https://github.com/catinello/ace-util) - Command line utility for the Ace HTML template engine.
ace-0.0.5/documentation/syntax.md 0000664 0000000 0000000 00000015506 12746334030 0016776 0 ustar 00root root 0000000 0000000 # Syntax
## Indent
A unit of an indent must be 2 spaces.
```ace
html
body
div
p
```
becomes
```html
```
## HTML Tags
A head word of a line is interpreted as an HTML tag. The rest words of the same line are interpreted as attributes or a text. An attribute value which contains spaces must be surrounded by double quotes. An attribute without value (like "check" and "required") can be defined by specifying no value and ending with an equal (=).
```ace
div id=container style="font-size: 12px; color: blue;"
p class=row This is interpreted as a text.
a href=https://github.com/ Go to GitHub
input type=checkbox checked=
```
becomes
```html
```
ID and classes can be defined with a head word of a line.
```ace
p#foo.bar
#container
.wrapper
```
becomes
```html
```
Block texts can be defined as a child element of an HTML tag by appending a dot (.) or double dot (..) to the head word of a line. BR tags are inserted to each line except for the last line by appending a double dot (..) to the head word of a line.
```ace
script.
var msg = 'Hello Ace';
alert(msg);
p..
This is a block text.
BR tags are inserted
automatically.
```
becomes
```html
This is a block text.
BR tags are inserted
automatically.
```
## Plain Texts
A line which starts with a pipe (|) or double pipe (||) is interpreted as a block of plain texts. BR tags are inserted to each line except for the last line by having a line start with a double pipe (||).
```ace
div
| This is a single line.
div
|
This is a
block line.
div
||
This is a
block line
with BR tags.
```
becomes
```html
This is a single line.
This is a
block line.
This is a
block line
with BR tags.
```
## Helper Methods
A line which starts withs an equal (=) is interpreted as a helper method.
```ace
= helperMethodName
```
The following helper methods are available.
### Conditional Comment Helper Method
A conditional comment helper method generates a [conditional comment](http://en.wikipedia.org/wiki/Conditional_comment).
```ace
= conditionalComment commentType condition
```
The following comment types are acceptable:
| Comment Type | Generated HTML |
| ------------ |----------------------------------------|
| hidden | |
| revealed | HTML |
```ace
= conditionalComment hidden IE 6
You are using Internet Explorer 6.
= conditionalComment revealed !IE
```
becomes
```html
```
### Content Helper Method
A content helper method defines a block content which is embedded in the base template. This helper method must be used only in the inner template.
```
= content main
h2 Inner Template - Main : {{.Msg}}
= content sub
h3 Inner Template - Sub : {{.Msg}}
```
### CSS Helper Method
A css helper method generates a style tag which has "text/css" type.
```ace
= css
body {
margin: 0;
}
h1 {
font-size: 200%;
color: blue;
}
```
becomes
```html
```
### Doctype Helper Method
A doctype helper method generates a doctype tag.
```ace
= doctype doctypeName
```
The following doctype names are acceptable:
| Doctype Name | Generated HTML |
| ------------ |--------------------------------------|
| html | |
| xml | |
| transitional | |
| strict | |
| frameset | |
| 1.1 | |
| basic | |
| mobile | |
```ace
= doctype html
```
becomes
```html
```
### Include Helper Method
An include helper method includes another template. You can pass a pipeline (parameter) from the including template to the included template.
```ace
= include templatePathWithoutExtension pipeline
```
### Javascript Helper Method
A javascript helper method generates a script tag which has "text/javascript" type.
```ace
= javascript
var msg = 'Hello Ace';
alert(msg);
```
becomes
```html
```
### Yield Helper Method
A yield helper method generates the HTML tags which are defined in the inner template. This helper method must be used only in the base template.
```
= yield main
| This message is rendered if the "main" content is not defined in the inner template.
= yield sub
| This message is rendered if the "sub" content is not defined in the inner template.
```
## Comments
A line which starts with a slash (/) or double slash (//) is interpreted as a comment. A line which starts with a slash (/) is not rendered. A line which starts with a double slash (//) is renderd as an HTML comment.
```ace
/ This is a single line comment which is not rendered.
/
This is a multiple lines comment
which is not rendered.
// This is a single line comment which is rendered as an HTML comment.
//
This is a multiple lines comment
which is rendered as an HTML comment.
```
becomes
```html
```
## Actions
[Actions](http://golang.org/pkg/text/template/#hdr-Actions) of the template package can be embedded in Ace templates.
```ace
body
h1 Base Template : {{.Msg}}
{{if true}}
p Conditional block
{{end}}
```
The following functions are predefined.
### HTML function
HTML function returns a non-escaped string.
```ace
{{" "}}
{{HTML " "}}
```
becomes
```html
<br>
```
ace-0.0.5/element.go 0000664 0000000 0000000 00000004572 12746334030 0014236 0 ustar 00root root 0000000 0000000 package ace
import (
"fmt"
"io"
)
// Helper method names
const (
helperMethodNameConditionalComment = "conditionalComment"
helperMethodNameContent = "content"
helperMethodNameCSS = "css"
helperMethodNameDoctype = "doctype"
helperMethodNameYield = "yield"
helperMethodNameInclude = "include"
helperMethodNameJavascript = "javascript"
)
// element is an interface for storing an element.
type element interface {
io.WriterTo
AppendChild(child element)
ContainPlainText() bool
Base() *elementBase
CanHaveChildren() bool
InsertBr() bool
SetLastChild(lastChild bool)
IsBlockElement() bool
IsControlElement() bool
}
// newElement creates and returns an element.
func newElement(ln *line, rslt *result, src *source, parent element, opts *Options) (element, error) {
var e element
var err error
switch {
case parent != nil && parent.ContainPlainText():
e = newPlainTextInner(ln, rslt, src, parent, parent.InsertBr(), opts)
case ln.isEmpty():
e = newEmptyElement(ln, rslt, src, parent, opts)
case ln.isComment():
e = newComment(ln, rslt, src, parent, opts)
case ln.isHTMLComment():
e = newHTMLComment(ln, rslt, src, parent, opts)
case ln.isHelperMethod():
switch {
case ln.isHelperMethodOf(helperMethodNameConditionalComment):
e, err = newHelperMethodConditionalComment(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameContent):
e, err = newHelperMethodContent(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameCSS):
e = newHelperMethodCSS(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameDoctype):
e, err = newHelperMethodDoctype(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameInclude):
e, err = newHelperMethodInclude(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameJavascript):
e = newHelperMethodJavascript(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameYield):
e, err = newHelperMethodYield(ln, rslt, src, parent, opts)
default:
err = fmt.Errorf("the helper method name is invalid [file: %s][line: %d]", ln.fileName(), ln.no)
}
case ln.isPlainText():
e = newPlainText(ln, rslt, src, parent, opts)
case ln.isAction():
e = newAction(ln, rslt, src, parent, opts)
default:
e, err = newHTMLTag(ln, rslt, src, parent, opts)
}
return e, err
}
ace-0.0.5/element_base.go 0000664 0000000 0000000 00000003747 12746334030 0015233 0 ustar 00root root 0000000 0000000 package ace
import "bytes"
// elementBase holds common fields for the elements.
type elementBase struct {
ln *line
rslt *result
src *source
parent element
children []element
opts *Options
lastChild bool
}
// AppendChild appends the child element to the element.
func (e *elementBase) AppendChild(child element) {
e.children = append(e.children, child)
}
// ContainPlainText returns false.
// This method should be overrided by a struct which contains
// the element base struct.
func (e *elementBase) ContainPlainText() bool {
return false
}
// Base returns the element base.
func (e *elementBase) Base() *elementBase {
return e
}
// CanHaveChildren returns true.
// This method should be overrided by a struct which contains
// the element base struct.
func (e *elementBase) CanHaveChildren() bool {
return true
}
func (e *elementBase) IsBlockElement() bool {
return false
}
func (e *elementBase) IsControlElement() bool {
return false
}
// InsertBr returns false.
// This method should be overrided by a struct which contains
// the element base struct.
func (e *elementBase) InsertBr() bool {
return false
}
// SetLastChild set the value to the last child field.
func (e *elementBase) SetLastChild(lastChild bool) {
e.lastChild = lastChild
}
// writeChildren writes the children's HTML.
func (e *elementBase) writeChildren(bf *bytes.Buffer) (int64, error) {
l := len(e.children)
for index, child := range e.children {
if index == l-1 {
child.SetLastChild(true)
}
if e.opts.formatter != nil {
if i, err := e.opts.formatter.OpeningElement(bf, child); err != nil {
return int64(i), err
}
}
if i, err := child.WriteTo(bf); err != nil {
return int64(i), err
}
}
return 0, nil
}
// newElementBase creates and returns an element base.
func newElementBase(ln *line, rslt *result, src *source, parent element, opts *Options) elementBase {
return elementBase{
ln: ln,
rslt: rslt,
src: src,
parent: parent,
opts: opts,
}
}
ace-0.0.5/element_test.go 0000664 0000000 0000000 00000000107 12746334030 0015263 0 ustar 00root root 0000000 0000000 package ace
import "testing"
func Test_newElement(t *testing.T) {
}
ace-0.0.5/empty_element.go 0000664 0000000 0000000 00000001046 12746334030 0015445 0 ustar 00root root 0000000 0000000 package ace
import "io"
// emptyElement represents an empty element.
type emptyElement struct {
elementBase
}
// Do nothing.
func (e *emptyElement) WriteTo(w io.Writer) (int64, error) {
return 0, nil
}
// CanHaveChildren returns false.
func (e *emptyElement) CanHaveChildren() bool {
return false
}
// newEmpty creates and returns an empty element.
func newEmptyElement(ln *line, rslt *result, src *source, parent element, opts *Options) *emptyElement {
return &emptyElement{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
}
ace-0.0.5/examples/ 0000775 0000000 0000000 00000000000 12746334030 0014064 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/README.md 0000664 0000000 0000000 00000001541 12746334030 0015344 0 ustar 00root root 0000000 0000000 # Examples
This documentation shows the examples of the web applications which use the Ace template engine.
## Basic
* [Single Template](single_template)
* [Base and Inner Template](base_inner_template)
* [HTML Tags](html_tags)
* [Plain Texts](plain_texts)
* [CSS and Javascript Helper Method](css_javascript_helper_method)
* [Comments](comments)
* [Include Helper Method](include_helper_method)
* [Actions](actions)
## Advanced
* [Dynamic Reload](dynamic_reload)
* [Load Templates from Binary Data](load_templates_from_binary_data)
* [Pass a Pipeline (Parameter) to the Included Template](pass_pipeline_to_included_template)
* [Set a Default Value to the Yield Helper Method](set_default_value_to_the_yield_helper_method)
* [Change the Action Delimiter](change_action_delimiter)
* [Set Custom Functions](set_custom_functions)
* [Cache Options](cache_options)
ace-0.0.5/examples/actions/ 0000775 0000000 0000000 00000000000 12746334030 0015524 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/actions/README.md 0000664 0000000 0000000 00000000105 12746334030 0016777 0 ustar 00root root 0000000 0000000 # Actions
This example shows how to embed actions in Ace templates.
ace-0.0.5/examples/actions/example.ace 0000664 0000000 0000000 00000000411 12746334030 0017625 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title {{.Title}}
body
h1 {{.Title}}
ul
{{range .Msgs}}
li {{.}}
{{end}}
div
{{"
Escaped String
"}}
div
{{HTML "
Non-Escaped String
"}}
ace-0.0.5/examples/actions/main.go 0000664 0000000 0000000 00000001107 12746334030 0016776 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := map[string]interface{}{
"Title": "Actions",
"Msgs": []string{
"Message1",
"Message2",
"Message3",
},
}
if err := tpl.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/base_inner_template/ 0000775 0000000 0000000 00000000000 12746334030 0020064 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/base_inner_template/README.md 0000664 0000000 0000000 00000000135 12746334030 0021342 0 ustar 00root root 0000000 0000000 # Base and Inner Template
This example shows how to use a base and inner Ace template file.
ace-0.0.5/examples/base_inner_template/base.ace 0000664 0000000 0000000 00000000243 12746334030 0021447 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Base and Inner Template
body
h1 This is a base template
= yield main
= yield sub
ace-0.0.5/examples/base_inner_template/inner.ace 0000664 0000000 0000000 00000000221 12746334030 0021644 0 ustar 00root root 0000000 0000000 = content main
h2 This is a content named "main" of an inner template.
= content sub
h2 This is a content named "sub" of an inner template.
ace-0.0.5/examples/base_inner_template/main.go 0000664 0000000 0000000 00000000710 12746334030 0021335 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("base", "inner", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/cache_options/ 0000775 0000000 0000000 00000000000 12746334030 0016702 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/cache_options/README.md 0000664 0000000 0000000 00000000235 12746334030 0020161 0 ustar 00root root 0000000 0000000 # Cache Options
This example shows how to cache the options for Ace template engine so that you don't have to specify them every time calling the Ace APIs.
ace-0.0.5/examples/cache_options/main.go 0000664 0000000 0000000 00000001054 12746334030 0020155 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
"github.com/yosssi/ace-proxy"
)
var p = proxy.New(&ace.Options{BaseDir: "views", DynamicReload: true})
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := p.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/cache_options/views/ 0000775 0000000 0000000 00000000000 12746334030 0020037 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/cache_options/views/example.ace 0000664 0000000 0000000 00000000156 12746334030 0022146 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Cache Options
body
h1 Cache Options
ace-0.0.5/examples/change_action_delimiter/ 0000775 0000000 0000000 00000000000 12746334030 0020704 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/change_action_delimiter/README.md 0000664 0000000 0000000 00000000126 12746334030 0022162 0 ustar 00root root 0000000 0000000 # Change the Action Delimiter
This example shows how to change the action delimiter.
ace-0.0.5/examples/change_action_delimiter/example.ace 0000664 0000000 0000000 00000000167 12746334030 0023015 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Change the Action Delimiter
body
h1 <%.Msg%>
ace-0.0.5/examples/change_action_delimiter/main.go 0000664 0000000 0000000 00000001066 12746334030 0022162 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", &ace.Options{
DelimLeft: "<%",
DelimRight: "%>",
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := map[string]interface{}{
"Msg": "Hello Ace",
}
if err := tpl.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/comments/ 0000775 0000000 0000000 00000000000 12746334030 0015711 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/comments/README.md 0000664 0000000 0000000 00000000067 12746334030 0017173 0 ustar 00root root 0000000 0000000 # Comments
This example shows how to define comments.
ace-0.0.5/examples/comments/example.ace 0000664 0000000 0000000 00000001051 12746334030 0020013 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Comments
body
/ This is a single line comment which is not rendered.
/
This is a multiple lines comment
which is not rendered.
// This is a single line comment which is rendered as an HTML comment.
//
This is a multiple lines comment
which is rendered as an HTML comment.
= conditionalComment hidden IE 6
You are using Internet Explorer 6.
= conditionalComment revealed !IE
ace-0.0.5/examples/comments/main.go 0000664 0000000 0000000 00000000706 12746334030 0017167 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/css_javascript_helper_method/ 0000775 0000000 0000000 00000000000 12746334030 0022001 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/css_javascript_helper_method/README.md 0000664 0000000 0000000 00000000150 12746334030 0023254 0 ustar 00root root 0000000 0000000 # CSS and Javascript Helper Method
This example shows how to use the css and javascript helper method.
ace-0.0.5/examples/css_javascript_helper_method/example.ace 0000664 0000000 0000000 00000000621 12746334030 0024105 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title CSS and Javascript Helper Method
= css
h1 {
color: blue;
}
h2 {
color: green;
}
body
h1 CSS and Javascript Helper Method
h2 This example shows how to use the css and javascript helper method.
= javascript
var msg = 'CSS and Javascript Helper Method';
alert(msg);
ace-0.0.5/examples/css_javascript_helper_method/main.go 0000664 0000000 0000000 00000000706 12746334030 0023257 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/dynamic_reload/ 0000775 0000000 0000000 00000000000 12746334030 0017036 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/dynamic_reload/README.md 0000664 0000000 0000000 00000000425 12746334030 0020316 0 ustar 00root root 0000000 0000000 # Dynamic Reload
This example shows how to reload templates dynamically. Ace caches the parsed templates by default but you can have Ace reload templates dynamically by setting the "DynamicReload" option to the Ace template enginge. This option should be used in development.
ace-0.0.5/examples/dynamic_reload/example.ace 0000664 0000000 0000000 00000000160 12746334030 0021140 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Dynamic Reload
body
h1 Dynamic Reload
ace-0.0.5/examples/dynamic_reload/main.go 0000664 0000000 0000000 00000000744 12746334030 0020316 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", &ace.Options{DynamicReload: true})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/external_css_and_js/ 0000775 0000000 0000000 00000000000 12746334030 0020074 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/external_css_and_js/README.md 0000664 0000000 0000000 00000000154 12746334030 0021353 0 ustar 00root root 0000000 0000000 # Single Template
This example shows how to build a web application which uses a single Ace template file.
ace-0.0.5/examples/external_css_and_js/example.ace 0000664 0000000 0000000 00000002172 12746334030 0022203 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title External CSS and JS
link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"
body
div.container
h1.
External CSS and JS
div.row
div.col-xs-12
label
input#completed-css disabled="disabled" type="checkbox"
span Load CSS from external source
div.row
div.col-xs-12
label
input#completed-js disabled="disabled" type="checkbox"
span Load JS from external source
script src="http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"
= javascript
// verification that we are using downloaded javascript
window.onload = function() {
if (jQuery !== undefined) {
document.getElementById("completed-js").checked = true;
}
for (var i = 0; i < document.styleSheets.length; ++i) {
if (document.styleSheets[i].href.indexOf("bootstrap.min.css") !== -1) {
document.getElementById("completed-css").checked = true;
}
}
};
ace-0.0.5/examples/external_css_and_js/main.go 0000664 0000000 0000000 00000000706 12746334030 0021352 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/html_tags/ 0000775 0000000 0000000 00000000000 12746334030 0016046 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/html_tags/README.md 0000664 0000000 0000000 00000000103 12746334030 0017317 0 ustar 00root root 0000000 0000000 # HTML Tags
This example shows how to generate various HTML tags.
ace-0.0.5/examples/html_tags/example.ace 0000664 0000000 0000000 00000000777 12746334030 0020166 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title HTML Tags
body
header
h1 HTML Tags
section#main-section.class1.class2 class=class3
#container
.wrapper
div Single text line can follow the tag name.
p..
This is a block text.
BR tags are inserted automatically.
a href=https://github.com Go to GitHub
input type=checkbox checked=
footer
script.
var msg = 'Hello Ace';
alert(msg);
ace-0.0.5/examples/html_tags/main.go 0000664 0000000 0000000 00000000706 12746334030 0017324 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/include_helper_method/ 0000775 0000000 0000000 00000000000 12746334030 0020406 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/include_helper_method/README.md 0000664 0000000 0000000 00000000121 12746334030 0021657 0 ustar 00root root 0000000 0000000 # Include Helper Method
This example shows how to use an include helper method.
ace-0.0.5/examples/include_helper_method/example.ace 0000664 0000000 0000000 00000000222 12746334030 0022507 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Include Helper Method
body
h1 This is a base template
= include inc
ace-0.0.5/examples/include_helper_method/inc.ace 0000664 0000000 0000000 00000000041 12746334030 0021624 0 ustar 00root root 0000000 0000000 h2 This is an included template.
ace-0.0.5/examples/include_helper_method/main.go 0000664 0000000 0000000 00000000706 12746334030 0021664 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/load_templates_from_binary_data/ 0000775 0000000 0000000 00000000000 12746334030 0022441 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/load_templates_from_binary_data/README.md 0000664 0000000 0000000 00000000770 12746334030 0023724 0 ustar 00root root 0000000 0000000 # Load Templates from Binary Data
This example shows how to load templates from binary data instead of template files.
You can run this example web application by executing the following command.
```sh
$ go run main.go asset.go
```
`asset.go` is created by executing `make_asset.sh`. This shell script executes [go-bindata](https://github.com/jteeuwen/go-bindata) and generates binary data from the Ace template.
**You can compile your web application into one binary file by using this function.**
ace-0.0.5/examples/load_templates_from_binary_data/asset.go 0000664 0000000 0000000 00000003615 12746334030 0024114 0 ustar 00root root 0000000 0000000 package main
import (
"bytes"
"compress/gzip"
"fmt"
"io"
)
func bindata_read(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err)
}
var buf bytes.Buffer
_, err = io.Copy(&buf, gz)
gz.Close()
if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err)
}
return buf.Bytes(), nil
}
func views_example_ace() ([]byte, error) {
return bindata_read([]byte{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0x84, 0xcb,
0xb1, 0x11, 0x83, 0x30, 0x14, 0x03, 0xd0, 0x9e, 0x29, 0xb4, 0x40, 0x8a,
0x74, 0x69, 0xbc, 0x41, 0x96, 0x10, 0xfc, 0x4f, 0xcc, 0x9d, 0xed, 0xcf,
0x19, 0xa5, 0xf0, 0xf6, 0x21, 0x2c, 0x40, 0x23, 0xdd, 0xe9, 0x9e, 0x12,
0x2c, 0x16, 0x8d, 0xdd, 0x91, 0x55, 0xcb, 0xf4, 0x0f, 0x14, 0xb6, 0x4f,
0xf2, 0x36, 0x01, 0xd9, 0x69, 0x67, 0x01, 0xd5, 0x45, 0x2c, 0x99, 0xfd,
0x70, 0xa5, 0xaf, 0xd6, 0xc7, 0xeb, 0x9a, 0xb5, 0xa9, 0x38, 0xde, 0x41,
0x83, 0xbc, 0xee, 0x85, 0xf2, 0x03, 0x6b, 0x8f, 0x8a, 0x79, 0x6b, 0xec,
0x03, 0x46, 0xf1, 0x94, 0x73, 0xd8, 0xb8, 0x0e, 0xf9, 0x79, 0xab, 0x7f,
0x01, 0x00, 0x00, 0xff, 0xff, 0x6b, 0xc6, 0x6a, 0x49, 0x92, 0x00, 0x00,
0x00,
},
"views/example.ace",
)
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
if f, ok := _bindata[name]; ok {
return f()
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
}
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string] func() ([]byte, error) {
"views/example.ace": views_example_ace,
}
ace-0.0.5/examples/load_templates_from_binary_data/main.go 0000664 0000000 0000000 00000000751 12746334030 0023717 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("views/example", "", &ace.Options{
Asset: Asset,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/load_templates_from_binary_data/make_asset.sh 0000775 0000000 0000000 00000000047 12746334030 0025115 0 ustar 00root root 0000000 0000000 #!/bin/sh
go-bindata -o asset.go views
ace-0.0.5/examples/load_templates_from_binary_data/views/ 0000775 0000000 0000000 00000000000 12746334030 0023576 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/load_templates_from_binary_data/views/example.ace 0000664 0000000 0000000 00000000222 12746334030 0025677 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Load templates from binary data
body
h1 Load templates from binary data
ace-0.0.5/examples/pass_pipeline_to_included_template/ 0000775 0000000 0000000 00000000000 12746334030 0023163 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/pass_pipeline_to_included_template/README.md 0000664 0000000 0000000 00000000210 12746334030 0024433 0 ustar 00root root 0000000 0000000 # Pass a Pipeline (Parameter) to the Included Template
This example shows how to pass a pipeline (parameter) to the included template.
ace-0.0.5/examples/pass_pipeline_to_included_template/example.ace 0000664 0000000 0000000 00000000377 12746334030 0025277 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Pass a Pipeline (Parameter) to the Included Template
body
h1 Pass a Pipeline (Parameter) to the Included Template
ul
{{range .Pets}}
= include pet .
{{end}}
ace-0.0.5/examples/pass_pipeline_to_included_template/main.go 0000664 0000000 0000000 00000001354 12746334030 0024441 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
// Pet represents a pet.
type Pet struct {
Species string
Name string
Age int
}
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := map[string]interface{}{
"Pets": []Pet{
Pet{Species: "Dog", Name: "Taro", Age: 5},
Pet{Species: "Cat", Name: "Hanako", Age: 10},
Pet{Species: "Rabbit", Name: "Jiro", Age: 1},
},
}
if err := tpl.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/pass_pipeline_to_included_template/pet.ace 0000664 0000000 0000000 00000000045 12746334030 0024424 0 ustar 00root root 0000000 0000000 li {{.Species}}, {{.Name}}, {{.Age}}
ace-0.0.5/examples/plain_texts/ 0000775 0000000 0000000 00000000000 12746334030 0016416 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/plain_texts/README.md 0000664 0000000 0000000 00000000077 12746334030 0017701 0 ustar 00root root 0000000 0000000 # Plain Texts
This example shows how to generate plain texts.
ace-0.0.5/examples/plain_texts/example.ace 0000664 0000000 0000000 00000000400 12746334030 0020515 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Plain Texts
body
div
| This is a single line.
div
|
This is a
block line.
div
||
This is a
block line
with BR tags.
ace-0.0.5/examples/plain_texts/main.go 0000664 0000000 0000000 00000000706 12746334030 0017674 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/set_custom_functions/ 0000775 0000000 0000000 00000000000 12746334030 0020341 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/set_custom_functions/README.md 0000664 0000000 0000000 00000000110 12746334030 0021610 0 ustar 00root root 0000000 0000000 # Set Custom Functions
This example shows how to set custom functions.
ace-0.0.5/examples/set_custom_functions/example.ace 0000664 0000000 0000000 00000000172 12746334030 0022446 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Set Custom Functions
body
h1 {{Greeting "Ace"}}
ace-0.0.5/examples/set_custom_functions/main.go 0000664 0000000 0000000 00000001133 12746334030 0021612 0 ustar 00root root 0000000 0000000 package main
import (
"html/template"
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
funcMap := template.FuncMap{
"Greeting": func(s string) string {
return "Hello " + s
},
}
tpl, err := ace.Load("example", "", &ace.Options{
FuncMap: funcMap,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/set_default_value_to_the_yield_helper_method/ 0000775 0000000 0000000 00000000000 12746334030 0025206 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/set_default_value_to_the_yield_helper_method/README.md 0000664 0000000 0000000 00000000174 12746334030 0026467 0 ustar 00root root 0000000 0000000 # Set a Default Value to the Yield Helper Method
This example shows how to set a default value to the yield helper method.
ace-0.0.5/examples/set_default_value_to_the_yield_helper_method/base.ace 0000664 0000000 0000000 00000000563 12746334030 0026576 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Set a Default Value to the Yield Helper Method
body
h1 This is a base template
= yield main
| This message is rendered if the "main" content is not defined in the inner template.
= yield sub
| This message is rendered if the "sub" content is not defined in the inner template.
ace-0.0.5/examples/set_default_value_to_the_yield_helper_method/inner.ace 0000664 0000000 0000000 00000000111 12746334030 0026764 0 ustar 00root root 0000000 0000000 = content main
h2 This is a content named "main" of an inner template.
ace-0.0.5/examples/set_default_value_to_the_yield_helper_method/main.go 0000664 0000000 0000000 00000000710 12746334030 0026457 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("base", "inner", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/examples/single_template/ 0000775 0000000 0000000 00000000000 12746334030 0017240 5 ustar 00root root 0000000 0000000 ace-0.0.5/examples/single_template/README.md 0000664 0000000 0000000 00000000154 12746334030 0020517 0 ustar 00root root 0000000 0000000 # Single Template
This example shows how to build a web application which uses a single Ace template file.
ace-0.0.5/examples/single_template/example.ace 0000664 0000000 0000000 00000000162 12746334030 0021344 0 ustar 00root root 0000000 0000000 = doctype html
html lang=en
head
meta charset=utf-8
title Single Template
body
h1 Single Template
ace-0.0.5/examples/single_template/main.go 0000664 0000000 0000000 00000000706 12746334030 0020516 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/yosssi/ace"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("example", "", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
ace-0.0.5/file.go 0000664 0000000 0000000 00000000336 12746334030 0013516 0 ustar 00root root 0000000 0000000 package ace
// File represents a file.
type File struct {
path string
data []byte
}
// NewFile creates and returns a file.
func NewFile(path string, data []byte) *File {
return &File{
path: path,
data: data,
}
}
ace-0.0.5/formatter.go 0000664 0000000 0000000 00000002241 12746334030 0014577 0 ustar 00root root 0000000 0000000 package ace
import "bytes"
import "strings"
// File represents a file.
type outputFormatter interface {
OpeningElement(*bytes.Buffer, element) (int, error)
ClosingElement(*bytes.Buffer, element) (int, error)
WritingTextValue(*bytes.Buffer, element) (int, error)
}
type Formatter struct {
indent string
}
func newFormatter(indent string) outputFormatter {
f := &Formatter{
indent: indent,
}
return f
}
func (f *Formatter) OpeningElement(bf *bytes.Buffer, e element) (int, error) {
if e.IsControlElement() {
return 0, nil
}
base := e.Base()
if base.parent != nil && base.parent.IsBlockElement() {
return f.writeIndent(bf, base.ln.indent)
}
return 0, nil
}
func (f *Formatter) ClosingElement(bf *bytes.Buffer, e element) (int, error) {
if e.IsBlockElement() {
return f.writeIndent(bf, e.Base().ln.indent)
}
return 0, nil
}
func (f *Formatter) WritingTextValue(bf *bytes.Buffer, e element) (int, error) {
if e.IsBlockElement() {
return f.writeIndent(bf, e.Base().ln.indent+1)
}
return 0, nil
}
func (f *Formatter) writeIndent(bf *bytes.Buffer, depth int) (int, error) {
indent := "\n" + strings.Repeat(f.indent, depth)
return bf.WriteString(indent)
}
ace-0.0.5/formatter_test.go 0000664 0000000 0000000 00000002574 12746334030 0015647 0 ustar 00root root 0000000 0000000 package ace
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
var innerTemplate string = `
= content inner
section
h1 hello
`
func TestFormatter(t *testing.T) {
inner, _ := ioutil.TempFile("", "inner")
inner.WriteString(innerTemplate)
inner.Close()
os.Rename(inner.Name(), inner.Name()+".ace")
defer os.Remove(inner.Name() + ".ace")
for i, this := range []struct {
template string
expect string
}{
{
template: `
a
span foo
`,
expect: `foo`,
},
{
template: `
div
span foo
`,
expect: `
foo
`,
},
{
template: `
section
div
{{if true}}
span foo
{{end}}
div text
`,
expect: `