libs/cbi: attach pcdata() to template scope and use it
[project/luci.git] / libs / cbi / luasrc / cbi.lua
index db76e3b..044993a 100644 (file)
@@ -60,17 +60,18 @@ function load(cbimap, ...)
 
        local upldir = "/lib/uci/upload/"
        local cbidir = luci.util.libpath() .. "/model/cbi/"
-
-       assert(fs.stat(cbimap) or
-               fs.stat(cbidir..cbimap..".lua") or
-               fs.stat(cbidir..cbimap..".lua.gz"),
-                       "Model not found!")
-
-       local func, err = loadfile(cbimap)
-       if not func then
-               func, err = loadfile(cbidir..cbimap..".lua") or
-                       loadfile(cbidir..cbimap..".lua.gz")
+       local func, err
+
+       if fs.access(cbimap) then
+               func, err = loadfile(cbimap)
+       elseif fs.access(cbidir..cbimap..".lua") then
+               func, err = loadfile(cbidir..cbimap..".lua")
+       elseif fs.access(cbidir..cbimap..".lua.gz") then
+               func, err = loadfile(cbidir..cbimap..".lua.gz")
+       else
+               func, err = nil, "Model '" .. cbimap .. "' not found!"
        end
+
        assert(func, err)
 
        luci.i18n.loadc("cbi")
@@ -1339,6 +1340,7 @@ function AbstractValue.render(self, s, scope)
                scope.section   = s
                scope.cbid      = self:cbid(s)
                scope.striptags = luci.util.striptags
+               scope.pcdata    = luci.util.pcdata
 
                scope.ifattr = function(cond,key,val)
                        if cond then