diff --git a/vendor/manifest b/vendor/manifest index 44085c2..064f43f 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -98,6 +98,12 @@ "revision": "5ec5e003b21ac1f06e175898413ada23a6797fc0", "branch": "master", "path": "/tiff" + }, + { + "importpath": "github.com/yosssi/ace", + "repository": "https://github.com/yosssi/ace", + "revision": "78e48a2f0ac5fb5a642585f96b03a5f47f7775f5", + "branch": "master" } ] } \ No newline at end of file diff --git a/vendor/src/github.com/yosssi/ace/LICENSE b/vendor/src/github.com/yosssi/ace/LICENSE new file mode 100644 index 0000000..73f313c --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/LICENSE @@ -0,0 +1,21 @@ +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. \ No newline at end of file diff --git a/vendor/src/github.com/yosssi/ace/README.md b/vendor/src/github.com/yosssi/ace/README.md new file mode 100644 index 0000000..8f17d9b --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/README.md @@ -0,0 +1,109 @@ +# Ace - HTML template engine for Go + +[![wercker status](https://app.wercker.com/status/8d3c657bcae7f31d10c8f88bbfa966d8/m "wercker status")](https://app.wercker.com/project/bykey/8d3c657bcae7f31d10c8f88bbfa966d8) +[![GoDoc](http://godoc.org/github.com/yosssi/ace?status.svg)](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 + + +
+
+ Ace is an HTML template engine for Go.
+ This engine simplifies HTML coding in Go web application development.
+
This is interpreted as a text.
+ Go to GitHub + +
+ This is a block text.
+ BR tags are inserted
+ automatically.
+
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 stirng. + +```ace +{{"You are using Internet Explorer 6.
+ = conditionalComment revealed !IE + diff --git a/vendor/src/github.com/yosssi/ace/examples/comments/main.go b/vendor/src/github.com/yosssi/ace/examples/comments/main.go new file mode 100644 index 0000000..594e7cb --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/comments/main.go @@ -0,0 +1,24 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/README.md b/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/README.md new file mode 100644 index 0000000..d24717c --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/README.md @@ -0,0 +1,3 @@ +# CSS and Javascript Helper Method + +This example shows how to use the css and javascript helper method. diff --git a/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/example.ace b/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/example.ace new file mode 100644 index 0000000..dfd2ef3 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/example.ace @@ -0,0 +1,18 @@ += 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); diff --git a/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/main.go b/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/main.go new file mode 100644 index 0000000..594e7cb --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/css_javascript_helper_method/main.go @@ -0,0 +1,24 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/README.md b/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/README.md new file mode 100644 index 0000000..aa09c1d --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/README.md @@ -0,0 +1,3 @@ +# 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. diff --git a/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/example.ace b/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/example.ace new file mode 100644 index 0000000..2f7ebdf --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/example.ace @@ -0,0 +1,7 @@ += doctype html +html lang=en + head + meta charset=utf-8 + title Dynamic Reload + body + h1 Dynamic Reload diff --git a/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/main.go b/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/main.go new file mode 100644 index 0000000..d034123 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/dynamic_reload/main.go @@ -0,0 +1,24 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/html_tags/README.md b/vendor/src/github.com/yosssi/ace/examples/html_tags/README.md new file mode 100644 index 0000000..34b286d --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/html_tags/README.md @@ -0,0 +1,3 @@ +# HTML Tags + +This example shows how to generate various HTML tags. diff --git a/vendor/src/github.com/yosssi/ace/examples/html_tags/example.ace b/vendor/src/github.com/yosssi/ace/examples/html_tags/example.ace new file mode 100644 index 0000000..7e81055 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/html_tags/example.ace @@ -0,0 +1,21 @@ += 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); diff --git a/vendor/src/github.com/yosssi/ace/examples/html_tags/main.go b/vendor/src/github.com/yosssi/ace/examples/html_tags/main.go new file mode 100644 index 0000000..594e7cb --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/html_tags/main.go @@ -0,0 +1,24 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/include_helper_method/README.md b/vendor/src/github.com/yosssi/ace/examples/include_helper_method/README.md new file mode 100644 index 0000000..4a71490 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/include_helper_method/README.md @@ -0,0 +1,3 @@ +# Include Helper Method + +This example shows how to use an include helper method. diff --git a/vendor/src/github.com/yosssi/ace/examples/include_helper_method/example.ace b/vendor/src/github.com/yosssi/ace/examples/include_helper_method/example.ace new file mode 100644 index 0000000..4670d39 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/include_helper_method/example.ace @@ -0,0 +1,8 @@ += doctype html +html lang=en + head + meta charset=utf-8 + title Include Helper Method + body + h1 This is a base template + = include inc diff --git a/vendor/src/github.com/yosssi/ace/examples/include_helper_method/inc.ace b/vendor/src/github.com/yosssi/ace/examples/include_helper_method/inc.ace new file mode 100644 index 0000000..7a5a4bc --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/include_helper_method/inc.ace @@ -0,0 +1 @@ +h2 This is an included template. diff --git a/vendor/src/github.com/yosssi/ace/examples/include_helper_method/main.go b/vendor/src/github.com/yosssi/ace/examples/include_helper_method/main.go new file mode 100644 index 0000000..594e7cb --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/include_helper_method/main.go @@ -0,0 +1,24 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/README.md b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/README.md new file mode 100644 index 0000000..fb72a49 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/README.md @@ -0,0 +1,13 @@ +# 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.** diff --git a/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/asset.go b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/asset.go new file mode 100644 index 0000000..638c7a2 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/asset.go @@ -0,0 +1,68 @@ +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, +} diff --git a/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/main.go b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/main.go new file mode 100644 index 0000000..ce32d81 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/main.go @@ -0,0 +1,26 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/make_asset.sh b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/make_asset.sh new file mode 100644 index 0000000..f2ffa2f --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/make_asset.sh @@ -0,0 +1,2 @@ +#!/bin/sh +go-bindata -o asset.go views diff --git a/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/views/example.ace b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/views/example.ace new file mode 100644 index 0000000..bfb6b14 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/load_templates_from_binary_data/views/example.ace @@ -0,0 +1,7 @@ += doctype html +html lang=en + head + meta charset=utf-8 + title Load templates from binary data + body + h1 Load templates from binary data diff --git a/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/README.md b/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/README.md new file mode 100644 index 0000000..8037d5c --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/README.md @@ -0,0 +1,3 @@ +# Pass a Pipeline (Parameter) to the Included Template + +This example shows how to pass a pipeline (parameter) to the included template. diff --git a/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/example.ace b/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/example.ace new file mode 100644 index 0000000..3d3c7b5 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/example.ace @@ -0,0 +1,11 @@ += 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}} diff --git a/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/main.go b/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/main.go new file mode 100644 index 0000000..fc01a8c --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/main.go @@ -0,0 +1,38 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/pet.ace b/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/pet.ace new file mode 100644 index 0000000..469dd9c --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/pass_pipeline_to_included_template/pet.ace @@ -0,0 +1 @@ +li {{.Species}}, {{.Name}}, {{.Age}} diff --git a/vendor/src/github.com/yosssi/ace/examples/plain_texts/README.md b/vendor/src/github.com/yosssi/ace/examples/plain_texts/README.md new file mode 100644 index 0000000..b01a502 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/plain_texts/README.md @@ -0,0 +1,3 @@ +# Plain Texts + +This example shows how to generate plain texts. diff --git a/vendor/src/github.com/yosssi/ace/examples/plain_texts/example.ace b/vendor/src/github.com/yosssi/ace/examples/plain_texts/example.ace new file mode 100644 index 0000000..e660ef6 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/plain_texts/example.ace @@ -0,0 +1,17 @@ += 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. diff --git a/vendor/src/github.com/yosssi/ace/examples/plain_texts/main.go b/vendor/src/github.com/yosssi/ace/examples/plain_texts/main.go new file mode 100644 index 0000000..594e7cb --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/plain_texts/main.go @@ -0,0 +1,24 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/README.md b/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/README.md new file mode 100644 index 0000000..df79161 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/README.md @@ -0,0 +1,3 @@ +# Set Custom Functions + +This example shows how to set custom functions. diff --git a/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/example.ace b/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/example.ace new file mode 100644 index 0000000..1d962c5 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/example.ace @@ -0,0 +1,7 @@ += doctype html +html lang=en + head + meta charset=utf-8 + title Set Custom Functions + body + h1 {{Greeting "Ace"}} diff --git a/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/main.go b/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/main.go new file mode 100644 index 0000000..f8b8ebd --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/set_custom_functions/main.go @@ -0,0 +1,32 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/README.md b/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/README.md new file mode 100644 index 0000000..37b807c --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/README.md @@ -0,0 +1,3 @@ +# Set a Default Value to the Yield Helper Method + +This example shows how to set a default value to the yield helper method. diff --git a/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/base.ace b/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/base.ace new file mode 100644 index 0000000..83513e2 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/base.ace @@ -0,0 +1,11 @@ += 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. diff --git a/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/inner.ace b/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/inner.ace new file mode 100644 index 0000000..d75f033 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/inner.ace @@ -0,0 +1,2 @@ += content main + h2 This is a content named "main" of an inner template. diff --git a/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/main.go b/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/main.go new file mode 100644 index 0000000..61c4cd0 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/set_default_value_to_the_yield_helper_method/main.go @@ -0,0 +1,24 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/examples/single_template/README.md b/vendor/src/github.com/yosssi/ace/examples/single_template/README.md new file mode 100644 index 0000000..1145984 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/single_template/README.md @@ -0,0 +1,3 @@ +# Single Template + +This example shows how to build a web application which uses a single Ace template file. diff --git a/vendor/src/github.com/yosssi/ace/examples/single_template/example.ace b/vendor/src/github.com/yosssi/ace/examples/single_template/example.ace new file mode 100644 index 0000000..64f68ed --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/single_template/example.ace @@ -0,0 +1,7 @@ += doctype html +html lang=en + head + meta charset=utf-8 + title Single Template + body + h1 Single Template diff --git a/vendor/src/github.com/yosssi/ace/examples/single_template/main.go b/vendor/src/github.com/yosssi/ace/examples/single_template/main.go new file mode 100644 index 0000000..594e7cb --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/examples/single_template/main.go @@ -0,0 +1,24 @@ +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) +} diff --git a/vendor/src/github.com/yosssi/ace/file.go b/vendor/src/github.com/yosssi/ace/file.go new file mode 100644 index 0000000..998ffa1 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/file.go @@ -0,0 +1,15 @@ +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, + } +} diff --git a/vendor/src/github.com/yosssi/ace/helper_method_conditional_comment.go b/vendor/src/github.com/yosssi/ace/helper_method_conditional_comment.go new file mode 100644 index 0000000..548b455 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/helper_method_conditional_comment.go @@ -0,0 +1,105 @@ +package ace + +import ( + "bytes" + "fmt" + "io" + "strings" +) + +// Comment types +const ( + commentTypeHidden = "hidden" + commentTypeRevealed = "revealed" +) + +// helperMethodConditionalComment represents a helper method +// conditional comment. +type helperMethodConditionalComment struct { + elementBase + commentType string + condition string +} + +// WriteTo writes data to w. +func (e *helperMethodConditionalComment) WriteTo(w io.Writer) (int64, error) { + var bf bytes.Buffer + + // Write an open tag. + bf.WriteString(e.opts.DelimLeft) + bf.WriteString(preDefinedFuncNameHTML) + bf.WriteString(space) + bf.WriteString(doubleQuote) + bf.WriteString(lt) + bf.WriteString(exclamation) + bf.WriteString(doubleQuote) + bf.WriteString(e.opts.DelimRight) + if e.commentType == commentTypeHidden { + bf.WriteString(hyphen) + bf.WriteString(hyphen) + } + bf.WriteString(bracketOpen) + bf.WriteString("if ") + bf.WriteString(e.condition) + bf.WriteString(bracketClose) + bf.WriteString(gt) + + bf.WriteString(lf) + + // Write the children's HTML. + if i, err := e.writeChildren(&bf); err != nil { + return i, err + } + + // Write a close tag. + bf.WriteString(e.opts.DelimLeft) + bf.WriteString(preDefinedFuncNameHTML) + bf.WriteString(space) + bf.WriteString(doubleQuote) + bf.WriteString(lt) + bf.WriteString(exclamation) + bf.WriteString(doubleQuote) + bf.WriteString(e.opts.DelimRight) + bf.WriteString(bracketOpen) + bf.WriteString("endif") + bf.WriteString(bracketClose) + if e.commentType == commentTypeHidden { + bf.WriteString(hyphen) + bf.WriteString(hyphen) + } + bf.WriteString(gt) + + // Write the buffer. + i, err := w.Write(bf.Bytes()) + + return int64(i), err +} + +// ContainPlainText returns true. +func (e *helperMethodConditionalComment) ContainPlainText() bool { + return true +} + +// newHelperMethodConditionalComment creates and returns an HTML comment. +func newHelperMethodConditionalComment(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodConditionalComment, error) { + switch len(ln.tokens) { + case 2: + return nil, fmt.Errorf("no comment type is specified [file: %s][line: %d]", ln.fileName(), ln.no) + case 3: + return nil, fmt.Errorf("no condition is specified [file: %s][line: %d]", ln.fileName(), ln.no) + } + + commentType := ln.tokens[2] + + if commentType != commentTypeHidden && commentType != commentTypeRevealed { + return nil, fmt.Errorf("the comment type is invalid [file: %s][line: %d]", ln.fileName(), ln.no) + } + + e := &helperMethodConditionalComment{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + commentType: commentType, + condition: strings.Join(ln.tokens[3:], space), + } + + return e, nil +} diff --git a/vendor/src/github.com/yosssi/ace/helper_method_content.go b/vendor/src/github.com/yosssi/ace/helper_method_content.go new file mode 100644 index 0000000..a020cf5 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/helper_method_content.go @@ -0,0 +1,53 @@ +package ace + +import ( + "bytes" + "fmt" + "io" +) + +// helperMethodContent represents a helper method content. +type helperMethodContent struct { + elementBase + name string +} + +// WriteTo writes data to w. +func (e *helperMethodContent) WriteTo(w io.Writer) (int64, error) { + var bf bytes.Buffer + + inner := e.src.inner + if inner == nil { + return 0, fmt.Errorf("inner is not specified [file: %s][line: %d]", e.ln.fileName(), e.ln.no) + } + + // Write a define action. + bf.WriteString(fmt.Sprintf(actionDefine, e.opts.DelimLeft, inner.path+doubleColon+e.name, e.opts.DelimRight)) + + // Write the children's HTML. + if i, err := e.writeChildren(&bf); err != nil { + return i, err + } + + // Write an end action. + bf.WriteString(fmt.Sprintf(actionEnd, e.opts.DelimLeft, e.opts.DelimRight)) + + // Write the buffer. + i, err := w.Write(bf.Bytes()) + + return int64(i), err +} + +// newHelperMethodContent creates and returns a helper method content. +func newHelperMethodContent(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodContent, error) { + if len(ln.tokens) < 3 || ln.tokens[2] == "" { + return nil, fmt.Errorf("no name is specified [file: %s][line: %d]", ln.fileName(), ln.no) + } + + e := &helperMethodContent{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + name: ln.tokens[2], + } + + return e, nil +} diff --git a/vendor/src/github.com/yosssi/ace/helper_method_css.go b/vendor/src/github.com/yosssi/ace/helper_method_css.go new file mode 100644 index 0000000..df800ae --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/helper_method_css.go @@ -0,0 +1,51 @@ +package ace + +import ( + "bytes" + "io" +) + +// helperMethodCSS represents a helper method css. +type helperMethodCSS struct { + elementBase +} + +// WriteTo writes data to w. +func (e *helperMethodCSS) WriteTo(w io.Writer) (int64, error) { + var bf bytes.Buffer + + // Write an open tag. + bf.WriteString(lt) + bf.WriteString(`style type="text/css"`) + bf.WriteString(gt) + + bf.WriteString(lf) + + // Write the children's HTML. + if i, err := e.writeChildren(&bf); err != nil { + return i, err + } + + // Write an open tag. + bf.WriteString(lt) + bf.WriteString(slash) + bf.WriteString("style") + bf.WriteString(gt) + + // Write the buffer. + i, err := w.Write(bf.Bytes()) + + return int64(i), err +} + +// ContainPlainText returns true. +func (e *helperMethodCSS) ContainPlainText() bool { + return true +} + +// helperMethodCSS creates and returns a helper method css. +func newHelperMethodCSS(ln *line, rslt *result, src *source, parent element, opts *Options) *helperMethodCSS { + return &helperMethodCSS{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + } +} diff --git a/vendor/src/github.com/yosssi/ace/helper_method_doctype.go b/vendor/src/github.com/yosssi/ace/helper_method_doctype.go new file mode 100644 index 0000000..bf1918d --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/helper_method_doctype.go @@ -0,0 +1,50 @@ +package ace + +import ( + "fmt" + "io" +) + +// Doctypes +var doctypes = map[string]string{ + "html": ``, + "xml": ``, + "transitional": ``, + "strict": ``, + "frameset": ``, + "1.1": ``, + "basic": ``, + "mobile": ``, +} + +// helperMethodDoctype represents a helper method doctype. +type helperMethodDoctype struct { + elementBase + doctype string +} + +// WriteTo writes data to w. +func (e *helperMethodDoctype) WriteTo(w io.Writer) (int64, error) { + i, err := w.Write([]byte(doctypes[e.doctype])) + return int64(i), err +} + +// newHelperMethodDoctype creates and returns a helper method doctype. +func newHelperMethodDoctype(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodDoctype, error) { + if len(ln.tokens) < 3 { + return nil, fmt.Errorf("doctype is not specified [file: %s][line: %d]", ln.fileName(), ln.no) + } + + doctype := ln.tokens[2] + + if _, ok := doctypes[doctype]; !ok { + return nil, fmt.Errorf("doctype is invalid [file: %s][line: %d][doctype: %s]", ln.fileName(), ln.no, doctype) + } + + e := &helperMethodDoctype{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + doctype: doctype, + } + + return e, nil +} diff --git a/vendor/src/github.com/yosssi/ace/helper_method_include.go b/vendor/src/github.com/yosssi/ace/helper_method_include.go new file mode 100644 index 0000000..bdcafd2 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/helper_method_include.go @@ -0,0 +1,50 @@ +package ace + +import ( + "fmt" + "io" + "strings" +) + +// helperMethodInclude represents a helper method include. +type helperMethodInclude struct { + elementBase + templateName string + pipeline string +} + +// WriteTo writes data to w. +func (e *helperMethodInclude) WriteTo(w io.Writer) (int64, error) { + var s string + + if e.pipeline == "" { + s = fmt.Sprintf(actionTemplate, e.opts.DelimLeft, e.templateName, e.opts.DelimRight) + } else { + s = fmt.Sprintf(actionTemplateWithPipeline, e.opts.DelimLeft, e.templateName, e.pipeline, e.opts.DelimRight) + } + + i, err := w.Write([]byte(s)) + + return int64(i), err +} + +// newHelperMethodInclude creates and returns a helper method include. +func newHelperMethodInclude(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodInclude, error) { + if len(ln.tokens) < 3 { + return nil, fmt.Errorf("no template name is specified [file: %s][line: %d]", ln.fileName(), ln.no) + } + + var pipeline string + + if len(ln.tokens) > 3 { + pipeline = strings.Join(ln.tokens[3:], space) + } + + e := &helperMethodInclude{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + templateName: ln.tokens[2], + pipeline: pipeline, + } + + return e, nil +} diff --git a/vendor/src/github.com/yosssi/ace/helper_method_javascript.go b/vendor/src/github.com/yosssi/ace/helper_method_javascript.go new file mode 100644 index 0000000..d7af21a --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/helper_method_javascript.go @@ -0,0 +1,51 @@ +package ace + +import ( + "bytes" + "io" +) + +// helperMethodJavascript represents a helper method javascript. +type helperMethodJavascript struct { + elementBase +} + +// WriteTo writes data to w. +func (e *helperMethodJavascript) WriteTo(w io.Writer) (int64, error) { + var bf bytes.Buffer + + // Write an open tag. + bf.WriteString(lt) + bf.WriteString(`script type="text/javascript"`) + bf.WriteString(gt) + + bf.WriteString(lf) + + // Write the children's HTML. + if i, err := e.writeChildren(&bf); err != nil { + return i, err + } + + // Write an open tag. + bf.WriteString(lt) + bf.WriteString(slash) + bf.WriteString("script") + bf.WriteString(gt) + + // Write the buffer. + i, err := w.Write(bf.Bytes()) + + return int64(i), err +} + +// ContainPlainText returns true. +func (e *helperMethodJavascript) ContainPlainText() bool { + return true +} + +// helperMethodJavascript creates and returns a helper method javascript. +func newHelperMethodJavascript(ln *line, rslt *result, src *source, parent element, opts *Options) *helperMethodJavascript { + return &helperMethodJavascript{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + } +} diff --git a/vendor/src/github.com/yosssi/ace/helper_method_yield.go b/vendor/src/github.com/yosssi/ace/helper_method_yield.go new file mode 100644 index 0000000..b34a010 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/helper_method_yield.go @@ -0,0 +1,60 @@ +package ace + +import ( + "bytes" + "fmt" + "io" +) + +// helperMethodYield represents a helper method yield. +type helperMethodYield struct { + elementBase + templateName string +} + +// WriteTo writes data to w. +func (e *helperMethodYield) WriteTo(w io.Writer) (int64, error) { + var bf bytes.Buffer + + inner := e.src.inner + if inner == nil { + return 0, fmt.Errorf("inner is not specified [file: %s][line: %d]", e.ln.fileName(), e.ln.no) + } + + var templateExists bool + + for _, innerE := range e.rslt.inner { + ln := innerE.Base().ln + if ln.isHelperMethodOf(helperMethodNameContent) && len(ln.tokens) > 2 && ln.tokens[2] == e.templateName { + templateExists = true + break + } + } + + if templateExists { + bf.WriteString(fmt.Sprintf(actionTemplateWithPipeline, e.opts.DelimLeft, inner.path+doubleColon+e.templateName, dot, e.opts.DelimRight)) + } else { + // Write the children's HTML. + if i, err := e.writeChildren(&bf); err != nil { + return i, err + } + } + + i, err := w.Write(bf.Bytes()) + + return int64(i), err +} + +// newHelperMethodYield creates and returns a helper method yield. +func newHelperMethodYield(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodYield, error) { + if len(ln.tokens) < 3 { + return nil, fmt.Errorf("no template name is specified [file: %s][line: %d]", ln.fileName(), ln.no) + } + + e := &helperMethodYield{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + templateName: ln.tokens[2], + } + + return e, nil +} diff --git a/vendor/src/github.com/yosssi/ace/html_comment.go b/vendor/src/github.com/yosssi/ace/html_comment.go new file mode 100644 index 0000000..9e863e6 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/html_comment.go @@ -0,0 +1,69 @@ +package ace + +import ( + "bytes" + "io" + "strings" +) + +// htmlComment represents an HTML comment. +type htmlComment struct { + elementBase +} + +// WriteTo writes data to w. +func (e *htmlComment) WriteTo(w io.Writer) (int64, error) { + var bf bytes.Buffer + + // Write an open tag. + bf.WriteString(e.opts.DelimLeft) + bf.WriteString(preDefinedFuncNameHTML) + bf.WriteString(space) + bf.WriteString(doubleQuote) + bf.WriteString(lt) + bf.WriteString(exclamation) + bf.WriteString(doubleQuote) + bf.WriteString(e.opts.DelimRight) + bf.WriteString(hyphen) + bf.WriteString(hyphen) + + // Write the HTML comment + if len(e.ln.tokens) > 1 { + bf.WriteString(space) + bf.WriteString(strings.Join(e.ln.tokens[1:], space)) + } + + // Write the children's HTML. + if len(e.children) > 0 { + bf.WriteString(lf) + + if i, err := e.writeChildren(&bf); err != nil { + return i, err + } + } else { + bf.WriteString(space) + + } + + // Write a close tag. + bf.WriteString(hyphen) + bf.WriteString(hyphen) + bf.WriteString(gt) + + // Write the buffer. + i, err := w.Write(bf.Bytes()) + + return int64(i), err +} + +// ContainPlainText returns true. +func (e *htmlComment) ContainPlainText() bool { + return true +} + +// newHTMLComment creates and returns an HTML comment. +func newHTMLComment(ln *line, rslt *result, src *source, parent element, opts *Options) *htmlComment { + return &htmlComment{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + } +} diff --git a/vendor/src/github.com/yosssi/ace/html_tag.go b/vendor/src/github.com/yosssi/ace/html_tag.go new file mode 100644 index 0000000..a971108 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/html_tag.go @@ -0,0 +1,305 @@ +package ace + +import ( + "bytes" + "fmt" + "io" + "strings" +) + +// Tag names +const ( + tagNameDiv = "div" +) + +// Attribute names +const ( + attributeNameID = "id" +) + +// htmlAttribute represents an HTML attribute. +type htmlAttribute struct { + key string + value string +} + +// htmlTag represents an HTML tag. +type htmlTag struct { + elementBase + tagName string + id string + classes []string + containPlainText bool + insertBr bool + attributes []htmlAttribute + textValue string +} + +// WriteTo writes data to w. +func (e *htmlTag) WriteTo(w io.Writer) (int64, error) { + var bf bytes.Buffer + + // Write an open tag. + bf.WriteString(lt) + bf.WriteString(e.tagName) + // Write an id. + if e.id != "" { + bf.WriteString(space) + bf.WriteString(attributeNameID) + bf.WriteString(equal) + bf.WriteString(doubleQuote) + bf.WriteString(e.id) + bf.WriteString(doubleQuote) + } + // Write classes. + if len(e.classes) > 0 { + bf.WriteString(space) + bf.WriteString(e.opts.AttributeNameClass) + bf.WriteString(equal) + bf.WriteString(doubleQuote) + for i, class := range e.classes { + if i > 0 { + bf.WriteString(space) + } + bf.WriteString(class) + } + bf.WriteString(doubleQuote) + } + // Write attributes. + if len(e.attributes) > 0 { + + for _, a := range e.attributes { + bf.WriteString(space) + bf.WriteString(a.key) + if a.value != "" { + bf.WriteString(equal) + bf.WriteString(doubleQuote) + bf.WriteString(a.value) + bf.WriteString(doubleQuote) + } + } + } + bf.WriteString(gt) + + // Write a text value + if e.textValue != "" { + bf.WriteString(e.textValue) + } + + if e.containPlainText { + bf.WriteString(lf) + } + + // Write children's HTML. + if i, err := e.writeChildren(&bf); err != nil { + return i, err + } + + // Write a close tag. + if !e.noCloseTag() { + bf.WriteString(lt) + bf.WriteString(slash) + bf.WriteString(e.tagName) + bf.WriteString(gt) + } + + // Write the buffer. + i, err := w.Write(bf.Bytes()) + + return int64(i), err +} + +// ContainPlainText returns the HTML tag's containPlainText field. +func (e *htmlTag) ContainPlainText() bool { + return e.containPlainText +} + +// InsertBr returns true if the br tag is inserted to the line. +func (e *htmlTag) InsertBr() bool { + return e.insertBr +} + +// setAttributes parses the tokens and set attributes to the element. +func (e *htmlTag) setAttributes() error { + parsedTokens := e.parseTokens() + + var i int + var token string + var setTextValue bool + + // Set attributes to the element. + for i, token = range parsedTokens { + kv := strings.Split(token, equal) + + if len(kv) < 2 { + setTextValue = true + break + } + + k := kv[0] + v := strings.Join(kv[1:], equal) + + // Remove the prefix and suffix of the double quotes. + if len(v) > 1 && strings.HasPrefix(v, doubleQuote) && strings.HasSuffix(v, doubleQuote) { + v = v[1 : len(v)-1] + } + + switch k { + case attributeNameID: + if e.id != "" { + return fmt.Errorf("multiple IDs are specified [file: %s][line: %d]", e.ln.fileName(), e.ln.no) + } + e.id = v + case e.opts.AttributeNameClass: + e.classes = append(e.classes, strings.Split(v, space)...) + default: + e.attributes = append(e.attributes, htmlAttribute{k, v}) + } + } + + // Set a text value to the element. + if setTextValue { + e.textValue = strings.Join(parsedTokens[i:], space) + } + + return nil +} + +// noCloseTag returns true is the HTML tag has no close tag. +func (e *htmlTag) noCloseTag() bool { + for _, name := range e.opts.NoCloseTagNames { + if e.tagName == name { + return true + } + } + + return false +} + +// newHTMLTag creates and returns an HTML tag. +func newHTMLTag(ln *line, rslt *result, src *source, parent element, opts *Options) (*htmlTag, error) { + if len(ln.tokens) < 1 { + return nil, fmt.Errorf("an HTML tag is not specified [file: %s][line: %d]", ln.fileName(), ln.no) + } + + s := ln.tokens[0] + + tagName := extractTagName(s) + + id, err := extractID(s, ln) + if err != nil { + return nil, err + } + + classes := extractClasses(s) + + e := &htmlTag{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + tagName: tagName, + id: id, + classes: classes, + containPlainText: strings.HasSuffix(s, dot), + insertBr: strings.HasSuffix(s, doubleDot), + attributes: make([]htmlAttribute, 0, 2), + } + + if err := e.setAttributes(); err != nil { + return nil, err + } + + return e, nil +} + +// extractTag extracts and returns a tag. +func extractTagName(s string) string { + tagName := strings.Split(strings.Split(s, sharp)[0], dot)[0] + + if tagName == "" { + tagName = tagNameDiv + } + + return tagName +} + +// extractID extracts and returns an ID. +func extractID(s string, ln *line) (string, error) { + tokens := strings.Split(s, sharp) + + l := len(tokens) + + if l < 2 { + return "", nil + } + + if l > 2 { + return "", fmt.Errorf("multiple IDs are specified [file: %s][line: %d]", ln.fileName(), ln.no) + } + + return strings.Split(tokens[1], dot)[0], nil +} + +// extractClasses extracts and returns classes. +func extractClasses(s string) []string { + var classes []string + + for i, token := range strings.Split(s, dot) { + if i == 0 { + continue + } + + class := strings.Split(token, sharp)[0] + + if class == "" { + continue + } + + classes = append(classes, class) + } + + return classes +} + +// parseTokens parses the tokens and return them +func (e *htmlTag) parseTokens() []string { + var inQuote bool + var inDelim bool + var tokens []string + var token string + + str := strings.Join(e.ln.tokens[1:], space) + for _, chr := range str { + switch c := string(chr); c { + case space: + if inQuote || inDelim { + token += c + } else { + tokens = append(tokens, token) + token = "" + } + case doubleQuote: + if !inDelim { + if inQuote { + inQuote = false + } else { + inQuote = true + } + } + token += c + default: + token += c + if inDelim { + if strings.HasSuffix(token, e.opts.DelimRight) { + inDelim = false + } + } else { + if strings.HasSuffix(token, e.opts.DelimLeft) { + inDelim = true + } + } + } + } + if len(token) > 0 { + tokens = append(tokens, token) + } + return tokens +} diff --git a/vendor/src/github.com/yosssi/ace/line.go b/vendor/src/github.com/yosssi/ace/line.go new file mode 100644 index 0000000..9032bdd --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/line.go @@ -0,0 +1,117 @@ +package ace + +import ( + "fmt" + "strings" +) + +const unicodeSpace = 32 + +const indentTop = 0 + +// line represents a line of codes. +type line struct { + no int + str string + indent int + tokens []string + opts *Options + file *File +} + +// isEmpty returns true if the line is empty. +func (l *line) isEmpty() bool { + return strings.TrimSpace(l.str) == "" +} + +// isTopIndent returns true if the line's indent is the top level. +func (l *line) isTopIndent() bool { + return l.indent == indentTop +} + +// isHelperMethod returns true if the line is a helper method. +func (l *line) isHelperMethod() bool { + return len(l.tokens) > 1 && l.tokens[0] == equal +} + +// isHelperMethodOf returns true if the line is a specified helper method. +func (l *line) isHelperMethodOf(name string) bool { + return l.isHelperMethod() && l.tokens[1] == name +} + +// isPlainText returns true if the line is a plain text. +func (l *line) isPlainText() bool { + return len(l.tokens) > 0 && (l.tokens[0] == pipe || l.tokens[0] == doublePipe) +} + +// isComment returns true if the line is a comment. +func (l *line) isComment() bool { + return len(l.tokens) > 0 && l.tokens[0] == slash +} + +// isHTMLComment returns true if the line is an HTML comment. +func (l *line) isHTMLComment() bool { + return len(l.tokens) > 0 && l.tokens[0] == slash+slash +} + +// isAction returns true if the line is an action. +func (l *line) isAction() bool { + str := strings.TrimSpace(l.str) + return strings.HasPrefix(str, l.opts.DelimLeft) && strings.HasSuffix(str, l.opts.DelimRight) +} + +// fileName returns the file name. +func (l *line) fileName() string { + return l.file.path + dot + l.opts.Extension +} + +// childOf returns true is the line is a child of the element. +func (l *line) childOf(parent element) (bool, error) { + var ok bool + var err error + + switch { + case l.isEmpty(): + ok = true + case parent.ContainPlainText(): + switch { + case parent.Base().ln.indent < l.indent: + ok = true + } + default: + switch { + case l.indent == parent.Base().ln.indent+1: + ok = true + case l.indent > parent.Base().ln.indent+1: + err = fmt.Errorf("the indent is invalid [file: %s][line: %d]", l.fileName(), l.no) + } + } + + return ok, err +} + +// newLine creates and returns a line. +func newLine(no int, str string, opts *Options, f *File) *line { + return &line{ + no: no, + str: str, + indent: indent(str), + tokens: strings.Split(strings.TrimLeft(str, space), space), + opts: opts, + file: f, + } +} + +// indent returns the line's indent. +func indent(str string) int { + var i int + + for _, b := range str { + if b != unicodeSpace { + break + } + i++ + } + + return i / 2 +} diff --git a/vendor/src/github.com/yosssi/ace/options.go b/vendor/src/github.com/yosssi/ace/options.go new file mode 100644 index 0000000..a2a7a2c --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/options.go @@ -0,0 +1,93 @@ +package ace + +import "html/template" + +// Defaults +const ( + defaultExtension = "ace" + defaultDelimLeft = "{{" + defaultDelimRight = "}}" + defaultAttributeNameClass = "class" +) + +// Default NoCloseTagNames +var defaultNoCloseTagNames = []string{ + "br", + "hr", + "img", + "input", + "link", + "meta", +} + +// Options represents options for the template engine. +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 + // 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 +} + +// InitializeOptions initializes the options. +func InitializeOptions(opts *Options) *Options { + if opts == nil { + opts = &Options{} + } + + if opts.Extension == "" { + opts.Extension = defaultExtension + } + + if opts.DelimLeft == "" { + opts.DelimLeft = defaultDelimLeft + } + + if opts.DelimRight == "" { + opts.DelimRight = defaultDelimRight + } + + if opts.AttributeNameClass == "" { + opts.AttributeNameClass = defaultAttributeNameClass + } + if opts.NoCloseTagNames == nil { + opts.NoCloseTagNames = make([]string, len(defaultNoCloseTagNames)) + copy(opts.NoCloseTagNames, defaultNoCloseTagNames) + } + + return opts +} + +// AddNoCloseTagName appends name to .NoCloseTagNames set. +func (opts *Options) AddNoCloseTagName(name string) { + opts.NoCloseTagNames = append(opts.NoCloseTagNames, name) +} + +// DeleteNoCloseTagName deletes name from .NoCloseTagNames set. +func (opts *Options) DeleteNoCloseTagName(name string) { + var newset []string + for _, n := range opts.NoCloseTagNames { + if n != name { + newset = append(newset, n) + } + } + opts.NoCloseTagNames = newset +} diff --git a/vendor/src/github.com/yosssi/ace/parse.go b/vendor/src/github.com/yosssi/ace/parse.go new file mode 100644 index 0000000..e8df8c2 --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/parse.go @@ -0,0 +1,114 @@ +package ace + +import "strings" + +// ParseSource parses the source and returns the result. +func ParseSource(src *source, opts *Options) (*result, error) { + // Initialize the options. + opts = InitializeOptions(opts) + + rslt := newResult(nil, nil, nil) + + base, err := parseBytes(src.base.data, rslt, src, opts, src.base) + if err != nil { + return nil, err + } + + inner, err := parseBytes(src.inner.data, rslt, src, opts, src.inner) + if err != nil { + return nil, err + } + + includes := make(map[string][]element) + + for _, f := range src.includes { + includes[f.path], err = parseBytes(f.data, rslt, src, opts, f) + if err != nil { + return nil, err + } + } + + rslt.base = base + rslt.inner = inner + rslt.includes = includes + + return rslt, nil +} + +// parseBytes parses the byte data and returns the elements. +func parseBytes(data []byte, rslt *result, src *source, opts *Options, f *File) ([]element, error) { + var elements []element + + lines := strings.Split(formatLF(string(data)), lf) + + i := 0 + l := len(lines) + + // Ignore the last empty line. + if l > 0 && lines[l-1] == "" { + l-- + } + + for i < l { + // Fetch a line. + ln := newLine(i+1, lines[i], opts, f) + i++ + + // Ignore the empty line. + if ln.isEmpty() { + continue + } + + if ln.isTopIndent() { + e, err := newElement(ln, rslt, src, nil, opts) + if err != nil { + return nil, err + } + + // Append child elements to the element. + if err := appendChildren(e, rslt, lines, &i, l, src, opts, f); err != nil { + return nil, err + } + + elements = append(elements, e) + } + } + + return elements, nil +} + +// appendChildren parses the lines and appends the children to the element. +func appendChildren(parent element, rslt *result, lines []string, i *int, l int, src *source, opts *Options, f *File) error { + for *i < l { + // Fetch a line. + ln := newLine(*i+1, lines[*i], opts, f) + + // Check if the line is a child of the parent. + ok, err := ln.childOf(parent) + + if err != nil { + return err + } + + if !ok { + return nil + } + + child, err := newElement(ln, rslt, src, parent, opts) + if err != nil { + return err + } + + parent.AppendChild(child) + + *i++ + + if child.CanHaveChildren() { + if err := appendChildren(child, rslt, lines, i, l, src, opts, f); err != nil { + return err + } + } + } + + return nil +} diff --git a/vendor/src/github.com/yosssi/ace/plain_text.go b/vendor/src/github.com/yosssi/ace/plain_text.go new file mode 100644 index 0000000..7f6490a --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/plain_text.go @@ -0,0 +1,57 @@ +package ace + +import ( + "bytes" + "io" + "strings" +) + +// plainText represents a plain text. +type plainText struct { + elementBase + insertBr bool +} + +// WriteTo writes data to w. +func (e *plainText) WriteTo(w io.Writer) (int64, error) { + var bf bytes.Buffer + + // Write the plain text. + bf.WriteString(strings.Join(e.ln.tokens[1:], space)) + + if len(e.ln.tokens) > 1 && e.insertBr { + bf.WriteString(htmlBr) + } + + // Write the children's HTML. + if len(e.children) > 0 { + bf.WriteString(lf) + + if i, err := e.writeChildren(&bf); err != nil { + return i, err + } + } + + // Write the buffer. + i, err := w.Write(bf.Bytes()) + + return int64(i), err +} + +// ContainPlainText returns true. +func (e *plainText) ContainPlainText() bool { + return true +} + +// InsertBr returns true if the br tag is inserted to the line. +func (e *plainText) InsertBr() bool { + return e.insertBr +} + +// newPlainText creates and returns a plain text. +func newPlainText(ln *line, rslt *result, src *source, parent element, opts *Options) *plainText { + return &plainText{ + elementBase: newElementBase(ln, rslt, src, parent, opts), + insertBr: ln.tokens[0] == doublePipe, + } +} diff --git a/vendor/src/github.com/yosssi/ace/plain_text_inner.go b/vendor/src/github.com/yosssi/ace/plain_text_inner.go new file mode 100644 index 0000000..3a70adb --- /dev/null +++ b/vendor/src/github.com/yosssi/ace/plain_text_inner.go @@ -0,0 +1,44 @@ +package ace + +import "io" + +// HTML +const ( + htmlBr = "