XU XUv0.8.8
中文

API

#text/template

import: #text/template

counts: 9 fns, 1 methods, 2 types, 0 consts, 0 ifaces

Templates without reflection: {{.}}, pipelines, if/with/range/define.

struct Template

XuAPI
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

XuAPI
pub struct Dict {
    pub keys []string
    pub vals []string
}

Purpose

Public struct `Dict`.

Parameters

keys []string
field ([]string)
vals []string
field ([]string)

new

XuAPI
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

XuAPI
pub fn new_dict() Dict

Purpose

Construct dict.

Parameters

none

Returns

Dict — a value of this type

(&mut Dict) set

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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