annotate framework/env/slot/render_layout.lua @ 363:1d850c6688b6
New release of v2.0.2 because tar.gz file of v2.0.1 did not contain Makefile.options
 | author | jbe | 
 | date | Sun Mar 29 15:21:54 2015 +0200 (2015-03-29) | 
 | parents | be8ede894624 | 
 | children | d89813dd4d92 | 
 
 | 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@209 | 13         WEBMCP_BASE_PATH, | 
| jbe/bsw@0 | 14         'app', | 
| jbe@209 | 15         WEBMCP_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@282 | 21     local layout = assert(layout_file:read("*a")) | 
| jbe@282 | 22     assert(layout_file:close()) | 
| 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 |