From 44f50f3a52f304be7667b328e3ed31a026d6c3e6 Mon Sep 17 00:00:00 2001 From: lxsang Date: Mon, 22 Jun 2020 22:14:52 +0200 Subject: [PATCH] Add Booklet front end --- Makefile | 2 +- blog/views/default/layout.ls | 2 +- doc/Makefile | 6 + doc/assets/style.css | 164 ++++++++++++++++++++++++++++ doc/controllers/AntosController.lua | 8 ++ doc/controllers/IndexController.lua | 10 ++ doc/controllers/TocController.lua | 5 + doc/controllers/doccontroller.lua | 107 ++++++++++++++++++ doc/router.lua | 52 +++++++++ doc/views/default/index/index.ls | 4 + doc/views/default/index/notfound.ls | 1 + doc/views/default/layout.ls | 93 ++++++++++++++++ doc/views/default/toc/index.ls | 31 ++++++ info/views/default/layout.ls | 2 +- silk/Router.lua | 3 +- 15 files changed, 486 insertions(+), 4 deletions(-) create mode 100644 doc/Makefile create mode 100644 doc/assets/style.css create mode 100644 doc/controllers/AntosController.lua create mode 100644 doc/controllers/IndexController.lua create mode 100644 doc/controllers/TocController.lua create mode 100644 doc/controllers/doccontroller.lua create mode 100644 doc/router.lua create mode 100644 doc/views/default/index/index.ls create mode 100644 doc/views/default/index/notfound.ls create mode 100644 doc/views/default/layout.ls create mode 100644 doc/views/default/toc/index.ls diff --git a/Makefile b/Makefile index eca50c5..45c8ce0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BUILDDIR?=./build -PROJS?=grs info blog apps os +PROJS?=grs info blog apps os doc copyfiles = index.ls mimes.json main: copy for f in $(PROJS); do BUILDDIR=$(BUILDDIR)/"$${f}" make -C "$${f}" ; done diff --git a/blog/views/default/layout.ls b/blog/views/default/layout.ls index 69f679d..35ac596 100644 --- a/blog/views/default/layout.ls +++ b/blog/views/default/layout.ls @@ -125,7 +125,7 @@
- Powered by antd server, (c) 2017 - 2018 Xuan Sang LE + Powered by antd server, (c) 2017 - Xuan Sang LE
\ No newline at end of file diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000..fa4e7c8 --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,6 @@ +copyfiles = views controllers router.lua assets + +main: + - mkdir $(BUILDDIR) + cp -rvf $(copyfiles) $(BUILDDIR) + - cd $(BUILDDIR) && ln -s ../grs ./rst \ No newline at end of file diff --git a/doc/assets/style.css b/doc/assets/style.css new file mode 100644 index 0000000..3ae2760 --- /dev/null +++ b/doc/assets/style.css @@ -0,0 +1,164 @@ +html,body{ + margin: 0; + padding: 0; + font-family: "Ubuntu"; + font-size: 15px; + line-height: 1.5; + width: 100%; + height: 100%; + overflow: hidden; +} +#top{ + background-color: #2c2c2c; + color: white; + font-weight: bold; + display: block; + text-align: center; + height: 30px; +} + +#bottom{ + position: fixed; + bottom: 0; + height: 20px; + text-align: center; + color:#878887; + background-color: white; + font-size: 12px; + width: 100%; + padding:5px; + border-top: 1px solid #878887; +} + +#cover{ + height: calc(100% - 80px); + overflow-y: auto; +} +#navbar{ + margin:0 auto; + max-width: 85%; + display: flex; + justify-content:flex-end; + flex-direction: row; +} +#book{ + margin:0 auto; + max-width: 85%; + max-height: 100%; + display: block; + justify-content:flex-end; + flex-direction: row; + text-align: justify; + height: 100%; +} +div.doc-name { + width: 300px; + text-align: left; + padding-top:3px; +} +div.doc-name a { + text-decoration: none; + color: #c9c9c9; +} + +div.doc-name a:before{ + /* padding-top:13px; */ + content: "\f015"; + color:#c9c9c9; + width:20px; + height: 25px; + font-family: "FontAwesome"; + font-size: 18px; +} +input.search-box{ + outline: none; + border: 0; + flex:1; + padding:0; + margin:0; + /* padding-top:13px; */ + height: 25px; + background-color: transparent; + border-bottom: 1px solid #878887; + font-size: 15px; + font-family: "Ubuntu"; + line-height: 0.5; + color: #878887; +} +div.search-icon:before{ + /* padding-top:13px; */ + content: "\f002"; + color:#878887; + display: block; + width:20px; + height: 25px; + font-family: "FontAwesome"; + font-size: 18px; + border-bottom: 1px solid #878887; +} +div.search-icon { + width: 35px; +} +div.doc-toc { + width: 300px; + /* font-size: 11px; */ + background-color: #e3e3e3; + color: #2c2c2c; + overflow: auto; + position: fixed; + top: 30px; + bottom: 30px; + border-right: 1px solid #c9c9c9; + padding-top: 10px; +} +div.doc-toc a { + text-decoration: none; + color: #2c2c2c; +} +#toc { + margin: 0; + list-style-type: none; + padding: 0; + padding-left: 10px; +} +div.doc-toc ul.nested { + list-style-type: none; +} + +div.doc-toc .caret { + cursor: pointer; + user-select: none; /* Prevent text selection */ +} +div.doc-toc .caret::before { + content: "\f147"; + color: #2c2c2c; + display: inline-block; + font-family: "FontAwesome"; + margin-right: 5px; +} +div.doc-toc .nested { + display: none; +} +div.doc-toc .caret-down::before { + content: "\f196"; + color: #2c2c2c; + display: inline-block; + font-family: "FontAwesome"; + margin-right: 5px; +} +div.doc-toc .active { + display: block; + padding-left: 20px; +} + +div.doc-content { + display: block; + width: calc(100% - 320px); + float: right; +} + +/* for block of code */ +/* #container .blogentry .hljs-ln td.hljs-ln-code { + padding-left: 10px; +} */ +img {max-width:100%} \ No newline at end of file diff --git a/doc/controllers/AntosController.lua b/doc/controllers/AntosController.lua new file mode 100644 index 0000000..9a6e260 --- /dev/null +++ b/doc/controllers/AntosController.lua @@ -0,0 +1,8 @@ +require(CONTROLLER_ROOT..".doccontroller") +DocController:subclass("AntosController", { + path_map = { + vfs_path = "home://testws/antos", + local_path = "/home/mrsang/testws/antos" + }, + name = "antos" +}) diff --git a/doc/controllers/IndexController.lua b/doc/controllers/IndexController.lua new file mode 100644 index 0000000..fe94f52 --- /dev/null +++ b/doc/controllers/IndexController.lua @@ -0,0 +1,10 @@ +BaseController:subclass("IndexController") + +function IndexController:index(...) + return true +end + +function IndexController:actionnotfound(...) + self.template:setView("index") + return self:index(table.unpack({...})) +end \ No newline at end of file diff --git a/doc/controllers/TocController.lua b/doc/controllers/TocController.lua new file mode 100644 index 0000000..c888984 --- /dev/null +++ b/doc/controllers/TocController.lua @@ -0,0 +1,5 @@ +BaseController:subclass("TocController") + +function TocController:index(...) + return true +end \ No newline at end of file diff --git a/doc/controllers/doccontroller.lua b/doc/controllers/doccontroller.lua new file mode 100644 index 0000000..ba9ae11 --- /dev/null +++ b/doc/controllers/doccontroller.lua @@ -0,0 +1,107 @@ +BaseController:subclass("DocController") + +local getpath = function(vfspath, controller) + return vfspath:gsub(controller.path_map.vfs_path, controller.path_map.local_path) +end + +function DocController:loadTOC() + local path = self.path_map.local_path.."/meta.json" + local result = { error = false} + if ulib.exists(path) then + local bmeta = JSON.decodeFile(path) + if bmeta == nil then + result.error = true + result.data = "Unable to read book meta.json" + else + result.data = { + name = bmeta.name, + path = self.path_map.vfs_path.."/INTRO.md", + entries = {} + } + -- read all the entries + for kc,vc in pairs(bmeta.entries) do + local cpath = getpath(vc.path, self).."/meta.json" + if ulib.exists(cpath) then + local cmeta = JSON.decodeFile(cpath) + if cmeta then + local chapter = { + name = cmeta.name, + path = vc.path.."/INTRO.md", + entries = {} + } + -- read all sections + for ks,vs in pairs(cmeta.entries) do + local spath = getpath(vs.path, self).."/meta.json" + local smeta = JSON.decodeFile(spath) + if smeta then + local section = { + name = smeta.name, + path = vs.path.."/INTRO.md", + entries = {} + } + -- read all files + for kf,vf in pairs(smeta.entries) do + local fpath = getpath(vf.path, self) + if ulib.exists(fpath) then + local file = io.open(fpath, "r") + io.input(file) + local line = io.read() + io.close() + if line then + local file = { + name = std.trim(std.trim(line, "#"), " "), + path = vf.path + } + table.insert( section.entries, file) + end + end + end + table.insert( chapter.entries, section) + end + end + table.insert( result.data.entries, chapter) + end + end + end + end + else + result.error = true + result.data = "No meta-data found" + end + return result +end + +function DocController:index(...) + local args = {...} + local toc = self:loadTOC() + toc.controller = self.name + self.template:set("toc", toc) + -- read data from the parameter + local path = nil + if args[1] then + local b64text = args[1] + if b64text then + local p = bytes.__tostring(std.b64decode(b64text .. "==")) + if p then + path = getpath(p, self) + end + end + else + path = self.path_map.local_path.."/INTRO.md" + end + if path and ulib.exists(path) then + local file = io.open(path, "r") + local content = file:read("*a") + file.close() + self.template:setView("index", "index") + self.template:set("data", content) + else + self.template:setView("notfound", "index") + end + return true +end + +function DocController:actionnotfound(...) + local args = {...} + return self:index(table.unpack(args)) +end \ No newline at end of file diff --git a/doc/router.lua b/doc/router.lua new file mode 100644 index 0000000..953a75e --- /dev/null +++ b/doc/router.lua @@ -0,0 +1,52 @@ + +-- the rewrite rule for the framework +-- should be something like this +-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>& +-- some global variables +DIR_SEP = "/" +WWW_ROOT = __ROOT__.."/doc" +if HEADER.Host then + HTTP_ROOT= "https://"..HEADER.Host +else + HTTP_ROOT = "https://doc.iohub.dev" +end +-- class path: path.to.class +BASE_FRW = "" +-- class path: path.to.class +CONTROLLER_ROOT = BASE_FRW.."doc.controllers" +MODEL_ROOT = BASE_FRW.."doc.models" +-- file path: path/to/file +VIEW_ROOT = WWW_ROOT..DIR_SEP.."views" +LOG_ROOT = WWW_ROOT..DIR_SEP.."logs" +POST_LIMIT = 10 +-- require needed library +require(BASE_FRW.."silk.api") + +if REQUEST.r then + REQUEST.r = REQUEST.r:gsub("%:", "/") +end + +-- registry object store global variables +local REGISTRY = {} +-- set logging level +REGISTRY.logger = Logger:new{ levels = {INFO = false, ERROR = true, DEBUG = false}} +REGISTRY.layout = 'default' +REGISTRY.fileaccess = true + +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 = { + toc = { + url = "toc/index", + visibility = "ALL" + } +} +router:route('default', default_routes_dependencies ) +--router:remap("r", "post") +router:delegate() + diff --git a/doc/views/default/index/index.ls b/doc/views/default/index/index.ls new file mode 100644 index 0000000..a148ed2 --- /dev/null +++ b/doc/views/default/index/index.ls @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/doc/views/default/index/notfound.ls b/doc/views/default/index/notfound.ls new file mode 100644 index 0000000..19eacfb --- /dev/null +++ b/doc/views/default/index/notfound.ls @@ -0,0 +1 @@ +404 not found \ No newline at end of file diff --git a/doc/views/default/layout.ls b/doc/views/default/layout.ls new file mode 100644 index 0000000..76d5f53 --- /dev/null +++ b/doc/views/default/layout.ls @@ -0,0 +1,93 @@ + + + + + + + + + + <?lua + if tocdata then + echo(tocdata.data.name) + else + echo("Untitled") + end + ?> + + + +
+ +
+
+
+
+ +
+ +
+ +
+
+
+ +
+ Powered by antd server, (c) 2019 - Xuan Sang LE +
+ + + diff --git a/doc/views/default/toc/index.ls b/doc/views/default/toc/index.ls new file mode 100644 index 0000000..bd614f0 --- /dev/null +++ b/doc/views/default/toc/index.ls @@ -0,0 +1,31 @@ +' + end + local markup = '
  • '..caret..''..data.name.."" + if data.entries then + markup = markup.."
      " + for k,v in pairs(data.entries) do + markup = markup..gentree(v, controller) + end + markup = markup.."
    " + end + markup = markup.."
  • " + return markup +end +?> + \ No newline at end of file diff --git a/info/views/default/layout.ls b/info/views/default/layout.ls index 1640c84..ca4e369 100644 --- a/info/views/default/layout.ls +++ b/info/views/default/layout.ls @@ -49,7 +49,7 @@ ?>