diff options
Diffstat (limited to 'libs/web/luasrc')
-rw-r--r-- | libs/web/luasrc/config.lua | 11 | ||||
-rw-r--r-- | libs/web/luasrc/dispatcher.lua | 40 | ||||
-rw-r--r-- | libs/web/luasrc/i18n.lua | 6 | ||||
-rw-r--r-- | libs/web/luasrc/template.lua | 40 |
4 files changed, 49 insertions, 48 deletions
diff --git a/libs/web/luasrc/config.lua b/libs/web/luasrc/config.lua index 854b128145..4eb8e46e4f 100644 --- a/libs/web/luasrc/config.lua +++ b/libs/web/luasrc/config.lua @@ -25,10 +25,9 @@ limitations under the License. ]]-- -module("luci.config", package.seeall) -require("luci.model.uci") -require("luci.util") -require("luci.sys") +local uci = require("luci.model.uci") +local util = require("luci.util") +module("luci.config") -- Warning! This is only for fallback and compatibility purporses! -- main = {} @@ -42,7 +41,7 @@ main.lang = "de" -- Now overwrite with UCI values -local ucidata = luci.model.uci.sections("luci") +local ucidata = uci.sections("luci") if ucidata then - luci.util.update(luci.config, ucidata) + util.update(_M, ucidata) end
\ No newline at end of file diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 8d1e493fb8..c7e1ed6fe2 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -177,7 +177,7 @@ end -- Calls the index function of all available controllers function createindex_plain(path, suffix) - local cachetime = nil + local cache = nil local controllers = luci.util.combine( luci.fs.glob(path .. "*" .. suffix) or {}, @@ -185,32 +185,38 @@ function createindex_plain(path, suffix) ) if indexcache then - cachetime = luci.fs.mtime(indexcache) + cache = luci.fs.mtime(indexcache) - if not cachetime then + if not cache then luci.fs.mkdir(indexcache) luci.fs.chmod(indexcache, "a=,u=rwx") + cache = luci.fs.mtime(indexcache) end end - if not cachetime then - for i,c in ipairs(controllers) do - c = "luci.controller." .. c:sub(#path+1, #c-#suffix):gsub("/", ".") - stat, mod = pcall(require, c) + for i,c in ipairs(controllers) do + local module = "luci.controller." .. c:sub(#path+1, #c-#suffix):gsub("/", ".") + local cachefile = indexcache .. "/" .. module + local stime + local ctime + + if cache then + stime = luci.fs.mtime(c) or 0 + ctime = luci.fs.mtime(cachefile) or 0 + end + + if not cache or stime > ctime then + stat, mod = pcall(require, module) if stat and mod and type(mod.index) == "function" then - index[c] = mod.index + index[module] = mod.index - if indexcache then - luci.fs.writefile(indexcache .. "/" .. c, string.dump(mod.index)) + if cache then + luci.fs.writefile(cachefile, luci.util.dump(mod.index)) end end - end - else - for i,c in ipairs(luci.fs.dir(indexcache)) do - if c:sub(1) ~= "." then - index[c] = loadfile(indexcache .. "/" .. c) - end + else + index[module] = loadfile(cachefile) end end end @@ -226,7 +232,7 @@ function createtree() -- Load default translation luci.i18n.loadc("default") - local scope = _G + local scope = luci.util.clone(_G) for k,v in pairs(_M) do if type(v) == "function" then scope[k] = v diff --git a/libs/web/luasrc/i18n.lua b/libs/web/luasrc/i18n.lua index 7ace708e9d..546429933b 100644 --- a/libs/web/luasrc/i18n.lua +++ b/libs/web/luasrc/i18n.lua @@ -39,7 +39,7 @@ end -- Loads a translation and copies its data into the global translation table function load(file, force) if force or not loaded[file] then - local f = loadfile(i18ndir .. file) + local f = loadfile(i18ndir..file..".lua") or loadfile(i18ndir..file) if f then setfenv(f, table) f() @@ -54,8 +54,8 @@ function load(file, force) end -- Same as load but autocompletes the filename with .LANG from config.lang -function loadc(file) - return load(file .. "." .. require("luci.config").main.lang) +function loadc(file, force) + return load(file .. "." .. require("luci.config").main.lang, force) end -- Returns the i18n-value defined by "key" or if there is no such: "default" diff --git a/libs/web/luasrc/template.lua b/libs/web/luasrc/template.lua index 369aa0a30b..c672f16bfd 100644 --- a/libs/web/luasrc/template.lua +++ b/libs/web/luasrc/template.lua @@ -30,22 +30,17 @@ require("luci.util") require("luci.fs") require("luci.http") -viewdir = luci.sys.libpath() .. "/view/" +luci.config.template = luci.config.template or {} + +viewdir = luci.config.template.viewdir or luci.sys.libpath() .. "/view" +compiledir = luci.config.template.compiledir or luci.sys.libpath() .. "/view" -- Compile modes: -- none: Never compile, only use precompiled data from files -- memory: Always compile, do not save compiled files, ignore precompiled -- file: Compile on demand, save compiled files, update precompiled -compiler_mode = "memory" - - --- This applies to compiler modes "always" and "smart" --- --- Produce compiled lua code rather than lua sourcecode --- WARNING: Increases template size heavily!!! --- This produces the same bytecode as luac but does not have a strip option -compiler_enable_bytecode = false +compiler_mode = luci.config.template.compiler_mode or "memory" -- Define the namespace for template modules @@ -107,12 +102,7 @@ function compile(template) template = template:gsub("<%%"..tostring(k).."%%>", re) end - if compiler_enable_bytecode then - tf = loadstring(template) - template = string.dump(tf) - end - - return template + return loadstring(template) end -- Oldstyle render shortcut @@ -156,8 +146,8 @@ function Template.__init__(self, name) end -- Compile and build - local sourcefile = viewdir .. name .. ".htm" - local compiledfile = viewdir .. name .. ".lua" + local sourcefile = viewdir .. "/" .. name .. ".htm" + local compiledfile = compiledir .. "/" .. name .. ".lua" local err if compiler_mode == "file" then @@ -171,9 +161,15 @@ function Template.__init__(self, name) source, err = luci.fs.readfile(sourcefile) if source then - local compiled = compile(source) - luci.fs.writefile(compiledfile, compiled) - self.template, err = loadstring(compiled) + local compiled, err = compile(source) + + local compiledfile_dir = luci.fs.dirname(compiledfile) + if not luci.fs.mtime(compiledfile_dir) then + luci.fs.mkdir(compiledfile_dir) + end + + luci.fs.writefile(compiledfile, luci.util.dump(compiled)) + self.template = compiled end else self.template, err = loadfile(compiledfile) @@ -186,7 +182,7 @@ function Template.__init__(self, name) local source source, err = luci.fs.readfile(sourcefile) if source then - self.template, err = loadstring(compile(source)) + self.template, err = compile(source) end end |