jbe/bsw@0: --[[-- jbe@497: output = -- document/data to be sent to the web browser jbe@497: slot.render_layout( jbe@497: layout_ident -- if set, selects layout to be used; otherwise layout set by slot.set_layout(...) is used jbe@497: ) 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@497: function slot.render_layout(layout_ident) jbe@497: local layout_ident = layout_ident or slot._current_layout jbe@497: if layout_ident 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@497: layout_ident .. '.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