summaryrefslogtreecommitdiffhomepage
path: root/src/ffluci/controller
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2008-03-02 21:52:58 +0000
committerJo-Philipp Wich <jow@openwrt.org>2008-03-02 21:52:58 +0000
commit3f5de3273c9e103b4909802e339db06fe0b53312 (patch)
tree793ef66c9456665f7b472e214d79b1078fccebe8 /src/ffluci/controller
* new project: ff-luci - Freifunk Lua Configuration Interface
Diffstat (limited to 'src/ffluci/controller')
-rw-r--r--src/ffluci/controller/admin/index.lua15
-rw-r--r--src/ffluci/controller/public/example-action.lua49
-rw-r--r--src/ffluci/controller/public/example-simpleview.lua27
-rw-r--r--src/ffluci/controller/public/index.lua32
4 files changed, 123 insertions, 0 deletions
diff --git a/src/ffluci/controller/admin/index.lua b/src/ffluci/controller/admin/index.lua
new file mode 100644
index 0000000000..9aec94c867
--- /dev/null
+++ b/src/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/src/ffluci/controller/public/example-action.lua b/src/ffluci/controller/public/example-action.lua
new file mode 100644
index 0000000000..538f5d9d05
--- /dev/null
+++ b/src/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/src/ffluci/controller/public/example-simpleview.lua b/src/ffluci/controller/public/example-simpleview.lua
new file mode 100644
index 0000000000..61f4ad32cd
--- /dev/null
+++ b/src/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/src/ffluci/controller/public/index.lua b/src/ffluci/controller/public/index.lua
new file mode 100644
index 0000000000..4498c77edf
--- /dev/null
+++ b/src/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("<h2>Hello World!</h2>")
+ for k,v in pairs(request) do
+ print("<div>" .. k .. ": " .. v .. "</div>")
+ 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