- -- Template module header/footer declaration
- local header = "write('"
- local footer = "')"
-
- template = header .. template .. footer
-
- -- Replacements
- local r_include = "')\ninclude('%s')\nwrite('"
- local r_i18n = "'..translate('%1','%2')..'"
- local r_i18n2 = "'..translate('%1', '')..'"
- local r_pexec = "'..(%s or '')..'"
- local r_exec = "')\n%s\nwrite('"
-
- -- Parse the expressions
- for k,v in pairs(expr) do
- local p = v:sub(1, 1)
- v = v:gsub("%%", "%%%%")
- local re = nil
- if p == "+" then
- re = r_include:format(sanitize(string.sub(v, 2)))
- elseif p == ":" then
- if v:find(" ") then
- re = sanitize(v):gsub(":(.-) (.*)", r_i18n)
- else
- re = sanitize(v):gsub(":(.+)", r_i18n2)
- end
- elseif p == "=" then
- re = r_pexec:format(v:sub(2))
- elseif p == "#" then
- re = ""
- else
- re = r_exec:format(v)
- end
- template = template:gsub("<%%"..tostring(k).."%%>", re)
- end
-
- return loadstring(template)
-end
-
--- Oldstyle render shortcut
-function render(name, scope, ...)
- scope = scope or getfenv(2)
- local s, t = luci.util.copcall(Template, name)
- if not s then
- error(t)
- else
- t:render(scope, ...)
- end
+--- Render a certain template.
+-- @param name Template name
+-- @param scope Scope to assign to template (optional)
+function render(name, scope)
+ return Template(name):render(scope or getfenv(2))