Changeset

581:a9a97df60b8c

mod_muc_log_http: Improved theme loading, and better error reporting.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 25 Jan 2012 04:29:26 +0500 (2012-01-24)
parents 580:10a9538f41f1
children 582:92ff305e7e32
files mod_muc_log_http/muc_log_http/mod_muc_log_http.lua
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Wed Jan 25 04:22:10 2012 +0500
+++ b/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Wed Jan 25 04:29:26 2012 +0500
@@ -705,7 +705,8 @@
 end
 
 local function readFile(filepath)
-	local f = assert(io_open(filepath, "r"));
+	local f,err = io_open(filepath, "r");
+	if not f then return f,err; end
 	local t = f:read("*all");
 	f:close()
 	return t;
@@ -713,10 +714,11 @@
 
 local function loadTheme(path)
 	for file in lfs.dir(path) do
-		if file ~= "." and file ~= ".." then
+		if file:match("%.html$") then
 			module:log("debug", "opening theme file: " .. file);
-			local tmp = split(file:gsub("\.html$", ""), "_");
-			local content = readFile(path .. "/" .. file);
+			local tmp = split(file:match("(.*)%.html$"), "_");
+			local content,err = readFile(path .. "/" .. file);
+			if not content then return content,err; end
 			assign(tmp, content);
 		end
 	end
@@ -741,8 +743,9 @@
 	end
 
 	-- module:log("debug", (require "util.serialization").serialize(html));
-	if(not loadTheme(themePath)) then
-		module:log("error", "Theme \"".. tostring(theme) .. "\" is missing something.");
+	local themeLoaded,err = loadTheme(themePath);
+	if not themeLoaded then
+		module:log("error", "Theme \"%s\" is missing something: %s", tostring(theme), err);
 		return false;
 	end
 	-- module:log("debug", (require "util.serialization").serialize(html));