Merge pull request #2749 from dibdot/wg
[oweals/luci.git] / modules / luci-base / luasrc / dispatcher.lua
index d85cb58243082e007a3144ca2ee03bbc50e2aca0..e8106b741d533541279597cf98dc8a8e4c7fedb0 100644 (file)
@@ -328,7 +328,7 @@ function dispatch(request)
                        assert(media, "No valid theme found")
                end
 
-               local function _ifattr(cond, key, val)
+               local function _ifattr(cond, key, val, noescape)
                        if cond then
                                local env = getfenv(3)
                                local scope = (type(env.self) == "table") and env.self
@@ -339,13 +339,16 @@ function dispatch(request)
                                                val = util.serialize_json(val)
                                        end
                                end
-                               return string.format(
-                                       ' %s="%s"', tostring(key),
-                                       util.pcdata(tostring( val
-                                        or (type(env[key]) ~= "function" and env[key])
-                                        or (scope and type(scope[key]) ~= "function" and scope[key])
-                                        or "" ))
-                               )
+
+                               val = tostring(val or
+                                       (type(env[key]) ~= "function" and env[key]) or
+                                       (scope and type(scope[key]) ~= "function" and scope[key]) or "")
+
+                               if noescape ~= true then
+                                       val = util.pcdata(val)
+                               end
+
+                               return string.format(' %s="%s"', tostring(key), val)
                        else
                                return ''
                        end
@@ -854,6 +857,15 @@ function template(name)
 end
 
 
+local _view = function(self, ...)
+       require "luci.template".render("view", { view = self.view })
+end
+
+function view(name)
+       return {type = "view", view = name, target = _view}
+end
+
+
 local function _cbi(self, ...)
        local cbi = require "luci.cbi"
        local tpl = require "luci.template"