From: Steven Barth Date: Mon, 10 Mar 2008 08:53:14 +0000 (+0000) Subject: Moved examples out of source directory X-Git-Tag: 0.8.0~1219 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=93a98dd13be5127871ff78d85e8199f2df77e9c2;p=oweals%2Fluci.git Moved examples out of source directory Added a first draft design Cleaned up Makefile Prepared for module development --- diff --git a/Makefile b/Makefile index 38b7981ec..2d732ff08 100644 --- a/Makefile +++ b/Makefile @@ -12,16 +12,25 @@ DIRECTORIES = dist/ffluci/model dist/ffluci/controller/public dist/ffluci/contro INFILES = $(CFILES:%=src/%) OUTFILE = ffluci/init.lua +.PHONY: all dist-compile dist-source examples-compile examples-source dist examples compile source clean + all: compile -dist-compile: compile examples -dist-source: source examples +dist-compile: compile dist +dist-source: source dist -examples: +examples-compile: compile examples +examples-source: source examples + + +dist: cp src/ffluci/controller/public/* dist/ffluci/controller/public/ cp src/ffluci/controller/admin/* dist/ffluci/controller/admin/ cp src/ffluci/i18n/* dist/ffluci/i18n/ cp src/ffluci/view/* dist/ffluci/view/ -R + +examples: + cp examples/* dist/ -R compile: mkdir -p $(DIRECTORIES) @@ -34,7 +43,5 @@ source: for i in $(CFILES); do cp src/$$i dist/$$i; done for i in $(FILES); do cp src/$$i dist/$$i; done - -.PHONY: clean clean: rm dist -rf diff --git a/contrib/index.cgi b/contrib/index.cgi index 429b4c3b0..31705ccf2 100755 --- a/contrib/index.cgi +++ b/contrib/index.cgi @@ -1,3 +1,3 @@ #!/usr/bin/haserl --shell=luac print("Status: 302 Found") -print("Location: /cgi-bin/ffluci\n") +print("Location: ffluci\n") diff --git a/contrib/media/cascade.css b/contrib/media/cascade.css new file mode 100644 index 000000000..143b93ba2 --- /dev/null +++ b/contrib/media/cascade.css @@ -0,0 +1,138 @@ +body { + font-family: Verdana, Arial, sans-serif; + background-color: #aaaaaa; +} + +#header { + padding: 0.2em; + height: 4.5em; + background-color: #262626; +} + +#columns { + border-left: 10.1em solid #262626; + border-right: 10.1em solid #262626; + display: block; + background-color: white; + padding: 0.1em; +} + +#columnswrapper { + display: block; + margin-left: -10em; + margin-right: -10em; +} + +#content { + margin-left: 10em; + margin-right: 10em; + display: block; + position: relative; + padding: 2px; +} + +.headerlogo { + height: 4em; + padding: 5px; +} + +.headerlogo img { + height: 100%; +} + +.headertitle { + font-size: 2.4em; + color: gray; + letter-spacing: 0.5em; + text-transform: lowercase; +} + +.separator { + padding-left: 0.25em; + font-weight: bold; + font-size: 0.8em; + line-height: 1.4em; +} + +.whitetext { + color: white; +} + +.yellowtext { + color: #ffcb05; +} + +.magentatext { + color: #dc0065; +} + +.inheritcolor { + color: inherit; +} + +.smalltext { + font-size: 0.8em; +} + +.yellow { + background-color: #ffcb05; +} + +.magenta { + background-color: #dc0065; +} + +.nodeco { + text-decoration: none; +} + +.redhover:hover { + color: red; +} + +.bold { + font-weight: bold; +} + +.sidebar { + position: relative; + padding: 0.25em; + color: gray; + width: 9em; + font-weight: bold; +} + +.separator a, .sidebar a { + color: inherit; + text-decoration: inherit; +} + +.separator a:hover, .sidebar a:hover { + color: red; +} + +.sidebar div { + padding-bottom: 0.5em; +} + +.sidebar ul { + font-size: 0.8em; + color: white; + list-style-type: none; + padding-left: 1em; + margin-top: 0%; +} + +.left { + float: left; + text-align: left; +} + +.right { + float: right; + text-align: right; +} + +.clear { + clear: both; +} diff --git a/contrib/media/logo.png b/contrib/media/logo.png new file mode 100644 index 000000000..d4c5dd9a3 Binary files /dev/null and b/contrib/media/logo.png differ diff --git a/contrib/package/ffluci/Makefile b/contrib/package/ffluci/Makefile index 12e811d2c..dab80be37 100644 --- a/contrib/package/ffluci/Makefile +++ b/contrib/package/ffluci/Makefile @@ -34,7 +34,9 @@ endef define Package/ffluci/install $(INSTALL_DIR) $(1)/usr/lib/lua $(INSTALL_DIR) $(1)/www/cgi-bin + $(INSTALL_DIR) $(1)/www/ffluci $(CP) $(PKG_BUILD_DIR)/dist/* $(1)/usr/lib/lua/ -R + $(CP) $(PKG_BUILD_DIR)/contrib/media $(1)/www/ffluci/ -R $(INSTALL_BIN) $(PKG_BUILD_DIR)/contrib/ffluci $(1)/www/cgi-bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/contrib/index.cgi $(1)/www/cgi-bin $(CP) -a ./ipkg/ffluci.postinst $(1)/CONTROL/postinst diff --git a/examples/ffluci/controller/admin/index.lua b/examples/ffluci/controller/admin/index.lua new file mode 100644 index 000000000..9aec94c86 --- /dev/null +++ b/examples/ffluci/controller/admin/index.lua @@ -0,0 +1,15 @@ +module(..., package.seeall) + +function dispatcher(request) + require("ffluci.template").render("header") + print("Hello there, Mr. Administrator") + require("ffluci.template").render("footer") +end + +menu = { + descr = "Administrative", + order = 10, + entries = { + {action = "index", descr = "Hello"} + } +} \ No newline at end of file diff --git a/examples/ffluci/controller/public/example-action.lua b/examples/ffluci/controller/public/example-action.lua new file mode 100644 index 000000000..538f5d9d0 --- /dev/null +++ b/examples/ffluci/controller/public/example-action.lua @@ -0,0 +1,49 @@ +-- This example demonstrates the action dispatcher which invokes +-- an appropriate action function named action_"action" + +-- This example consists of: +-- ffluci/controller/index/example-action.lua (this file) + +-- Try the following address(es) in your browser: +-- ffluci/index/example-action +-- ffluci/index/example-action/sp +-- ffluci/index/example-action/redir + +module(..., package.seeall) + +dispatcher = require("ffluci.dispatcher").action + +menu = { + descr = "Example Action", + order = 30, + entries = { + {action = "index", descr = "Action-Dispatcher Example"}, + {action = "sp", descr = "Simple View Template Stealing"}, + {action = "redir", descr = "Hello World Redirector"} + } +} + +function action_index() + require("ffluci.template").render("header") + local formvalue = require("ffluci.http").formvalue + + local x = formvalue("x", nil, true) + + print(x and "x*x: "..tostring(x*x) or "Set ?x= any number") + require("ffluci.template").render("footer") +end + +function action_sp() + require("ffluci.http") + require("ffluci.i18n") + require("ffluci.config") + require("ffluci.template") + + -- Try uncommenting the next line + -- ffluci.i18n.loadc("example-simpleview") + ffluci.template.render("example-simpleview/index") +end + +function action_redir() + require("ffluci.http").request_redirect("public", "index", "foobar") +end \ No newline at end of file diff --git a/examples/ffluci/controller/public/example-simpleview.lua b/examples/ffluci/controller/public/example-simpleview.lua new file mode 100644 index 000000000..61f4ad32c --- /dev/null +++ b/examples/ffluci/controller/public/example-simpleview.lua @@ -0,0 +1,27 @@ +-- This example demonstrates the simple view dispatcher which is the +-- most simple way to provide content as it directly renders the +-- associated template + +-- This example consists of: +-- ffluci/controller/index/example-simpleview.lua (this file) +-- ffluci/view/example-simpleview/index.htm (the template for action "index") +-- ffluci/view/example-simpleview/foo.htm (the template for action "foo") +-- ffluci/i18n/example-simpleview.de (the german language file for this module) + +-- Try the following address(es) in your browser: +-- ffluci/index/example-simpleview +-- ffluci/index/example-simpleview/index +-- ffluci/index/example-simpleview/foo + +module(..., package.seeall) + +dispatcher = require("ffluci.dispatcher").simpleview + +menu = { + descr = "Example Simpleview", + order = 20, + entries = { + {action = "index", descr = "Simpleview Index"}, + {action = "foo", descr = "Simpleview Foo"} + } +} \ No newline at end of file diff --git a/examples/ffluci/controller/public/index.lua b/examples/ffluci/controller/public/index.lua new file mode 100644 index 000000000..4498c77ed --- /dev/null +++ b/examples/ffluci/controller/public/index.lua @@ -0,0 +1,32 @@ +-- This is a very simple example Hello World FFLuCI controller +-- See the other examples for more automated controllers + +-- Initialise Lua module system +module(..., package.seeall) + +-- This is the module dispatcher. It implements the last step of the +-- dispatching process. +function dispatcher(request) + require("ffluci.template").render("header") + print("

Hello World!

") + for k,v in pairs(request) do + print("
" .. k .. ": " .. v .. "
") + end + require("ffluci.template").render("footer") +end + +-- The following part is optional it could be useful for menu generators +-- An example menu generator is implemented in the template "menu" + +menu = { + -- This is the menu item description + descr = "Hello World", + + -- This is the order level of the menu entry (lowest goes first) + order = 10, + + -- A list of menu entries in the form action => "description" + entries = { + {action = "index", descr = "Hello World"}, + } +} \ No newline at end of file diff --git a/examples/ffluci/view/example-simpleview/foo.htm b/examples/ffluci/view/example-simpleview/foo.htm new file mode 100755 index 000000000..a0df536f1 --- /dev/null +++ b/examples/ffluci/view/example-simpleview/foo.htm @@ -0,0 +1,3 @@ +<%+header%> +

bar

+<%+footer%> \ No newline at end of file diff --git a/examples/ffluci/view/example-simpleview/index.htm b/examples/ffluci/view/example-simpleview/index.htm new file mode 100755 index 000000000..ffe1ccf71 --- /dev/null +++ b/examples/ffluci/view/example-simpleview/index.htm @@ -0,0 +1,6 @@ +<%+header%> +

<%:descr This is the Simple View-Example.
+This template is ffluci/view/example-simpleview/index.htm and belongs +to the index-Action.%>

+

<%:lan The router's LAN IP-Address is:%> <%~network.lan.ipaddr%>

+<%+footer%> \ No newline at end of file diff --git a/examples/ffluci/view/hello.htm b/examples/ffluci/view/hello.htm new file mode 100644 index 000000000..8231b61f9 --- /dev/null +++ b/examples/ffluci/view/hello.htm @@ -0,0 +1 @@ +A very little Hello <%=muh%> diff --git a/src/ffluci/controller/admin/index.lua b/src/ffluci/controller/admin/index.lua deleted file mode 100644 index 9aec94c86..000000000 --- a/src/ffluci/controller/admin/index.lua +++ /dev/null @@ -1,15 +0,0 @@ -module(..., package.seeall) - -function dispatcher(request) - require("ffluci.template").render("header") - print("Hello there, Mr. Administrator") - require("ffluci.template").render("footer") -end - -menu = { - descr = "Administrative", - order = 10, - entries = { - {action = "index", descr = "Hello"} - } -} \ No newline at end of file diff --git a/src/ffluci/controller/public/example-action.lua b/src/ffluci/controller/public/example-action.lua deleted file mode 100644 index 538f5d9d0..000000000 --- a/src/ffluci/controller/public/example-action.lua +++ /dev/null @@ -1,49 +0,0 @@ --- This example demonstrates the action dispatcher which invokes --- an appropriate action function named action_"action" - --- This example consists of: --- ffluci/controller/index/example-action.lua (this file) - --- Try the following address(es) in your browser: --- ffluci/index/example-action --- ffluci/index/example-action/sp --- ffluci/index/example-action/redir - -module(..., package.seeall) - -dispatcher = require("ffluci.dispatcher").action - -menu = { - descr = "Example Action", - order = 30, - entries = { - {action = "index", descr = "Action-Dispatcher Example"}, - {action = "sp", descr = "Simple View Template Stealing"}, - {action = "redir", descr = "Hello World Redirector"} - } -} - -function action_index() - require("ffluci.template").render("header") - local formvalue = require("ffluci.http").formvalue - - local x = formvalue("x", nil, true) - - print(x and "x*x: "..tostring(x*x) or "Set ?x= any number") - require("ffluci.template").render("footer") -end - -function action_sp() - require("ffluci.http") - require("ffluci.i18n") - require("ffluci.config") - require("ffluci.template") - - -- Try uncommenting the next line - -- ffluci.i18n.loadc("example-simpleview") - ffluci.template.render("example-simpleview/index") -end - -function action_redir() - require("ffluci.http").request_redirect("public", "index", "foobar") -end \ No newline at end of file diff --git a/src/ffluci/controller/public/example-simpleview.lua b/src/ffluci/controller/public/example-simpleview.lua deleted file mode 100644 index 61f4ad32c..000000000 --- a/src/ffluci/controller/public/example-simpleview.lua +++ /dev/null @@ -1,27 +0,0 @@ --- This example demonstrates the simple view dispatcher which is the --- most simple way to provide content as it directly renders the --- associated template - --- This example consists of: --- ffluci/controller/index/example-simpleview.lua (this file) --- ffluci/view/example-simpleview/index.htm (the template for action "index") --- ffluci/view/example-simpleview/foo.htm (the template for action "foo") --- ffluci/i18n/example-simpleview.de (the german language file for this module) - --- Try the following address(es) in your browser: --- ffluci/index/example-simpleview --- ffluci/index/example-simpleview/index --- ffluci/index/example-simpleview/foo - -module(..., package.seeall) - -dispatcher = require("ffluci.dispatcher").simpleview - -menu = { - descr = "Example Simpleview", - order = 20, - entries = { - {action = "index", descr = "Simpleview Index"}, - {action = "foo", descr = "Simpleview Foo"} - } -} \ No newline at end of file diff --git a/src/ffluci/controller/public/index.lua b/src/ffluci/controller/public/index.lua deleted file mode 100644 index 4498c77ed..000000000 --- a/src/ffluci/controller/public/index.lua +++ /dev/null @@ -1,32 +0,0 @@ --- This is a very simple example Hello World FFLuCI controller --- See the other examples for more automated controllers - --- Initialise Lua module system -module(..., package.seeall) - --- This is the module dispatcher. It implements the last step of the --- dispatching process. -function dispatcher(request) - require("ffluci.template").render("header") - print("

Hello World!

") - for k,v in pairs(request) do - print("
" .. k .. ": " .. v .. "
") - end - require("ffluci.template").render("footer") -end - --- The following part is optional it could be useful for menu generators --- An example menu generator is implemented in the template "menu" - -menu = { - -- This is the menu item description - descr = "Hello World", - - -- This is the order level of the menu entry (lowest goes first) - order = 10, - - -- A list of menu entries in the form action => "description" - entries = { - {action = "index", descr = "Hello World"}, - } -} \ No newline at end of file diff --git a/src/ffluci/template.lua b/src/ffluci/template.lua index 8c7f07f94..3d6457169 100644 --- a/src/ffluci/template.lua +++ b/src/ffluci/template.lua @@ -39,7 +39,7 @@ viewdir = ffluci.fs.dirname(ffluci.util.__file__()) .. "view/" -- memory: Always compile, do not save compiled files, ignore precompiled -- always: Same as "memory" but also saves compiled files -- smart: Compile on demand, save compiled files, update precompiled -compiler_mode = "smart" +compiler_mode = "memory" -- This applies to compiler modes "always" and "smart" @@ -186,4 +186,4 @@ function render(name, scope) -- Now finally render the thing return view() -end \ No newline at end of file +end diff --git a/src/ffluci/view/example-simpleview/foo.htm b/src/ffluci/view/example-simpleview/foo.htm deleted file mode 100755 index a0df536f1..000000000 --- a/src/ffluci/view/example-simpleview/foo.htm +++ /dev/null @@ -1,3 +0,0 @@ -<%+header%> -

bar

-<%+footer%> \ No newline at end of file diff --git a/src/ffluci/view/example-simpleview/index.htm b/src/ffluci/view/example-simpleview/index.htm deleted file mode 100755 index ffe1ccf71..000000000 --- a/src/ffluci/view/example-simpleview/index.htm +++ /dev/null @@ -1,6 +0,0 @@ -<%+header%> -

<%:descr This is the Simple View-Example.
-This template is ffluci/view/example-simpleview/index.htm and belongs -to the index-Action.%>

-

<%:lan The router's LAN IP-Address is:%> <%~network.lan.ipaddr%>

-<%+footer%> \ No newline at end of file diff --git a/src/ffluci/view/footer.htm b/src/ffluci/view/footer.htm index 17c7245b6..c43cbb7e4 100644 --- a/src/ffluci/view/footer.htm +++ b/src/ffluci/view/footer.htm @@ -1,3 +1,7 @@ - + +
+ + +
FFLuCI 0.1 - Freifunk Lua Configuration Interface
\ No newline at end of file diff --git a/src/ffluci/view/header.htm b/src/ffluci/view/header.htm index f47388a42..2c0836be5 100644 --- a/src/ffluci/view/header.htm +++ b/src/ffluci/view/header.htm @@ -1,9 +1,56 @@ -<% require("ffluci.http").htmlheader() %> - +<% +local req = require("ffluci.dispatcher").request +local menu = require("ffluci.menu").get()[req.category] +require("ffluci.i18n").loadc("default") +require("ffluci.http").htmlheader() +%> + + -FFLuCI Examples + +FFLuCI -

FFLuCI

-<%+menu%> -
\ No newline at end of file + + + + +
+ + <% end %> +
+ +
diff --git a/src/ffluci/view/hello.htm b/src/ffluci/view/hello.htm deleted file mode 100644 index 8231b61f9..000000000 --- a/src/ffluci/view/hello.htm +++ /dev/null @@ -1 +0,0 @@ -A very little Hello <%=muh%> diff --git a/src/ffluci/view/menu.htm b/src/ffluci/view/menu.htm deleted file mode 100644 index 8d5c597cf..000000000 --- a/src/ffluci/view/menu.htm +++ /dev/null @@ -1,25 +0,0 @@ -<% -local req = require("ffluci.dispatcher").request -local menu = require("ffluci.menu").get()[req.category] -local menu_module = nil -require("ffluci.i18n").loadc("default") -%> -