Mercurial > prosody-hg
comparison util/interpolation.lua @ 6771:60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 17 Jul 2015 12:43:04 +0200 |
| parents | 936cf2f7531f |
| children | 805baeca56b6 |
comparison
equal
deleted
inserted
replaced
| 6766:b38db4b634d3 | 6771:60957dd5b41b |
|---|---|
| 1 -- Simple template language | 1 -- Simple template language |
| 2 -- | 2 -- |
| 3 -- The new() function takes a pattern and an escape function and returns | 3 -- The new() function takes a pattern and an escape function and returns |
| 4 -- a render() function. Both are required. | 4 -- a render() function. Both are required. |
| 5 -- | 5 -- |
| 6 -- The function render() takes a string template and a table of values. | 6 -- The function render() takes a string template and a table of values. |
| 7 -- Sequences like {name} in the template string are substituted | 7 -- Sequences like {name} in the template string are substituted |
| 8 -- with values from the table, optionally depending on a modifier | 8 -- with values from the table, optionally depending on a modifier |
| 9 -- symbol. | 9 -- symbol. |
| 10 -- | 10 -- |
| 11 -- Variants are: | 11 -- Variants are: |
| 12 -- {name} is substituted for values["name"] and is escaped using the | 12 -- {name} is substituted for values["name"] and is escaped using the |
| 13 -- second argument to new_render(). To disable the escaping, use {name!}. | 13 -- second argument to new_render(). To disable the escaping, use {name!}. |
| 14 -- {name.item} can be used to access table items. | 14 -- {name.item} can be used to access table items. |
| 15 -- To renter lists of items: {name# item number {idx} is {item} } | 15 -- To renter lists of items: {name# item number {idx} is {item} } |
| 16 -- Or key-value pairs: {name% t[ {idx} ] = {item} } | 16 -- Or key-value pairs: {name% t[ {idx} ] = {item} } |
| 17 -- To show a defaults for missing values {name? sub-template } can be used, | 17 -- To show a defaults for missing values {name? sub-template } can be used, |
| 18 -- which renders a sub-template if values["name"] is false-ish. | 18 -- which renders a sub-template if values["name"] is false-ish. |
| 19 -- {name& sub-template } does the opposite, the sub-template is rendered | 19 -- {name& sub-template } does the opposite, the sub-template is rendered |
| 20 -- if the selected value is anything but false or nil. | 20 -- if the selected value is anything but false or nil. |
| 21 | 21 |
| 22 local type, tostring = type, tostring; | 22 local type, tostring = type, tostring; |
| 23 local pairs, ipairs = pairs, ipairs; | 23 local pairs, ipairs = pairs, ipairs; |
| 24 local s_sub, s_gsub, s_match = string.sub, string.gsub, string.match; | 24 local s_sub, s_gsub, s_match = string.sub, string.gsub, string.match; |
