gluon-web: split out model support into a separate package
This commit is contained in:
parent
83a6847fbd
commit
c3e4ceed28
@ -15,7 +15,7 @@ define Package/gluon-setup-mode
|
||||
SECTION:=gluon
|
||||
CATEGORY:=Gluon
|
||||
TITLE:=Setup mode
|
||||
DEPENDS:=+gluon-core +gluon-web +ubus +uhttpd +dnsmasq
|
||||
DEPENDS:=+gluon-core +gluon-web-model +ubus +uhttpd +dnsmasq
|
||||
endef
|
||||
|
||||
define Package/gluon-setup-mode/description
|
||||
|
36
package/gluon-web-model/Makefile
Normal file
36
package/gluon-web-model/Makefile
Normal file
@ -0,0 +1,36 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=gluon-web-model
|
||||
PKG_VERSION:=1
|
||||
|
||||
|
||||
include ../gluon.mk
|
||||
|
||||
PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG)
|
||||
|
||||
|
||||
define Package/gluon-web-model
|
||||
SECTION:=gluon
|
||||
CATEGORY:=Gluon
|
||||
TITLE:=Minimal Lua web framework derived from LuCI (model support)
|
||||
DEPENDS:=+gluon-web
|
||||
endef
|
||||
|
||||
|
||||
define Build/Prepare
|
||||
mkdir -p $(PKG_BUILD_DIR)
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(call GluonBuildI18N,gluon-web-model,i18n)
|
||||
$(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
|
||||
endef
|
||||
|
||||
define Package/gluon-web-model/install
|
||||
$(CP) ./files/* $(1)/
|
||||
$(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/
|
||||
$(call GluonInstallI18N,gluon-web-model,$(1))
|
||||
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,gluon-web-model))
|
23
package/gluon-web-model/i18n/de.po
Normal file
23
package/gluon-web-model/i18n/de.po
Normal file
@ -0,0 +1,23 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"PO-Revision-Date: 2013-03-29 12:13+0200\n"
|
||||
"Last-Translator: Matthias Schiffer <mschiffer@universe-factory.net>\n"
|
||||
"Language-Team: German\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
msgid "One or more fields contain invalid values!"
|
||||
msgstr "Ein oder mehrere Felder enthalten ungültige Werte!"
|
||||
|
||||
msgid "One or more required fields have no value!"
|
||||
msgstr "Ein oder mehr benötigte Felder sind nicht ausgefüllt!"
|
||||
|
||||
msgid "Reset"
|
||||
msgstr "Zurücksetzen"
|
||||
|
||||
msgid "Save"
|
||||
msgstr "Speichern"
|
23
package/gluon-web-model/i18n/fr.po
Normal file
23
package/gluon-web-model/i18n/fr.po
Normal file
@ -0,0 +1,23 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"PO-Revision-Date: 2013-12-22 17:11+0200\n"
|
||||
"Last-Translator: goofy <pierre.gaufillet@gmail.com>\n"
|
||||
"Language-Team: French\n"
|
||||
"Language: fr\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
|
||||
msgid "One or more fields contain invalid values!"
|
||||
msgstr "Un ou plusieurs champs contiennent des valeurs incorrectes !"
|
||||
|
||||
msgid "One or more required fields have no value!"
|
||||
msgstr "Un ou plusieurs champs n'ont pas de valeur !"
|
||||
|
||||
msgid "Reset"
|
||||
msgstr "Remise à zéro"
|
||||
|
||||
msgid "Save"
|
||||
msgstr "Soumettre"
|
14
package/gluon-web-model/i18n/gluon-web-model.pot
Normal file
14
package/gluon-web-model/i18n/gluon-web-model.pot
Normal file
@ -0,0 +1,14 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8"
|
||||
|
||||
msgid "One or more fields contain invalid values!"
|
||||
msgstr ""
|
||||
|
||||
msgid "One or more required fields have no value!"
|
||||
msgstr ""
|
||||
|
||||
msgid "Reset"
|
||||
msgstr ""
|
||||
|
||||
msgid "Save"
|
||||
msgstr ""
|
@ -0,0 +1,68 @@
|
||||
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
||||
-- Copyright 2017-2018 Matthias Schiffer <mschiffer@universe-factory.net>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
module('gluon.web.model', package.seeall)
|
||||
|
||||
local fs = require 'nixio.fs'
|
||||
local classes = require 'gluon.web.model.classes'
|
||||
|
||||
local util = require 'gluon.web.util'
|
||||
local instanceof = util.instanceof
|
||||
|
||||
-- Loads a model from given file, creating an environment and returns it
|
||||
local function load(filename, i18n)
|
||||
local func = assert(loadfile(filename))
|
||||
|
||||
setfenv(func, setmetatable({}, {__index =
|
||||
function(tbl, key)
|
||||
return classes[key] or i18n[key] or _G[key]
|
||||
end
|
||||
}))
|
||||
|
||||
local models = { func() }
|
||||
|
||||
for k, model in ipairs(models) do
|
||||
if not instanceof(model, classes.Node) then
|
||||
error("model definition returned an invalid model object")
|
||||
end
|
||||
model.index = k
|
||||
end
|
||||
|
||||
return models
|
||||
end
|
||||
|
||||
return function(config, http, renderer, name, pkg)
|
||||
local hidenav = false
|
||||
|
||||
local modeldir = config.base_path .. '/model/'
|
||||
local filename = modeldir..name..'.lua'
|
||||
|
||||
if not fs.access(filename) then
|
||||
error("Model '" .. name .. "' not found!")
|
||||
end
|
||||
|
||||
local i18n = setmetatable({
|
||||
i18n = renderer.i18n
|
||||
}, {
|
||||
__index = renderer.i18n(pkg)
|
||||
})
|
||||
|
||||
local maps = load(filename, i18n)
|
||||
|
||||
for _, map in ipairs(maps) do
|
||||
map:parse(http)
|
||||
end
|
||||
for _, map in ipairs(maps) do
|
||||
map:handle()
|
||||
hidenav = hidenav or map.hidenav
|
||||
end
|
||||
|
||||
renderer.render('layout', {
|
||||
content = 'model/wrapper',
|
||||
env = {
|
||||
maps = maps,
|
||||
},
|
||||
hidenav = hidenav,
|
||||
})
|
||||
end
|
@ -1,12 +1,11 @@
|
||||
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
||||
-- Copyright 2017 Matthias Schiffer <mschiffer@universe-factory.net>
|
||||
-- Copyright 2017-2018 Matthias Schiffer <mschiffer@universe-factory.net>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
module("gluon.web.model", package.seeall)
|
||||
module("gluon.web.model.classes", package.seeall)
|
||||
|
||||
local util = require "gluon.web.util"
|
||||
|
||||
local fs = require "nixio.fs"
|
||||
local datatypes = require "gluon.web.model.datatypes"
|
||||
local class = util.class
|
||||
local instanceof = util.instanceof
|
||||
@ -15,41 +14,6 @@ FORM_NODATA = 0
|
||||
FORM_VALID = 1
|
||||
FORM_INVALID = -1
|
||||
|
||||
-- Loads a model from given file, creating an environment and returns it
|
||||
function load(config, name, renderer, pkg)
|
||||
local modeldir = config.base_path .. "/model/"
|
||||
|
||||
if not fs.access(modeldir..name..".lua") then
|
||||
error("Model '" .. name .. "' not found!")
|
||||
end
|
||||
|
||||
local func = assert(loadfile(modeldir..name..".lua"))
|
||||
|
||||
local i18n = setmetatable({
|
||||
i18n = renderer.i18n
|
||||
}, {
|
||||
__index = renderer.i18n(pkg)
|
||||
})
|
||||
|
||||
|
||||
setfenv(func, setmetatable({}, {__index =
|
||||
function(tbl, key)
|
||||
return _M[key] or i18n[key] or _G[key]
|
||||
end
|
||||
}))
|
||||
|
||||
local models = { func() }
|
||||
|
||||
for k, model in ipairs(models) do
|
||||
if not instanceof(model, Node) then
|
||||
error("model definition returned an invalid model object")
|
||||
end
|
||||
model.index = k
|
||||
end
|
||||
|
||||
return models
|
||||
end
|
||||
|
||||
|
||||
local function parse_datatype(code)
|
||||
local match, arg, arg2
|
||||
@ -86,7 +50,7 @@ function Node:__init__(title, description, name)
|
||||
self.name = name
|
||||
self.index = nil
|
||||
self.parent = nil
|
||||
self.package = 'gluon-web'
|
||||
self.package = 'gluon-web-model'
|
||||
end
|
||||
|
||||
function Node:append(obj)
|
@ -16,7 +16,7 @@ define Package/gluon-web-theme
|
||||
SECTION:=gluon
|
||||
CATEGORY:=Gluon
|
||||
TITLE:=gluon-web theme
|
||||
DEPENDS:=+gluon-core +gluon-web
|
||||
DEPENDS:=+gluon-core +gluon-web-model
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
|
@ -142,7 +142,7 @@ You may obtain a copy of the License at
|
||||
<%
|
||||
ok, err = pcall(renderer.render, content, env, pkg)
|
||||
if not ok then
|
||||
renderer.render('error500', {message = err}, 'gluon-web')
|
||||
renderer.render('error/500', {message = err}, 'gluon-web')
|
||||
end
|
||||
%>
|
||||
|
||||
|
@ -3,7 +3,6 @@ include $(TOPDIR)/rules.mk
|
||||
PKG_NAME:=gluon-web
|
||||
PKG_VERSION:=1
|
||||
|
||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
include ../gluon.mk
|
||||
|
||||
|
@ -16,18 +16,6 @@ msgstr "Interner Serverfehler"
|
||||
msgid "Not Found"
|
||||
msgstr "Nicht Gefunden"
|
||||
|
||||
msgid "One or more fields contain invalid values!"
|
||||
msgstr "Ein oder mehrere Felder enthalten ungültige Werte!"
|
||||
|
||||
msgid "One or more required fields have no value!"
|
||||
msgstr "Ein oder mehr benötigte Felder sind nicht ausgefüllt!"
|
||||
|
||||
msgid "Reset"
|
||||
msgstr "Zurücksetzen"
|
||||
|
||||
msgid "Save"
|
||||
msgstr "Speichern"
|
||||
|
||||
msgid "Sorry, the object you requested was not found."
|
||||
msgstr "Entschuldigung, das anfgeforderte Objekt wurde nicht gefunden."
|
||||
|
||||
|
@ -16,18 +16,6 @@ msgstr "Erreur Serveur Interne"
|
||||
msgid "Not Found"
|
||||
msgstr "Pas trouvé"
|
||||
|
||||
msgid "One or more fields contain invalid values!"
|
||||
msgstr "Un ou plusieurs champs contiennent des valeurs incorrectes !"
|
||||
|
||||
msgid "One or more required fields have no value!"
|
||||
msgstr "Un ou plusieurs champs n'ont pas de valeur !"
|
||||
|
||||
msgid "Reset"
|
||||
msgstr "Remise à zéro"
|
||||
|
||||
msgid "Save"
|
||||
msgstr "Soumettre"
|
||||
|
||||
msgid "Sorry, the object you requested was not found."
|
||||
msgstr "Désolé, l'objet que vous avez demandé n'as pas été trouvé."
|
||||
|
||||
|
@ -7,18 +7,6 @@ msgstr ""
|
||||
msgid "Not Found"
|
||||
msgstr ""
|
||||
|
||||
msgid "One or more fields contain invalid values!"
|
||||
msgstr ""
|
||||
|
||||
msgid "One or more required fields have no value!"
|
||||
msgstr ""
|
||||
|
||||
msgid "Reset"
|
||||
msgstr ""
|
||||
|
||||
msgid "Save"
|
||||
msgstr ""
|
||||
|
||||
msgid "Sorry, the object you requested was not found."
|
||||
msgstr ""
|
||||
|
||||
|
@ -146,26 +146,7 @@ local function dispatch(config, http, request)
|
||||
model = function(name)
|
||||
local pkg = _pkg
|
||||
return function()
|
||||
local hidenav = false
|
||||
|
||||
local model = require "gluon.web.model"
|
||||
local maps = model.load(config, name, renderer, pkg)
|
||||
|
||||
for _, map in ipairs(maps) do
|
||||
map:parse(http)
|
||||
end
|
||||
for _, map in ipairs(maps) do
|
||||
map:handle()
|
||||
hidenav = hidenav or map.hidenav
|
||||
end
|
||||
|
||||
renderer.render("layout", {
|
||||
content = "model/wrapper",
|
||||
env = {
|
||||
maps = maps,
|
||||
},
|
||||
hidenav = hidenav,
|
||||
})
|
||||
require('gluon.web.model')(config, http, renderer, name, pkg)
|
||||
end
|
||||
end,
|
||||
|
||||
@ -198,7 +179,7 @@ local function dispatch(config, http, request)
|
||||
if not node or not node.target then
|
||||
http:status(404, "Not Found")
|
||||
renderer.render("layout", {
|
||||
content = "error404",
|
||||
content = "error/404",
|
||||
env = {
|
||||
message =
|
||||
"No page is registered at '/" .. table.concat(request, "/") .. "'.\n" ..
|
||||
@ -215,7 +196,7 @@ local function dispatch(config, http, request)
|
||||
if not ok then
|
||||
http:status(500, "Internal Server Error")
|
||||
renderer.render("layout", {
|
||||
content = "error500",
|
||||
content = "error/500",
|
||||
env = {
|
||||
message =
|
||||
"Failed to execute dispatcher target for entry '/" .. table.concat(request, "/") .. "'.\n" ..
|
||||
|
Loading…
Reference in New Issue
Block a user