Template:InsertDynamicCall

    Table of contents
    No headers
    /***
        USAGE: InsertDyanmicCall{ function: 'wiki.tree', args: [ 'App_Catalog', 1 ] }
            Embed a call to a function/template with substituted parameters.
    
        ARGUMENTS:
            function    name of function to call (can also be the name of a template); do not include brackets of any kind.
            args        (optional) either a list or map of arguments to apply to the function invocation
            style       (optional) can be one of 'pre' or 'img'; style to use for embedding call;
                            'pre' creates a readable section of dekiscript (e.g. <pre class='script'>)
                            'img' creates an image place holder with a hidden dekiscript code in the img attributes (e.g. <img src="..." function="(code)" />)
            image       (optional) image to use for 'img' style; by default, uses the Yahoo! widget image (64x64)
    
    ***/
    
    // read arguments
    var function = $function ?? $0;
    var args = $args ?? $1;
    var style = $style ?? $2;
    var image = $image ?? $3;
    
    // create function call using supplied arguments
    var code;
    if(args is map) {
        let code = function .. "{" .. string.join([ string.quote(name) .. " : " .. json.format(arg) foreach var name:arg in args ], ", ")  .. "}";
    } else if(args is list) {
        let code = function .. "(" .. string.join([ json.format(arg) foreach var arg in args ], ", ") .. ")";
    } else if(args is nil) {
        let code = function .. "()";
    } else {
    
        // invalid type for arguments
        let code = "ERROR: Specified argument type is not valid. Must be a map or a list.";
        let style = "error";
    }
    
    // embed function call using specified style
    switch(style) {
    default:
    case 'img':
        <img src=($image ?? "http://www.iconarchive.com/icons/deleket/sleek-xp-software/64/Yahoo-Widget-Engine-icon.png") function=(code .. "; var _dummy = $;") />
    case 'pre':
        <pre class="script"> code </pre>
    case 'error':
        <span style="warning"> code </span>
    }
    
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by