Skip to content
Snippets Groups Projects
Unverified Commit c3e4ceed authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

gluon-web: split out model support into a separate package

parent 83a6847f
No related branches found
No related tags found
No related merge requests found
Showing
with 169 additions and 41 deletions
......@@ -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
......
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))
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"
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"
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 ""
-- 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
-- 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment