From 5f5c165f0ba84110d1901f6d0836358c19f23e3a Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Thu, 23 Aug 2018 11:43:42 +0200 Subject: [PATCH] fix --- apps/router.lua | 3 -- apps/views/admin/{index.ls => layout.ls} | 0 apps/views/default/{index.ls => layout.ls} | 0 info/Makefile | 2 +- info/controllers/IndexController.lua | 10 ++++ info/models/CategoryModel.lua | 9 ++++ info/models/SectionsModel.lua | 13 ++++++ info/models/UserModel.lua | 12 +++++ info/router.lua | 54 ++++++++++++++++++++++ info/views/default/index/index.ls | 3 ++ info/views/default/layout.ls | 9 ++++ silk/Router.lua | 2 +- silk/router.lua.tpl | 54 ++++++++++++++++++++++ 13 files changed, 166 insertions(+), 5 deletions(-) rename apps/views/admin/{index.ls => layout.ls} (100%) rename apps/views/default/{index.ls => layout.ls} (100%) create mode 100644 info/controllers/IndexController.lua create mode 100644 info/models/CategoryModel.lua create mode 100644 info/models/SectionsModel.lua create mode 100644 info/models/UserModel.lua create mode 100644 info/router.lua create mode 100644 info/views/default/index/index.ls create mode 100644 info/views/default/layout.ls create mode 100644 silk/router.lua.tpl diff --git a/apps/router.lua b/apps/router.lua index df676a0..5eb7f2f 100644 --- a/apps/router.lua +++ b/apps/router.lua @@ -17,9 +17,6 @@ LOG_ROOT = WWW_ROOT..DIR_SEP.."logs" -- require needed library require(BASE_FRW.."silk.api") --- need to define this --- basically it initialize an session object --- session_start() -- registry object store global variables local REGISTRY = {} diff --git a/apps/views/admin/index.ls b/apps/views/admin/layout.ls similarity index 100% rename from apps/views/admin/index.ls rename to apps/views/admin/layout.ls diff --git a/apps/views/default/index.ls b/apps/views/default/layout.ls similarity index 100% rename from apps/views/default/index.ls rename to apps/views/default/layout.ls diff --git a/info/Makefile b/info/Makefile index 0c5b2cf..9ff2274 100644 --- a/info/Makefile +++ b/info/Makefile @@ -1,6 +1,6 @@ BUILDDIR = ../build/info -copyfiles = index.ls style.css +copyfiles = index.ls style.css router.lua models views controllers main: - mkdir $(BUILDDIR) diff --git a/info/controllers/IndexController.lua b/info/controllers/IndexController.lua new file mode 100644 index 0000000..10621f6 --- /dev/null +++ b/info/controllers/IndexController.lua @@ -0,0 +1,10 @@ +IndexController = BaseController:extends{ + class = "IndexController", + registry = {}, + models = { "sections", "user", "category" } +} + +function IndexController:index(...) + local args = {...} + return true +end diff --git a/info/models/CategoryModel.lua b/info/models/CategoryModel.lua new file mode 100644 index 0000000..3ddf774 --- /dev/null +++ b/info/models/CategoryModel.lua @@ -0,0 +1,9 @@ +CategoryModel = BaseModel:extends{ + registry = {}, + name = "cv_cat", + fields = { + publish = "NUMERIC", + name = "TEXT", + pid = "NUMERIC" + } +} \ No newline at end of file diff --git a/info/models/SectionsModel.lua b/info/models/SectionsModel.lua new file mode 100644 index 0000000..5a4fc94 --- /dev/null +++ b/info/models/SectionsModel.lua @@ -0,0 +1,13 @@ +SectionsModel = BaseModel:extends{ + name = "cv_sections", + fields = { + title = "TEXT", + start = "NUMERIC", + location = "TEXT", + ["end"] = "NUMERIC", + content = "TEXT", + subtitle = "TEXT", + publish = "NUMERIC", + cid = "NUMERIC", + } +} \ No newline at end of file diff --git a/info/models/UserModel.lua b/info/models/UserModel.lua new file mode 100644 index 0000000..e157945 --- /dev/null +++ b/info/models/UserModel.lua @@ -0,0 +1,12 @@ +UserModel = BaseModel:extends{ + registry = {}, + name = "user", + fields = { + address = "TEXT", + Phone = "TEXT", + shortbiblio = "TEXT", + fullname = "TEXT", + email = "TEXT", + url = "TEXT" + } +} \ No newline at end of file diff --git a/info/router.lua b/info/router.lua new file mode 100644 index 0000000..98c4847 --- /dev/null +++ b/info/router.lua @@ -0,0 +1,54 @@ + +-- the rewrite rule for the framework +-- should be something like this +-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>& +-- some global variables +DIR_SEP = "/" +WWW_ROOT = "/opt/www/htdocs/info" +HTTP_ROOT = "https://apps.localhost:9195/" +-- class path: path.to.class +BASE_FRW = "" +-- class path: path.to.class +CONTROLLER_ROOT = BASE_FRW.."info.controllers" +MODEL_ROOT = BASE_FRW.."info.models" +-- file path: path/to/file +VIEW_ROOT = WWW_ROOT..DIR_SEP.."views" +LOG_ROOT = WWW_ROOT..DIR_SEP.."logs" + +-- require needed library +require(BASE_FRW.."silk.api") + +-- registry object store global variables +local REGISTRY = {} +-- set logging level +REGISTRY.logger = Logger:new{ levels = {INFO = true, ERROR = true, DEBUG = true}} +REGISTRY.db = DBHelper:new{db="mrsang"} +REGISTRY.layout = 'default' + +REGISTRY.db:open() +local router = Router:new{registry = REGISTRY} +REGISTRY.router = router +router:setPath(CONTROLLER_ROOT) +--router:route('edit', 'post/edit', "ALL" ) + +-- example of depedencies to the current main route +-- each layout may have different dependencies +local default_routes_dependencies = { + edit = { + url = "post/edit", + visibility = { + shown = true, + routes = { + ["post/index"] = true + } + } + }, + --category = { + -- url = "cat/index", + -- visibility = "ALL" + --} +} +router:route('default', default_routes_dependencies ) +router:delegate() +if REGISTRY.db then REGISTRY.db:close() end + diff --git a/info/views/default/index/index.ls b/info/views/default/index/index.ls new file mode 100644 index 0000000..282580f --- /dev/null +++ b/info/views/default/index/index.ls @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/info/views/default/layout.ls b/info/views/default/layout.ls new file mode 100644 index 0000000..0d25652 --- /dev/null +++ b/info/views/default/layout.ls @@ -0,0 +1,9 @@ +Default page") + + local args = {...} + local views = args[1] + if views.__main__ then + views.__main__:render() + end +?> \ No newline at end of file diff --git a/silk/Router.lua b/silk/Router.lua index a03fa63..009e06e 100644 --- a/silk/Router.lua +++ b/silk/Router.lua @@ -77,7 +77,7 @@ function Router:delegate() end -- now require the main page to put the view - local fn, e = loadscript(VIEW_ROOT..DIR_SEP..self.registry.layout..DIR_SEP.."index.ls") + local fn, e = loadscript(VIEW_ROOT..DIR_SEP..self.registry.layout..DIR_SEP.."layout.ls") html() if fn then local r,o = pcall(fn, views) diff --git a/silk/router.lua.tpl b/silk/router.lua.tpl new file mode 100644 index 0000000..5eb7f2f --- /dev/null +++ b/silk/router.lua.tpl @@ -0,0 +1,54 @@ + +-- the rewrite rule for the framework +-- should be something like this +-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>& +-- some global variables +DIR_SEP = "/" +WWW_ROOT = "/opt/www/htdocs/apps" +HTTP_ROOT = "https://apps.localhost:9195/" +-- class path: path.to.class +BASE_FRW = "" +-- class path: path.to.class +CONTROLLER_ROOT = BASE_FRW.."apps.controllers" +MODEL_ROOT = BASE_FRW.."apps.models" +-- file path: path/to/file +VIEW_ROOT = WWW_ROOT..DIR_SEP.."views" +LOG_ROOT = WWW_ROOT..DIR_SEP.."logs" + +-- require needed library +require(BASE_FRW.."silk.api") + +-- registry object store global variables +local REGISTRY = {} +-- set logging level +REGISTRY.logger = Logger:new{ levels = {INFO = true, ERROR = true, DEBUG = true}} +REGISTRY.db = DBHelper:new{db="iosapps"} +REGISTRY.layout = 'default' + +REGISTRY.db:open() +local router = Router:new{registry = REGISTRY} +REGISTRY.router = router +router:setPath(CONTROLLER_ROOT) +--router:route('edit', 'post/edit', "ALL" ) + +-- example of depedencies to the current main route +-- each layout may have different dependencies +local default_routes_dependencies = { + edit = { + url = "post/edit", + visibility = { + shown = true, + routes = { + ["post/index"] = true + } + } + }, + --category = { + -- url = "cat/index", + -- visibility = "ALL" + --} +} +router:route('default', default_routes_dependencies ) +router:delegate() +if REGISTRY.db then REGISTRY.db:close() end +