XU XUv0.16.0

#text/template

import: #text/template

counts: 9 functions, 1 methods, 2 types, 0 constants, 0 method sets

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

struct Template

XuAPI
pub struct Template {
    pub src string
}

Purpose

Structure encapsulating src.

Public fields

src string
source

struct Dict

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

Purpose

Structure encapsulating keys, vals.

Public fields

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

No arguments are required.

Returns

Dict — a value of this type

($&Dict) set

XuAPI
pub fn (d $&Dict) set(k string, v string)

Purpose

Execute set on $&Dict.

Parameters

d $&Dict
The Dict instance used by this call (exclusive borrow).
k string
key or index (string)
v string
value (string)

Returns

This call does not return a value.

get

XuAPI
pub fn get(d &Dict, k string) string

Purpose

Execute get.

Parameters

d &Dict
d (read-only borrow; caller keeps the original; 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

Apply data to template and render output as string. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Template
t (read-only borrow; caller keeps the original; type &Template)
root string
root (string)

Returns

string — result string

execute

XuAPI
pub fn execute(t &Template, d &Dict) string

Purpose

Apply data context to template and execute rendering. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Template
t (read-only borrow; caller keeps the original; type &Template)
d &Dict
d (read-only borrow; caller keeps the original; type &Dict)

Returns

string — result string

execute_list

XuAPI
pub fn execute_list(t &Template, items []string) string

Purpose

Render the template with a list of strings as its data context; return one string. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Template
t (read-only borrow; caller keeps the original; 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; handle the error or propagate it to the caller.

Parameters

t &Template
t (read-only borrow; caller keeps the original; 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; handle the error or propagate it to the caller.

Parameters

t &Template
t (read-only borrow; caller keeps the original; type &Template)
d &Dict
d (read-only borrow; caller keeps the original; 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; handle the error or propagate it to the caller.

Parameters

t &Template
t (read-only borrow; caller keeps the original; type &Template)
items []string
items ([]string)

Returns

string — result string