]]--
-local fs = require "nixio.fs"
-local sys = require "luci.sys"
local util = require "luci.util"
-local table = require "table"
-local string = require "string"
local config = require "luci.config"
-local nixio = require "nixio", require "nixio.util"
local tparser = require "luci.template.parser"
local tostring, pairs, loadstring = tostring, pairs, loadstring
if not self.template then
-- Compile template
+ local err
local sourcefile = viewdir .. "/" .. name .. ".htm"
+
self.template, _, err = tparser.parse(sourcefile)
-- If we have no valid template throw error, otherwise cache the template
if not self.template then
- error(err)
+ error("Failed to load template '" .. name .. "'.\n" ..
+ "Error while parsing template '" .. sourcefile .. "'.\n" ..
+ "A syntax error occured near '" ..
+ (err or "(nil)"):gsub("\t", "\\t"):gsub("\n", "\\n") .. "'.")
else
self.cache[name] = self.template
end
-- Now finally render the thing
local stat, err = util.copcall(self.template)
if not stat then
- error("Error in template %s: %s" % {self.name, err})
+ error("Failed to execute template '" .. self.name .. "'.\n" ..
+ "A runtime error occured: " .. tostring(err or "(nil)"))
end
end