webmcp
annotate framework/env/slot/render_layout.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
author | jbe/bsw |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
parents | 9fdfb27f8e67 |
children | 2cb27106aa73 |
rev | line source |
---|---|
jbe/bsw@0 | 1 --[[-- |
jbe/bsw@0 | 2 output = -- document/data to be sent to the web browser |
jbe/bsw@0 | 3 slot.render_layout() |
jbe/bsw@0 | 4 |
jbe/bsw@0 | 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. |
jbe/bsw@0 | 6 |
jbe/bsw@0 | 7 --]]-- |
jbe/bsw@0 | 8 |
jbe/bsw@0 | 9 function slot.render_layout() |
jbe/bsw@0 | 10 if slot._current_layout then |
jbe/bsw@0 | 11 local layout_file = assert(io.open( |
jbe/bsw@0 | 12 encode.file_path( |
jbe/bsw@0 | 13 request.get_app_basepath(), |
jbe/bsw@0 | 14 'app', |
jbe/bsw@0 | 15 request.get_app_name(), |
jbe/bsw@0 | 16 '_layout', |
jbe/bsw@0 | 17 slot._current_layout .. '.html' |
jbe/bsw@0 | 18 ), |
jbe/bsw@0 | 19 'r' |
jbe/bsw@0 | 20 )) |
jbe/bsw@0 | 21 local layout = layout_file:read("*a") |
jbe/bsw@0 | 22 io.close(layout_file) |
jbe/bsw@0 | 23 |
jbe/bsw@0 | 24 -- render layout |
jbe/bsw@0 | 25 layout = string.gsub(layout, "__BASEURL__/?", request.get_relative_baseurl()) -- TODO: find a better placeholder than __BASEURL__ ? |
jbe/bsw@0 | 26 layout = string.gsub(layout, '<!%-%- *WEBMCP +SLOT +([^ ]+) *%-%->', |
jbe/bsw@0 | 27 function(slot_ident) |
jbe/bsw@0 | 28 if #slot.get_content(slot_ident) > 0 then |
jbe/bsw@0 | 29 return '<div class="slot_' .. slot_ident .. '" id="slot_' .. slot_ident .. '">' .. slot.get_content(slot_ident).. '</div>' |
jbe/bsw@0 | 30 else |
jbe/bsw@0 | 31 return '' |
jbe/bsw@0 | 32 end |
jbe/bsw@0 | 33 end |
jbe/bsw@0 | 34 ) |
jbe/bsw@0 | 35 layout = string.gsub(layout, '<!%-%- *WEBMCP +SLOTNODIV +([^ ]+) *%-%->', |
jbe/bsw@0 | 36 function(slot_ident) |
jbe/bsw@0 | 37 if #slot.get_content(slot_ident) > 0 then |
jbe/bsw@0 | 38 return slot.get_content(slot_ident) |
jbe/bsw@0 | 39 else |
jbe/bsw@0 | 40 return '' |
jbe/bsw@0 | 41 end |
jbe/bsw@0 | 42 end |
jbe/bsw@0 | 43 ) |
jbe/bsw@0 | 44 return layout |
jbe/bsw@0 | 45 else |
jbe/bsw@0 | 46 return slot.get_content("data") |
jbe/bsw@0 | 47 end |
jbe/bsw@0 | 48 end |