Documentation ¶
Overview ¶
Small library to create structured html templates using html/template package from go
The library is inspired by how rails structure it's view templates.
Index ¶
- func AllowHtmlJsAndCss(f Namer) bool
- func DiscoverDelim(name string) (string, string)
- func LoadDirInto(t TreeSet, dir Dir, funcs tt.FuncMap, filter Filter) error
- func LoadFileInto(t TreeSet, f File, funcs tt.FuncMap) error
- func Template(set TreeSet, alias map[string]string) (*template.Template, error)
- func TemplateName(f Namer) string
- type Dir
- type File
- type Filter
- type FilterFunc
- type Namer
- type Parenter
- type TreeSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowHtmlJsAndCss ¶
Filter function that allow only html,(js/json) and css files
All directories are allowed too
func DiscoverDelim ¶
Discover the best delimiter for the given filename
HTML => {{ / }} JS => <% / %> CSS => <% / %>
func LoadDirInto ¶
Load all files from the given Dir into the given template
func LoadFileInto ¶
Read a file and register a new template under the filename
The name is given by TemplateName(f)
func Template ¶
Return a new template containing all templates from set.
The alias map can be used to access one template with two or more names
Consider this:
layout/main.html The contents come from {{ template "contents" }} index/index.html I have the contents user/index.html I also have the contents
If you loaded all those files, you have a treeSet with three templates: "layout/main.html", "index/index.html" and "user/index.html"
Now you can use the alias to map "index/index.html" to "contents"
alias := map[string]string { "contents": "index/index.html" }
When you execute the template, instead of having a "template contents not found" the system will execute the "index/index.html" template and put its result on "layout/main.html"
This keeps all the safety from html/template but enable your to use more dynamic templates without having to parse them every single time.
If you need a new template with a different alias, just call this function again passing a different alias map
func TemplateName ¶
Return the unique name of the object.
If the object is also a Parenter, the name will contain the name of it's parents
Types ¶
type Dir ¶
type Dir interface { Namer Parenter // Return the files that hold any content that can be parsed from // the template engine ReadFiles() ([]File, error) // Return the list of sub-directories ReadDirs() ([]Dir, error) }
A virtual directory
type File ¶
type File interface { Namer // Return the contents of this file Contents() ([]byte, error) Parenter }
A virtual file
type FilterFunc ¶
Implements the Filter interface
type Namer ¶
type Namer interface { // The name of the item, only text that is allowed inside a URL // can be returned. // // Unicode MUST BE encoded as UTF-8 instead of using %xx // // The name here should only return its name without any information // from its parents // // Directories MUST NOT include the "/" Name() string // Should return if the current item represents a directory IsDir() bool }
A item that have a name
type Parenter ¶
type Parenter interface { // Return the parent of this directory, might return nil, // in this case, this Dir is the root Parent() Dir }
Represent any entry in the filesystem that can have a parent
type TreeSet ¶
A set of compiled templates
func LoadDir ¶
Load all files under root and return a set of all templates if two templates have the same name (let's say that file a.html and b.html both define the template "nice_button"). Only one of those definitions will be available (the last one returned by the vfs)
Each template can be accessed by its full path from root, that means "layout/body.html" represents a file under "layout" with a name of "body.html"
Directories ¶
Path | Synopsis |
---|---|
fileserver enable the user to modify the path of a file request before serving the actual file.
|
fileserver enable the user to modify the path of a file request before serving the actual file. |
Helper methods to combine webview templates with http requests objects Uses the gorilla context library
|
Helper methods to combine webview templates with http requests objects Uses the gorilla context library |
Enable easy and fast http prototype to go
|
Enable easy and fast http prototype to go |
This package wrap the npm module regenerator from Facebook to allow more people to use ES6 without having to compile lot's of files every new deploy.
|
This package wrap the npm module regenerator from Facebook to allow more people to use ES6 without having to compile lot's of files every new deploy. |