Was this page helpful?

Web.Text

    Table of contents
    1. 1. Usage Restrictions
    2. 2. Parameters
    3. 3. Result
    4. 4. Samples
    web.Text(source : str, xpath : str, namespaces : map, xml : bool, ttl: num) : str
    

    Convert source to text by optionally fetching and parsing it.

    Usage Restrictions

    1.9.0 or later

    Parameters

    Name Type Description
    source str source text or source uri
    xpath str (optional, default: none) xpath to value.
    namespaces map (optional, default: none) XML namespace definitions  (1.9.0b or later)
    xml bool (optional, default: false) capture enclosing XML element (1.9.1 or later)
    ttl num (optional, range: 60 - 86400, default: 300) Caching durations in seconds (8.08 or later)

    Result

    The result of web.text depends on the combination of arguments provided.  If source is not a URI and xpath is omitted, web.text simply returns source as its result.  If source is not a URI and xpath is provided, then web.text behaves like xml.text by parsing source as an XML document and applying the xpath expression (see xpath note below). If source is a URI and xpath is omitted, then web.text fetches the data from the URI as text and returns it.  If source is a URI and xpath is provided, then web.text fetches the data from the URI as an XML document and applies the xpath expression.

    When applying the xpath expression, web.text returns only the contents of the text nodes that are immediate children of the first XML node matched by the xpath expression.  If the first matched XML node is an XML attribute, the value of the attribute is returned instead.  If the xml argument is set to true, web.text returns the entire XML node rendered as text.

    NOTE: all web.* functions are limited to reading at most 500KB of data from a URI.

    Samples

      Output

    To insert an html list as text:

    {{ web.Text("<ul><li>item 1</li><li>item 2</li></ul>") }} 

    <ul><li>item 1</li><li>item 2</li></ul>

    To extract the current user's nickname:

    {{ web.Text(user.api, "/user/nick") }}

    To display the formatted contents of an XML file:

    {{ syntax.xml(web.text("http://scripts.mindtouch.com/scratch.xml")) }}

    <extension>
      <title>Scratch Extension</title>
      <label>Scratch</label>
      <copyright>Copyright (c) 2006-2010 MindTouch Inc.</copyright>
      <description>This extension contains functions for embedding Scratch applications.</description>
      <uri.help>http://developer.mindtouch.com/App_Catalog/Scratch</uri.help>
      <uri.logo>http://scripts.mindtouch.com/logos/scratch-logo.png</uri.logo>
    
      <function>
        <name>scratch</name>
        <description>Embed a Scratch application.</description>
        <param name="id" type="str">Application User/ID.</param>
        <param name="width" type="num" optional="true">Application width. (default: 482)</param>
        <param name="height" type="num" optional="true">Application height. (default: 387)</param>
        <return>
          <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
            <body>
              <applet id="ProjectApplet" style="display:block" code="ScratchApplet" codebase="http://scratch.mit.edu/static/misc" archive="ScratchApplet.jar" eval:width="web.size(args.width ?? 482)" eval:height="web.size(args.height ?? 387)">
                <param name="project" eval:value="'../../static/projects/' .. args.id .. '.sb'" />
              </applet>
              <a eval:href="'http://scratch.mit.edu/projects/' .. args.id">Learn more about this project</a>
            </body>
          </html>
        </return>
      </function>
    </extension>

     

     

    Was this page helpful?
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by