summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/acf_cli-controller.lua6
-rw-r--r--app/acf_www-controller.lua39
-rw-r--r--app/template-ajax.lsp6
-rw-r--r--app/template-html.lsp3
-rw-r--r--app/template-stream.lsp2
-rwxr-xr-xbin/acf-cli2
-rwxr-xr-xlua/mvc.lua24
7 files changed, 35 insertions, 47 deletions
diff --git a/app/acf_cli-controller.lua b/app/acf_cli-controller.lua
index f3b7d6f..e68dfe9 100644
--- a/app/acf_cli-controller.lua
+++ b/app/acf_cli-controller.lua
@@ -30,12 +30,6 @@ end
mvc.post_exec = function ()
end
-view_resolver = function(self)
- return function (viewtable)
- print(session.serialize("result", viewtable))
- end
-end
-
exception_handler = function (self, message )
print(session.serialize("exception", message))
parent_exception_handler(self, message)
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index b4f8e91..462a226 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -14,6 +14,7 @@ require "posix"
-- We use the parent exception handler in a last-case situation
local parent_exception_handler
local parent_create_helper_library
+local parent_view_resolver
local function build_menus(self)
m=require("menubuilder")
@@ -171,44 +172,27 @@ end
-- Our local view resolver called by our dispatch - add the template and skin
view_resolver = function(self)
- local template, viewname, viewlibrary
- local viewtype = self.conf.viewtype or "html"
+ self.conf.viewtype = self.conf.viewtype or "html"
+ local viewfunc, viewlibrary, pageinfo = parent_view_resolver(self)
+ pageinfo.viewfunc = viewfunc
-- search for template
+ local template
if self.conf.component ~= true then
template = find_template ( self.conf.appdir, self.conf.prefix,
- self.conf.controller, self.conf.action, viewtype )
+ self.conf.controller, self.conf.action, self.conf.viewtype )
end
-
- -- search for view
- viewname = find_view ( self.conf.appdir, self.conf.prefix,
- self.conf.controller, self.conf.action, viewtype )
- local func = function() end
+ local func = viewfunc
if template then
- -- We have a template
+ -- We have a template, use it as the function
func = haserl.loadfile (template)
- elseif viewname then
- -- No template, but have a view
- func = haserl.loadfile (viewname)
end
-
- -- create the view helper library
- viewlibrary = self:create_helper_library()
-
- local pageinfo = { viewfile = viewname,
- controller = self.conf.controller,
- action = self.conf.action,
- prefix = self.conf.prefix,
- script = self.conf.script,
- wwwprefix = self.conf.wwwprefix or "",
- staticdir = self.conf.staticdir or "",
- skin = self.conf.skin or "",
- orig_action = self.conf.orig_action or self.conf.prefix .. self.conf.controller .. "/" .. self.conf.action,
- clientdata = self.clientdata,
- }
+
if self.sessiondata.userinfo and self.sessiondata.userinfo.skin and self.sessiondata.userinfo.skin ~= "" then
pageinfo.skin = self.sessiondata.userinfo.skin
+ else
+ pageinfo.skin = self.conf.skin or ""
end
return func, viewlibrary, pageinfo, self.sessiondata
@@ -235,6 +219,7 @@ mvc.on_load = function (self, parent)
parent_exception_handler = parent.exception_handler
parent_create_helper_library = parent.create_helper_library
+ parent_view_resolver = parent.view_resolver
sessionlib=require ("session")
diff --git a/app/template-ajax.lsp b/app/template-ajax.lsp
index 96e6378..bb7fc9f 100644
--- a/app/template-ajax.lsp
+++ b/app/template-ajax.lsp
@@ -1,8 +1,6 @@
-<% local view, viewlibrary, page_info = ... %>
+<% local view, viewlibrary, page_info, session = ... %>
<% require("json") %>
Status: 200 OK
Content-Type: "application/json"
<% io.write("\n") %>
-<%
- print(json.encode(view))
-%>
+<% page_info.viewfunc(view, viewlibrary, page_info, session) %>
diff --git a/app/template-html.lsp b/app/template-html.lsp
index a37a31e..81043b6 100644
--- a/app/template-html.lsp
+++ b/app/template-html.lsp
@@ -131,8 +131,7 @@ end
<div class="leader">
</div>
- <% local func = haserl.loadfile(pageinfo.viewfile) %>
- <% func (viewtable, viewlibrary, pageinfo, session) %>
+ <% pageinfo.viewfunc(viewtable, viewlibrary, pageinfo, session) %>
<div class="tailer">
</div>
diff --git a/app/template-stream.lsp b/app/template-stream.lsp
index e8a6e68..17693af 100644
--- a/app/template-stream.lsp
+++ b/app/template-stream.lsp
@@ -9,4 +9,4 @@ Content-Length: <%= viewtable.length %>
Content-Disposition: attachment; filename="<%= viewtable.label %>"
<% end %>
<% io.write("\n") %>
-<%= viewtable.value %>
+<% pageinfo.viewfunc(viewtable, viewlibrary, pageinfo, session) %>
diff --git a/bin/acf-cli b/bin/acf-cli
index d2f7006..1c2fe6a 100755
--- a/bin/acf-cli
+++ b/bin/acf-cli
@@ -30,7 +30,7 @@ APP=FRAMEWORK:new("acf_cli")
local p,c,a = APP.parse_path_info(arg[1])
local clientdata = {}
for i=2,#arg do
- a,v = string.match(arg[i], "([^=]*)=(.*)")
+ local a,v = string.match(arg[i], "([^=]*)=(.*)")
if v then
clientdata[a] = v
else
diff --git a/lua/mvc.lua b/lua/mvc.lua
index bd69051..731f297 100755
--- a/lua/mvc.lua
+++ b/lua/mvc.lua
@@ -127,7 +127,6 @@ end
dispatch = function (self, userprefix, userctlr, useraction, clientdata)
local controller = nil
local success, err = xpcall ( function ()
-
self.conf.prefix = userprefix or "/"
self.conf.controller = userctlr or ""
self.conf.action = useraction or ""
@@ -336,7 +335,19 @@ create_helper_library = function ( self )
end
-- The view of last resort
-auto_view = function()
+auto_view = function(viewtable, viewlibrary, pageinfo, session)
+ if pageinfo.viewtype == "html" then
+ require("htmlviewfunctions")
+ htmlviewfunctions.displayitem(viewtable, 1, pageinfo)
+ elseif pageinfo.viewtype == "ajax" then
+ require("json")
+ print(json.encode(viewtable))
+ elseif pageinfo.viewtype == "stream" then
+ print(tostring(viewtable.value))
+ elseif pageinfo.viewtype == "serialized" then
+ local s = require("session")
+ print(s.serialize("result", viewtable))
+ end
end
-- The view resolver of last resort.
@@ -344,18 +355,19 @@ view_resolver = function(self)
local viewname, viewlibrary
-- search for view
- viewname = find_view ( self.conf.appdir, self.conf.prefix,
+ viewname = self.find_view ( self.conf.appdir, self.conf.prefix,
self.conf.controller, self.conf.action, self.conf.viewtype )
- local func = auto_view
+ local func = self.auto_view
if viewname then
func = haserl.loadfile (viewname)
end
-- create the view helper library
- viewlibrary = create_helper_library ( self )
+ viewlibrary = self:create_helper_library()
local pageinfo = { viewfile = viewname,
+ viewtype = self.conf.viewtype,
controller = self.conf.controller,
action = self.conf.action,
prefix = self.conf.prefix,
@@ -365,7 +377,7 @@ view_resolver = function(self)
orig_action = self.conf.orig_action or self.conf.prefix .. self.conf.controller .. "/" .. self.conf.action,
clientdata = self.clientdata,
}
-
+
return func, viewlibrary, pageinfo, self.sessiondata
end