require("ffluci.i18n")
require("ffluci.model.uci")
-viewdir = ffluci.fs.dirname(ffluci.util.__file__()) .. "view/"
+viewdir = ffluci.config.path .. "/view/"
-- Compile modes:
-- Define the namespace for template modules
viewns = {
translate = ffluci.i18n.translate,
- config = ffluci.model.uci.get,
+ config = function(...) return ffluci.model.uci.get(...) or "" end,
controller = os.getenv("SCRIPT_NAME"),
- media = ffluci.config.mediaurlbase,
+ media = ffluci.config.main.mediaurlbase,
write = io.write,
include = function(name) Template(name):render(getfenv(2)) end,
}
elseif p == "~" then
re = sanitize(v):gsub("~(.-)%.(.-)%.(.+)", r_uci)
elseif p == "=" then
- re = r_pexec:format(string.sub(v, 2))
+ re = r_pexec:format(v:sub(2))
else
re = r_exec:format(v)
end
-- Build if there is no compiled file or if compiled file is outdated
if ((commt == nil) and not (tplmt == nil))
or (not (commt == nil) and not (tplmt == nil) and commt < tplmt) then
- local compiled = compile(ffluci.fs.readfile(sourcefile))
- ffluci.fs.writefile(compiledfile, compiled)
- self.template, err = loadstring(compiled)
+ local source
+ source, err = ffluci.fs.readfile(sourcefile)
+
+ if source then
+ local compiled = compile(source)
+ ffluci.fs.writefile(compiledfile, compiled)
+ self.template, err = loadstring(compiled)
+ end
else
self.template, err = loadfile(compiledfile)
end
self.template, err = loadfile(self.compiledfile)
elseif compiler_mode == "memory" then
- self.template, err = loadstring(compile(ffluci.fs.readfile(sourcefile)))
+ local source
+ source, err = ffluci.fs.readfile(sourcefile)
+ if source then
+ self.template, err = loadstring(compile(source))
+ end
end