diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/menubuilder.lua | 100 | ||||
-rw-r--r-- | lib/roles.lua | 23 |
2 files changed, 67 insertions, 56 deletions
diff --git a/lib/menubuilder.lua b/lib/menubuilder.lua index 51ed76d..2606fb7 100644 --- a/lib/menubuilder.lua +++ b/lib/menubuilder.lua @@ -59,61 +59,63 @@ local prio_compare = function(x,y) end -- returns a table of all the menu items found, sorted by priority -get_menuitems = function (startdir) +get_menuitems = function (self) local cats = {} local reversecats = {} - startdir = (string.gsub(startdir, "/$", "")) --remove trailing / - for k,filename in pairs(get_candidates(startdir)) do - local controller = string.gsub(posix.basename(filename), ".menu$", "") - local prefix = (string.gsub(posix.dirname(filename), startdir, "")).."/" + for p in string.gmatch(self.conf.appdir, "[^,]+") do + p = (string.gsub(p, "/$", "")) --remove trailing / + for k,filename in pairs(get_candidates(p)) do + local controller = string.gsub(posix.basename(filename), ".menu$", "") + local prefix = (string.gsub(posix.dirname(filename), p, "")).."/" - -- open the menu file, and parse the contents - local handle = io.open(filename) - for x in handle:lines() do - local result = parse_menu_line(x) - if result then - for i = 1,1 do -- loop so break works - -- Add the category - if nil == reversecats[result.cat] then - table.insert ( cats, - { name=result.cat, - groups = {}, - reversegroups = {} } ) - reversecats[result.cat] = #cats - end - local cat = cats[reversecats[result.cat]] - cat.priority = cat.priority or result.cat_prio - -- Add the group - if nil == result.group then break end - if nil == cat.groups[cat.reversegroups[result.group]] then - table.insert ( cat.groups, - { name = result.group, - controllers = {}, - reversetabs = {}, - tabs = {} } ) - cat.reversegroups[result.group] = #cat.groups - end - cat.groups[cat.reversegroups[result.group]].controllers[prefix..controller] = true - local group = cat.groups[cat.reversegroups[result.group]] - group.priority = group.priority or result.group_prio - -- Add the tab - if nil == result.tab or nil == result.action then break end - local tab = { name = result.tab, - controller = controller, - prefix = prefix, - action = result.action } - table.insert(group.tabs, tab) - if group.reversetabs[tab.name] then - -- Flag for two tabs of same name - group.flag = tab.name - table.insert(group.reversetabs[tab.name], #group.tabs) - else - group.reversetabs[tab.name] = {#group.tabs} - end + -- open the menu file, and parse the contents + local handle = io.open(filename) + for x in handle:lines() do + local result = parse_menu_line(x) + if result then + for i = 1,1 do -- loop so break works + -- Add the category + if nil == reversecats[result.cat] then + table.insert ( cats, + { name=result.cat, + groups = {}, + reversegroups = {} } ) + reversecats[result.cat] = #cats + end + local cat = cats[reversecats[result.cat]] + cat.priority = cat.priority or result.cat_prio + -- Add the group + if nil == result.group then break end + if nil == cat.groups[cat.reversegroups[result.group]] then + table.insert ( cat.groups, + { name = result.group, + controllers = {}, + reversetabs = {}, + tabs = {} } ) + cat.reversegroups[result.group] = #cat.groups + end + cat.groups[cat.reversegroups[result.group]].controllers[prefix..controller] = true + local group = cat.groups[cat.reversegroups[result.group]] + group.priority = group.priority or result.group_prio + -- Add the tab + if nil == result.tab or nil == result.action then break end + local tab = { name = result.tab, + controller = controller, + prefix = prefix, + action = result.action } + table.insert(group.tabs, tab) + if group.reversetabs[tab.name] then + -- Flag for two tabs of same name + group.flag = tab.name + table.insert(group.reversetabs[tab.name], #group.tabs) + else + group.reversetabs[tab.name] = {#group.tabs} + end + end end end + handle:close() end - handle:close() end -- Now that we have the entire menu, sort by priority diff --git a/lib/roles.lua b/lib/roles.lua index bfd45cf..a07d290 100644 --- a/lib/roles.lua +++ b/lib/roles.lua @@ -10,16 +10,25 @@ guest_role = "GUEST" -- returns a table of the *.roles files -- startdir should be the app dir -local get_roles_candidates = function (startdir) - return fs.find_files_as_array(".*%.roles", startdir, true) or {} +local get_roles_candidates = function(self) + local list = {} + for p in string.gmatch(self.conf.appdir, "[^,]+") do + local l = fs.find_files_as_array(".*%.roles", p, true) or {} + for i,f in ipairs(l) do + list[#list+1] = f + end + end + return list end -- Return a list of *controller.lua files list_controllers = function(self) local list = {} - for file in fs.find(".*controller%.lua", self.conf.appdir, true) do - if not string.find(file, "acf_") then - list[#list + 1] = file + for p in string.gmatch(self.conf.appdir, "[^,]+") do + for file in fs.find(".*controller%.lua", p, true) do + if not string.find(file, "acf_") then + list[#list + 1] = file + end end end @@ -85,7 +94,7 @@ list_default_roles = function(self) local reverseroles = {} -- find all of the default roles files and parse them - local rolesfiles = get_roles_candidates(self.conf.appdir) + local rolesfiles = get_roles_candidates(self) for x,file in ipairs(rolesfiles) do f = fs.read_file_as_array(file) or {} @@ -152,7 +161,7 @@ local determine_perms = function(self,roles) end -- find all of the default roles files and parse them - local rolesfiles = get_roles_candidates(self.conf.appdir) + local rolesfiles = get_roles_candidates(self) for x,file in ipairs(rolesfiles) do local prefix = string.match(file, "(/[^/]+/)[^/]+$") or "/" |