* luci/statistics: fix path to types.db in default config, adept stat-genconfig to...
[project/luci.git] / core / src / menu.lua
index 5724b2cb9e6f8d4c909d018efa848a3d6e0ffd3e..30cc5a1225bccc6a2ad68dac50078ab3deea917d 100644 (file)
@@ -1,5 +1,5 @@
 --[[
-FFLuCI - Menu Builder
+LuCI - Menu Builder
 
 Description:
 Collects menu building information from controllers
@@ -23,115 +23,24 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 ]]--
-module("ffluci.menu", package.seeall)
+module("luci.menu", package.seeall)
 
-require("ffluci.fs")
-require("ffluci.util")
-require("ffluci.sys")
+require("luci.fs")
+require("luci.util")
+require("luci.sys")
+require("luci.dispatcher")
 
 -- Default modelpath
-modelpath = ffluci.sys.libpath() .. "/model/menu/"
+modelpattern = luci.sys.libpath() .. "/model/menu/*.lua"
 
 -- Menu definition extra scope
 scope = {
-       translate = function(...) return require("ffluci.i18n").translate(...) end,
-       loadtrans = function(...) return require("ffluci.i18n").loadc(...) end,
-       isfile    = ffluci.fs.isfile
+       translate = function(...) return require("luci.i18n").translate(...) end,
+       loadtrans = function(...) return require("luci.i18n").loadc(...) end,
+       isfile    = luci.fs.isfile
 }
 
--- Local menu database
-local menu = nil
-
--- The current pointer
-local menuc = {}
-
--- Adds a menu category to the current menu and selects it
-function add(cat, controller, title, order)
-       order = order or 100
-       if not menu[cat] then
-               menu[cat] = {}
-       end
-       
-       local entry = {}
-       entry[".descr"] = title
-       entry[".order"] = order
-       entry[".contr"] = controller
-       
-       menuc = entry
-
-       local i = 0                     
-       for k,v in ipairs(menu[cat]) do
-               if v[".order"] > entry[".order"] then
-                       break
-               end  
-               i = k
-       end     
-       table.insert(menu[cat], i+1, entry)
-               
-       return true
-end
-
--- Adds an action to the current menu
-function act(action, title)
-       table.insert(menuc, {action = action, descr = title})
-       return true
-end
-
--- Selects a menu category
-function sel(cat, controller)
-       if not menu[cat] then
-               return nil
-       end
-       menuc = menu[cat]
-       
-       local stat = nil
-       for k,v in ipairs(menuc) do
-               if v[".contr"] == controller then
-                       menuc = v
-                       stat = true
-               end
-       end
-       
-       return stat
-end
-
-
--- Collect all menu information provided in the model dir
-function collect()
-       local generators = {}
-       
-       for k, menu in pairs(ffluci.fs.dir(modelpath)) do
-               if menu:sub(1, 1) ~= "." then
-                       local f = loadfile(modelpath.."/"..menu)
-                       if f then
-                               table.insert(generators, f)
-                       end
-               end
-       end
-       
-       return generators
-end
-
--- Parse the collected information
-function parse(generators)
-       menu = {}
-       for i, f in pairs(generators) do
-               local env = ffluci.util.clone(scope)
-               
-               env.add = add
-               env.sel = sel
-               env.act = act
-               
-               setfenv(f, env)
-               f()
-       end
-       return menu
-end
-
 -- Returns the menu information
 function get()
-       if not menu then
-               menu = parse(collect())
-       end
        return menu
 end
\ No newline at end of file