jbe/bsw@0: --[[-- jbe/bsw@0: output = -- document/data to be sent to the web browser jbe/bsw@0: slot.render_layout() jbe/bsw@0: jbe/bsw@0: 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: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function slot.render_layout() jbe/bsw@0: if slot._current_layout then jbe/bsw@0: local layout_file = assert(io.open( jbe/bsw@0: encode.file_path( jbe@209: WEBMCP_BASE_PATH, jbe/bsw@0: 'app', jbe@209: WEBMCP_APP_NAME, jbe/bsw@0: '_layout', jbe/bsw@0: slot._current_layout .. '.html' jbe/bsw@0: ), jbe/bsw@0: 'r' jbe/bsw@0: )) jbe@282: local layout = assert(layout_file:read("*a")) jbe@282: assert(layout_file:close()) jbe/bsw@0: jbe/bsw@0: -- render layout jbe/bsw@0: layout = string.gsub(layout, "__BASEURL__/?", request.get_relative_baseurl()) -- TODO: find a better placeholder than __BASEURL__ ? jbe/bsw@0: layout = string.gsub(layout, '', jbe/bsw@0: function(slot_ident) jbe/bsw@0: if #slot.get_content(slot_ident) > 0 then jbe/bsw@0: return '
' .. slot.get_content(slot_ident).. '
' jbe/bsw@0: else jbe/bsw@0: return '' jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: ) jbe/bsw@0: layout = string.gsub(layout, '', jbe/bsw@0: function(slot_ident) jbe/bsw@0: if #slot.get_content(slot_ident) > 0 then jbe/bsw@0: return slot.get_content(slot_ident) jbe/bsw@0: else jbe/bsw@0: return '' jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: ) jbe/bsw@0: return layout jbe/bsw@0: else jbe/bsw@0: return slot.get_content("data") jbe/bsw@0: end jbe/bsw@0: end