webmcp

diff framework/env/ui/script.lua @ 11:d76a8857ba62

Added ui.partial and other functions, which allow partial content replacement using XMLHttpRequests; Image support for ui.link

Also includes following changes:
- Fix for rocketcgi library to accept POST data content-types, which contain additional charset information.
- Support arrays passed as params to encode.url (only for keys ending with "[]")
- Version information changed to "1.0.7"

Documentation for added functions is not yet complete.
author jbe/bsw
date Fri Feb 12 18:40:22 2010 +0100 (2010-02-12)
parents e017c47d43b5
children
line diff
     1.1 --- a/framework/env/ui/script.lua	Wed Feb 03 00:57:18 2010 +0100
     1.2 +++ b/framework/env/ui/script.lua	Fri Feb 12 18:40:22 2010 +0100
     1.3 @@ -9,7 +9,7 @@
     1.4  
     1.5  This function is used to insert a script into the active slot.
     1.6  
     1.7 -WARNING: The given script MUST NOT include two closing square brackets directly followed by a greater-than sign, unless the output is interpreted strictly as XHTML. For string literals this is ensured automatically, if being encoded with encode.json{...}.
     1.8 +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.
     1.9  
    1.10  --]]--
    1.11  
    1.12 @@ -31,19 +31,21 @@
    1.13    if attr.src then
    1.14      ui.tag{ tag = "script", attr = attr, content = "" }
    1.15    elseif script then
    1.16 +    local script_string
    1.17 +    if type(script) == "function" then
    1.18 +      script_string = slot.use_temporary(script)
    1.19 +    else
    1.20 +      script_string = script
    1.21 +    end
    1.22 +    if string.find(script_string, "]]>") then
    1.23 +      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.')
    1.24 +    end
    1.25      ui.tag{
    1.26        tag  = "script",
    1.27        attr = attr,
    1.28        content = function()
    1.29          slot.put("/* <![CDATA[ */")
    1.30 -        local script_string
    1.31 -        if type(script) == "function" then
    1.32 -          script_string = slot.use_temporary(script)
    1.33 -        else
    1.34 -          script_string = script
    1.35 -        end
    1.36 -        -- Using double parenthesis in following command is important
    1.37 -        slot.put((string.gsub(script_string, "]]>", "]]]]><![CDATA[>")))
    1.38 +        slot.put(script_string)
    1.39          slot.put("/* ]]> */")
    1.40        end
    1.41      }

Impressum / About Us