webmcp

annotate framework/env/slot/render_layout.lua @ 382:810c020b0da4

Reverted changes to mondelefant_result_index and mondelefant_result_newindex C-functions (proxying of JSON document)
author jbe
date Mon Nov 16 18:31:49 2015 +0100 (2015-11-16)
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

Impressum / About Us