summaryrefslogtreecommitdiffhomepage
path: root/libs/web
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2008-07-07 21:29:22 +0000
committerJo-Philipp Wich <jow@openwrt.org>2008-07-07 21:29:22 +0000
commite8e67f15cde3583d81cffd8801e7d3f6678ff3c1 (patch)
tree1adeb6ab1e4cccd5973991e4df4cc1d3bdeb89cc /libs/web
parenta41f33ba0188f897c6277cb23f9371749d2403f5 (diff)
* luci/libs/web: extended template syntax to allow removal of leading and trailing whitespace
Diffstat (limited to 'libs/web')
-rw-r--r--libs/web/luasrc/template.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/libs/web/luasrc/template.lua b/libs/web/luasrc/template.lua
index e5a4884ce..bc216e1b5 100644
--- a/libs/web/luasrc/template.lua
+++ b/libs/web/luasrc/template.lua
@@ -53,9 +53,11 @@ viewns = {
-- Compiles a given template into an executable Lua module
function compile(template)
-- Search all <% %> expressions (remember: Lua table indexes begin with #1)
- local function expr_add(command)
+ local function expr_add(ws1, skip1, command, skip2, ws2)
table.insert(expr, command)
- return "<%" .. tostring(#expr) .. "%>"
+ return ( skip1 and "" or ws1 ) ..
+ "<%" .. tostring(#expr) .. "%>" ..
+ ( skip2 and "" or ws2 )
end
-- As "expr" should be local, we have to assign it to the "expr_add" scope
@@ -63,7 +65,7 @@ function compile(template)
luci.util.extfenv(expr_add, "expr", expr)
-- Save all expressiosn to table "expr"
- template = template:gsub("<%%(.-)%%>", expr_add)
+ template = template:gsub("(%s*)<%%(%-?)(.-)(%-?)%%>(%s*)", expr_add)
local function sanitize(s)
s = luci.util.escape(s)