webmcp
view framework/env/slot/render_layout.lua @ 3:795b764629ca
Version 1.0.3
Important bugfix related to internal forwards (Bug was introduced by the restriction of views with underscore prefix in Version 1.0.2)
Important bugfix related to internal forwards (Bug was introduced by the restriction of views with underscore prefix in Version 1.0.2)
| author | jbe |
|---|---|
| date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
| parents | 9fdfb27f8e67 |
| children | 2cb27106aa73 |
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 request.get_app_basepath(),
14 'app',
15 request.get_app_name(),
16 '_layout',
17 slot._current_layout .. '.html'
18 ),
19 'r'
20 ))
21 local layout = layout_file:read("*a")
22 io.close(layout_file)
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
