webmcp

annotate framework/env/ui/script.lua @ 23:3a6fe8663b26

Code cleanup and documentation added; Year in copyright notice changed to 2009-2010

Details:
- Changed quoting style in auth.openid.xrds_document{...}
- Fixed documentation for auth.openid.initiate{...}
- Added documentation for mondelefant
- Code-cleanup in mondelefant:
-- removed unneccessary lines "rows = PQntuples(res); cols = PQnfields(res);"
-- avoided extra copy of first argument (self) in mondelefant_conn_query
-- no rawget in meta-method "__index" of database result lists and objects
-- removed unreachable "return 0;" in meta-method "__newindex" of database result lists and objects
- Year in copyright notice changed to 2009-2010
- Version string changed to "1.1.1"
author jbe
date Fri Jun 04 19:00:34 2010 +0200 (2010-06-04)
parents d76a8857ba62
children
rev   line source
jbe/bsw@0 1 --[[--
jbe/bsw@0 2 ui.script{
jbe/bsw@0 3 noscript_attr = noscript_attr, -- HTML attributes for noscript tag
jbe/bsw@0 4 noscript = noscript, -- string or function for noscript content
jbe/bsw@0 5 attr = attr, -- extra HTML attributes for script tag
jbe/bsw@0 6 type = type, -- type of script, defaults to "text/javascript"
jbe/bsw@0 7 script = script, -- string or function for script content
jbe/bsw@0 8 }
jbe/bsw@0 9
jbe/bsw@9 10 This function is used to insert a script into the active slot.
jbe/bsw@0 11
jbe/bsw@11 12 WARNING: If the script contains two closing square brackets directly followed by a greater-than sign, it will be rejected to avoid ambiguity related to HTML vs. XML parsing. Additional space characters can be added within the program code to avoid occurrence of the character sequence. The function encode.json{...} encodes all string literals in a way that the sequence is not contained.
jbe@10 13
jbe/bsw@0 14 --]]--
jbe/bsw@0 15
jbe/bsw@0 16 function ui.script(args)
jbe/bsw@0 17 local args = args or {}
jbe/bsw@0 18 local noscript_attr = args.noscript_attr
jbe/bsw@0 19 local noscript = args.noscript
jbe/bsw@0 20 local attr = table.new(args.attr)
jbe/bsw@0 21 attr.type = attr.type or args.type or "text/javascript"
jbe/bsw@0 22 local script = args.script
jbe/bsw@4 23 if args.external then
jbe/bsw@4 24 attr.src = encode.url{ external = args.external }
jbe/bsw@4 25 elseif args.static then
jbe/bsw@4 26 attr.src = encode.url{ static = args.static }
jbe/bsw@4 27 end
jbe/bsw@0 28 if noscript then
jbe/bsw@0 29 ui.tag{ tag = "noscript", attr = attr, content = noscript }
jbe/bsw@0 30 end
jbe/bsw@4 31 if attr.src then
jbe/bsw@4 32 ui.tag{ tag = "script", attr = attr, content = "" }
jbe/bsw@4 33 elseif script then
jbe/bsw@11 34 local script_string
jbe/bsw@11 35 if type(script) == "function" then
jbe/bsw@11 36 script_string = slot.use_temporary(script)
jbe/bsw@11 37 else
jbe/bsw@11 38 script_string = script
jbe/bsw@11 39 end
jbe/bsw@11 40 if string.find(script_string, "]]>") then
jbe/bsw@11 41 error('Script contains character sequence "]]>" and is thus rejected to avoid ambiguity. If this sequence occurs as part of program code, please add additional space characters. If this sequence occurs inside a string literal, please encode one of this characters using the \\uNNNN unicode escape sequence.')
jbe/bsw@11 42 end
jbe/bsw@9 43 ui.tag{
jbe/bsw@9 44 tag = "script",
jbe/bsw@9 45 attr = attr,
jbe/bsw@9 46 content = function()
jbe/bsw@9 47 slot.put("/* <![CDATA[ */")
jbe/bsw@11 48 slot.put(script_string)
jbe/bsw@9 49 slot.put("/* ]]> */")
jbe/bsw@9 50 end
jbe/bsw@9 51 }
jbe/bsw@0 52 end
jbe/bsw@0 53 end

Impressum / About Us