go vendor
This commit is contained in:
59
vendor/github.com/revel/modules/template-engine/ace/README.md
generated
vendored
Normal file
59
vendor/github.com/revel/modules/template-engine/ace/README.md
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
# Ace
|
||||
The [ACE](https://github.com/yosssi/ace) Templating Plugin
|
||||
|
||||
- Ace templates have full access to the revel.TemplateFuncs, any function
|
||||
defined in there can be used by the this engine
|
||||
|
||||
- Ace files must be identified by using a `shebang` on the first line
|
||||
(preferred method) or changing the file extension to home.ace.html.
|
||||
By default the operation of revel assumes just a `.html` extension for
|
||||
controller responses so it would make more sense to use the shebang
|
||||
- Ace templates can be set to be case sensitive by setting
|
||||
`ace.tempate.caseinsensitive=false`, default is not case sensitive. If case sensitivity
|
||||
is off internal imports must be done using lower case
|
||||
- All function registered in `revel.TemplateFuncs` are available for use
|
||||
inside the ace framework
|
||||
|
||||
##### Details
|
||||
Ace is a little different of a templating system, its output is a
|
||||
standard go template but there is no concept of template sets,
|
||||
instead you build a composite template using
|
||||
a *base* template and an *inner* template. The
|
||||
*inner* template can only contain items like :
|
||||
```
|
||||
= content main
|
||||
h2 Inner Template - Main : {{.Msg}}
|
||||
|
||||
= content sub
|
||||
h3 Inner Template - Sub : {{.Msg}}
|
||||
|
||||
```
|
||||
The base template can contain items like
|
||||
```
|
||||
= 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}}');
|
||||
```
|
||||
|
||||
You are allowed to include one *inner* template with the base template,
|
||||
to do so in revel you can extend your controller from the ace controller
|
||||
and call `RenderAceTemplate(base ,inner string)` which will insert
|
||||
the inner template using the outer template.
|
||||
|
||||
The ace engine requires that you explicitly set the template type on the
|
||||
template itself by either using the shebang method on the first line
|
||||
like `#! ace` or having the file name like `template.ace.html`
|
||||
either method will work.
|
||||
|
3
vendor/github.com/revel/modules/template-engine/ace/ace.go
generated
vendored
Normal file
3
vendor/github.com/revel/modules/template-engine/ace/ace.go
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package ace
|
||||
|
||||
// Required for vendoring see golang.org/issue/13832
|
13
vendor/github.com/revel/modules/template-engine/ace/app/controllers/ace.go
generated
vendored
Normal file
13
vendor/github.com/revel/modules/template-engine/ace/app/controllers/ace.go
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/revel/revel"
|
||||
|
||||
type AceController struct {
|
||||
*revel.Controller
|
||||
}
|
||||
|
||||
// Called to render the ace template inner
|
||||
func (c *AceController) RenderAceTemplate(base, inner string) revel.Result {
|
||||
c.ViewArgs["ace_inner"] = inner
|
||||
return c.RenderTemplate(base)
|
||||
}
|
139
vendor/github.com/revel/modules/template-engine/ace/app/init.go
generated
vendored
Normal file
139
vendor/github.com/revel/modules/template-engine/ace/app/init.go
generated
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/revel/revel"
|
||||
"github.com/yosssi/ace"
|
||||
"html/template"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const ACE_TEMPLATE = "ace"
|
||||
|
||||
// Adapter for Go Templates.
|
||||
type AceTemplate struct {
|
||||
*template.Template
|
||||
engine *AceEngine
|
||||
*revel.TemplateView
|
||||
File *ace.File
|
||||
Inner *ace.File
|
||||
}
|
||||
|
||||
// A bit trick of an implementation
|
||||
// If the arg contains an ace_inner field then that will be used
|
||||
// to fetch a new template
|
||||
func (acetmpl AceTemplate) Render(wr io.Writer, arg interface{}) error {
|
||||
// We can redirect this render to another template if the arguments contain ace_content in them
|
||||
if argmap, ok := arg.(map[string]interface{}); ok {
|
||||
if acecontentraw, ok := argmap["ace-inner"]; ok {
|
||||
acecontent := acecontentraw.(string)
|
||||
newtemplatename := acetmpl.TemplateName + "-" + acecontent
|
||||
// Now lookup the template again
|
||||
if _, ok := acetmpl.engine.templatesByName[newtemplatename]; !ok {
|
||||
if inner, ok := acetmpl.engine.templatesByName[acecontent]; !ok {
|
||||
return fmt.Errorf("Inner content %s not found in ace templates", acecontent)
|
||||
} else {
|
||||
acetmpl.engine.templatesByName[newtemplatename] = &AceTemplate{
|
||||
File: acetmpl.File,
|
||||
Inner: inner.File,
|
||||
engine: acetmpl.engine,
|
||||
TemplateView: acetmpl.TemplateView}
|
||||
}
|
||||
|
||||
}
|
||||
return acetmpl.engine.templatesByName[newtemplatename].renderInternal(wr, arg)
|
||||
}
|
||||
}
|
||||
return acetmpl.renderInternal(wr, arg)
|
||||
}
|
||||
|
||||
func (acetmpl AceTemplate) renderInternal(wr io.Writer, arg interface{}) error {
|
||||
if acetmpl.Template == nil {
|
||||
// Compile the template first
|
||||
if acetmpl.Inner == nil {
|
||||
acetmpl.Inner = ace.NewFile("", nil)
|
||||
}
|
||||
source := ace.NewSource(acetmpl.File, acetmpl.Inner, acetmpl.engine.files)
|
||||
result, err := ace.ParseSource(source, acetmpl.engine.Options)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if gtemplate, err := ace.CompileResult(acetmpl.TemplateName, result, acetmpl.engine.Options); err != nil {
|
||||
return err
|
||||
} else {
|
||||
acetmpl.Template = gtemplate
|
||||
}
|
||||
}
|
||||
return acetmpl.Execute(wr, arg)
|
||||
}
|
||||
|
||||
type AceEngine struct {
|
||||
loader *revel.TemplateLoader
|
||||
templatesByName map[string]*AceTemplate
|
||||
files []*ace.File
|
||||
Options *ace.Options
|
||||
CaseInsensitive bool
|
||||
}
|
||||
|
||||
func (i *AceEngine) ConvertPath(path string) string {
|
||||
if i.CaseInsensitive {
|
||||
return strings.ToLower(path)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func (i *AceEngine) Handles(templateView *revel.TemplateView) bool {
|
||||
return revel.EngineHandles(i, templateView)
|
||||
}
|
||||
|
||||
func (engine *AceEngine) ParseAndAdd(baseTemplate *revel.TemplateView) error {
|
||||
|
||||
// Ace templates must only render views specified for it (no trial and error)
|
||||
if baseTemplate.EngineType != ACE_TEMPLATE {
|
||||
return &revel.Error{
|
||||
Title: "Template Compilation Error",
|
||||
Path: baseTemplate.FilePath,
|
||||
Description: "Not correct template for engine",
|
||||
Line: 1,
|
||||
SourceLines: baseTemplate.Content(),
|
||||
}
|
||||
}
|
||||
|
||||
baseTemplate.TemplateName = engine.ConvertPath(baseTemplate.TemplateName)
|
||||
file := ace.NewFile(baseTemplate.TemplateName, baseTemplate.FileBytes)
|
||||
engine.files = append(engine.files, file)
|
||||
engine.templatesByName[baseTemplate.TemplateName] = &AceTemplate{File: file, engine: engine, TemplateView: baseTemplate}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (engine *AceEngine) Lookup(templateName string) revel.Template {
|
||||
if tpl, found := engine.templatesByName[engine.ConvertPath(templateName)]; found {
|
||||
|
||||
return tpl
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (engine *AceEngine) Name() string {
|
||||
return ACE_TEMPLATE
|
||||
}
|
||||
|
||||
func (engine *AceEngine) Event(action int, i interface{}) {
|
||||
if action == revel.TEMPLATE_REFRESH_REQUESTED {
|
||||
engine.templatesByName = map[string]*AceTemplate{}
|
||||
engine.CaseInsensitive = revel.Config.BoolDefault("ace.template.caseinsensitive", true)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
revel.RegisterTemplateLoader(ACE_TEMPLATE, func(loader *revel.TemplateLoader) (revel.TemplateEngine, error) {
|
||||
|
||||
return &AceEngine{
|
||||
loader: loader,
|
||||
templatesByName: map[string]*AceTemplate{},
|
||||
Options: &ace.Options{FuncMap: revel.TemplateFuncs},
|
||||
}, nil
|
||||
})
|
||||
}
|
9
vendor/github.com/revel/modules/template-engine/ace/app/views/errors/403.ace.html
generated
vendored
Normal file
9
vendor/github.com/revel/modules/template-engine/ace/app/views/errors/403.ace.html
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
= doctype html
|
||||
html lang=en
|
||||
head
|
||||
meta charset=utf-8
|
||||
title Forbidden
|
||||
body
|
||||
h1 Base Template : {{.Error.Title}}
|
||||
p : {{.Error.Description}}
|
||||
|
4
vendor/github.com/revel/modules/template-engine/ace/app/views/errors/403.json
generated
vendored
Normal file
4
vendor/github.com/revel/modules/template-engine/ace/app/views/errors/403.json
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "{{Error.Title|escapejs}}",
|
||||
"description": "{{Error.Description|escapejs}}"
|
||||
}
|
3
vendor/github.com/revel/modules/template-engine/ace/app/views/errors/403.txt
generated
vendored
Normal file
3
vendor/github.com/revel/modules/template-engine/ace/app/views/errors/403.txt
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{{.Error.Title}}
|
||||
|
||||
{{.Error.Description}}
|
23
vendor/github.com/revel/modules/template-engine/ace/tests/apptest.go
generated
vendored
Normal file
23
vendor/github.com/revel/modules/template-engine/ace/tests/apptest.go
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"github.com/revel/revel/testing"
|
||||
)
|
||||
|
||||
type ApplicationTest struct {
|
||||
testing.TestSuite
|
||||
}
|
||||
|
||||
func (t *ApplicationTest) Before() {
|
||||
println("Set up")
|
||||
}
|
||||
|
||||
func (t *ApplicationTest) TestThatIndexPageWorks() {
|
||||
t.Get("/")
|
||||
t.AssertOk()
|
||||
t.AssertContentType("text/html; charset=utf-8")
|
||||
}
|
||||
|
||||
func (t *ApplicationTest) After() {
|
||||
println("Tear down")
|
||||
}
|
Reference in New Issue
Block a user