API
#text/template
Xu 0.8.8 API
import: #text/template
counts: 9 fns, 1 methods, 2 types, 0 consts, 0 ifaces
Templates without reflection: {{.}}, pipelines, if/with/range/define.
struct Template
pub struct Template {
pub src string
}
Purpose
Minimal text/template without reflect or user FuncMap. Supports: literal text, {{.}} , {{.Key}} , pipes {{. | html | len}}, {{if}}/{{with}}/{{range}}, {{define}}/{{template}}/{{block}}. Dict is parallel key/value strings. Execute walks actions once. execute_*html escapes interpolation via html.escape_string unless the pipeline already applied `| html`.
Parameters
src string- source
struct Dict
pub struct Dict {
pub keys []string
pub vals []string
}
Purpose
Public struct `Dict`.
Parameters
keys []string- field ([]string)
vals []string- field ([]string)
new
pub fn new(src string) Template
Purpose
Construct a new value of this type.
Parameters
src string- source (string)
Returns
Template — a value of this type
new_dict
Purpose
Construct dict.
Parameters
none
Returns
Dict — a value of this type
(&mut Dict) set
pub fn (d &mut Dict) set(k string, v string)
Purpose
Call `set` on `&mut Dict`.
Parameters
d &mut Dict- receiver &mut Dict (exclusive borrow)
k string- key or index (string)
v string- value (string)
get
pub fn get(d &Dict, k string) string
Purpose
get; returns string.
Parameters
d &Dict- d (borrowed; caller keeps it; type &Dict)
k string- key or index (string)
Returns
string — result string
execute_str
pub fn execute_str(t &Template, root string) string
Purpose
Execute str. Throws on failure.
Parameters
t &Template- t (borrowed; caller keeps it; type &Template)
root string- root (string)
Returns
string — result string
execute
pub fn execute(t &Template, d &Dict) string
Purpose
execute; returns string. Throws on failure.
Parameters
t &Template- t (borrowed; caller keeps it; type &Template)
d &Dict- d (borrowed; caller keeps it; type &Dict)
Returns
string — result string
execute_list
pub fn execute_list(t &Template, items []string) string
Purpose
Execute list. Throws on failure.
Parameters
t &Template- t (borrowed; caller keeps it; type &Template)
items []string- items ([]string)
Returns
string — result string
execute_str_html
pub fn execute_str_html(t &Template, root string) string
Purpose
Execute str html. Throws on failure.
Parameters
t &Template- t (borrowed; caller keeps it; type &Template)
root string- root (string)
Returns
string — result string
execute_html
pub fn execute_html(t &Template, d &Dict) string
Purpose
Execute html. Throws on failure.
Parameters
t &Template- t (borrowed; caller keeps it; type &Template)
d &Dict- d (borrowed; caller keeps it; type &Dict)
Returns
string — result string
execute_list_html
pub fn execute_list_html(t &Template, items []string) string
Purpose
Execute list html. Throws on failure.
Parameters
t &Template- t (borrowed; caller keeps it; type &Template)
items []string- items ([]string)
Returns
string — result string