comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 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
parents 10a9538f41f1
children 92ff305e7e32
comparison
equal deleted inserted replaced
580:10a9538f41f1 581:a9a97df60b8c
703 end 703 end
704 tmp[idx] = content; 704 tmp[idx] = content;
705 end 705 end
706 706
707 local function readFile(filepath) 707 local function readFile(filepath)
708 local f = assert(io_open(filepath, "r")); 708 local f,err = io_open(filepath, "r");
709 if not f then return f,err; end
709 local t = f:read("*all"); 710 local t = f:read("*all");
710 f:close() 711 f:close()
711 return t; 712 return t;
712 end 713 end
713 714
714 local function loadTheme(path) 715 local function loadTheme(path)
715 for file in lfs.dir(path) do 716 for file in lfs.dir(path) do
716 if file ~= "." and file ~= ".." then 717 if file:match("%.html$") then
717 module:log("debug", "opening theme file: " .. file); 718 module:log("debug", "opening theme file: " .. file);
718 local tmp = split(file:gsub("\.html$", ""), "_"); 719 local tmp = split(file:match("(.*)%.html$"), "_");
719 local content = readFile(path .. "/" .. file); 720 local content,err = readFile(path .. "/" .. file);
721 if not content then return content,err; end
720 assign(tmp, content); 722 assign(tmp, content);
721 end 723 end
722 end 724 end
723 return true; 725 return true;
724 end 726 end
739 module:log("error", "Theme folder of theme \"".. tostring(theme) .. "\" isn't existing. expected Path: " .. themePath); 741 module:log("error", "Theme folder of theme \"".. tostring(theme) .. "\" isn't existing. expected Path: " .. themePath);
740 return false; 742 return false;
741 end 743 end
742 744
743 -- module:log("debug", (require "util.serialization").serialize(html)); 745 -- module:log("debug", (require "util.serialization").serialize(html));
744 if(not loadTheme(themePath)) then 746 local themeLoaded,err = loadTheme(themePath);
745 module:log("error", "Theme \"".. tostring(theme) .. "\" is missing something."); 747 if not themeLoaded then
748 module:log("error", "Theme \"%s\" is missing something: %s", tostring(theme), err);
746 return false; 749 return false;
747 end 750 end
748 -- module:log("debug", (require "util.serialization").serialize(html)); 751 -- module:log("debug", (require "util.serialization").serialize(html));
749 752
750 httpserver.new_from_config({ config.http_port or true }, handle_request, { base = urlBase, ssl = false, port = 5290 }); 753 httpserver.new_from_config({ config.http_port or true }, handle_request, { base = urlBase, ssl = false, port = 5290 });