From 661e4dee9f635888adc44893ca72907687f10017 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 25 Feb 2018 05:44:25 +0100 Subject: [PATCH] gluon-config-mode-core, gluon-web-*: do not access dispatcher directly --- .../web/model/gluon-config-mode/wizard.lua | 1 - .../gluon/web/controller/admin/upgrade.lua | 1 - .../gluon/web/view/themes/gluon/layout.html | 34 ++++++++++++++++--- .../usr/lib/lua/gluon/web/dispatcher.lua | 27 --------------- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/package/gluon-config-mode-core/luasrc/lib/gluon/web/model/gluon-config-mode/wizard.lua b/package/gluon-config-mode-core/luasrc/lib/gluon/web/model/gluon-config-mode/wizard.lua index 2afceb31..d328f438 100644 --- a/package/gluon-config-mode-core/luasrc/lib/gluon/web/model/gluon-config-mode/wizard.lua +++ b/package/gluon-config-mode-core/luasrc/lib/gluon/web/model/gluon-config-mode/wizard.lua @@ -1,4 +1,3 @@ -local disp = require 'gluon.web.dispatcher' local fs = require "nixio.fs" local util = require "gluon.web.util" local nixio_util = require "nixio.util" diff --git a/package/gluon-web-admin/luasrc/lib/gluon/web/controller/admin/upgrade.lua b/package/gluon-web-admin/luasrc/lib/gluon/web/controller/admin/upgrade.lua index 98562005..dc6dbea2 100644 --- a/package/gluon-web-admin/luasrc/lib/gluon/web/controller/admin/upgrade.lua +++ b/package/gluon-web-admin/luasrc/lib/gluon/web/controller/admin/upgrade.lua @@ -30,7 +30,6 @@ local function filehandler(meta, chunk, eof) end local function action_upgrade(http, renderer) - local disp = require 'gluon.web.dispatcher' local nixio = require 'nixio' local function fork_exec(...) diff --git a/package/gluon-web-theme/files/lib/gluon/web/view/themes/gluon/layout.html b/package/gluon-web-theme/files/lib/gluon/web/view/themes/gluon/layout.html index b7f60d09..febe91b5 100644 --- a/package/gluon-web-theme/files/lib/gluon/web/view/themes/gluon/layout.html +++ b/package/gluon-web-theme/files/lib/gluon/web/view/themes/gluon/layout.html @@ -10,7 +10,6 @@ You may obtain a copy of the License at -%> <% local uci = require("simple-uci").cursor() - local disp = require "gluon.web.dispatcher" local fs = require "nixio.fs" local pretty_hostname = require "pretty_hostname" @@ -23,9 +22,34 @@ You may obtain a copy of the License at local category = request[1] local cattree = category and node(category) - local categories = disp.node_children(root) + local function node_visible(node) + return ( + node.title and + node.target and + (not node.hidden) + ) + end - http:prepare_content("application/xhtml+xml") + local function node_children(node) + if not node then return {} end + + local ret = {} + for k, v in pairs(node.nodes) do + if node_visible(v) then + table.insert(ret, k) + end + end + + table.sort(ret, + function(a, b) + return (node.nodes[a].order or 100) + < (node.nodes[b].order or 100) + end + ) + return ret + end + + local categories = node_children(root) local function append(xs, x) local r = {unpack(xs)} @@ -40,7 +64,7 @@ You may obtain a copy of the License at local function subtree(prefix, node, name, ...) if not node then return end - local children = disp.node_children(node) + local children = node_children(node) if #children == 0 then return end %> @@ -69,6 +93,8 @@ You may obtain a copy of the License at local function menutree(path, ...) subtree({path}, root.nodes[category], ...) end + + http:prepare_content("application/xhtml+xml") -%> diff --git a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/dispatcher.lua b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/dispatcher.lua index 25404fa4..2612af99 100644 --- a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/dispatcher.lua +++ b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/dispatcher.lua @@ -20,33 +20,6 @@ function redirect(http, ...) http:redirect(build_url(http, {...})) end -function node_visible(node) - return ( - node.title and - node.target and - (not node.hidden) - ) -end - -function node_children(node) - if not node then return {} end - - local ret = {} - for k, v in pairs(node.nodes) do - if node_visible(v) then - table.insert(ret, k) - end - end - - table.sort(ret, - function(a, b) - return (node.nodes[a].order or 100) - < (node.nodes[b].order or 100) - end - ) - return ret -end - function httpdispatch(http) local request = {}