webmcp

view framework/env/slot/render_layout.lua @ 382:810c020b0da4

Reverted changes to mondelefant_result_index and mondelefant_result_newindex C-functions (proxying of JSON document)
author jbe
date Mon Nov 16 18:31:49 2015 +0100 (2015-11-16)
parents be8ede894624
children d89813dd4d92
line source
1 --[[--
2 output = -- document/data to be sent to the web browser
3 slot.render_layout()
5 This function returns the selected layout after replacing all slot placeholders with the respective slot contents. If slot.set_layout(...) was called with nil as first argument, then no layout will be used, but only the contents of the slot named "data" are returned.
7 --]]--
9 function slot.render_layout()
10 if slot._current_layout then
11 local layout_file = assert(io.open(
12 encode.file_path(
13 WEBMCP_BASE_PATH,
14 'app',
15 WEBMCP_APP_NAME,
16 '_layout',
17 slot._current_layout .. '.html'
18 ),
19 'r'
20 ))
21 local layout = assert(layout_file:read("*a"))
22 assert(layout_file:close())
24 -- render layout
25 layout = string.gsub(layout, "__BASEURL__/?", request.get_relative_baseurl()) -- TODO: find a better placeholder than __BASEURL__ ?
26 layout = string.gsub(layout, '<!%-%- *WEBMCP +SLOT +([^ ]+) *%-%->',
27 function(slot_ident)
28 if #slot.get_content(slot_ident) > 0 then
29 return '<div class="slot_' .. slot_ident .. '" id="slot_' .. slot_ident .. '">' .. slot.get_content(slot_ident).. '</div>'
30 else
31 return ''
32 end
33 end
34 )
35 layout = string.gsub(layout, '<!%-%- *WEBMCP +SLOTNODIV +([^ ]+) *%-%->',
36 function(slot_ident)
37 if #slot.get_content(slot_ident) > 0 then
38 return slot.get_content(slot_ident)
39 else
40 return ''
41 end
42 end
43 )
44 return layout
45 else
46 return slot.get_content("data")
47 end
48 end

Impressum / About Us