Page Blocks

Hosting sponsored by:

Point In Space

 

API: Cnfg

Filename:
fwpCnfg_loadLines.ctag

Released With:
5.0.0

Current Version:
1.3.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwpCnfg_loadLines (Tag)

Description

Loads a configuration file which is structured with each line being a separate configuration item be it a single value, pair, or delimited multi-value line. The line format is irrelevent as the only important fact is that your application code will utilize each line individually. Line endings are normalized, comment lines are removed, and the data is split to become a Lasso array.

The tag searches the /site/configs/ folder and the current /_resources/configs/ folder. The tag can be instructed to merge or not merge files if one is found in both folders. Alternately, a full file pathname can be given to load a specific file not in the usual /configs/ folder.

This tag is essentially a macro for the sequence of tags fwpCnfg_loadFile, fwpCnfg_splitLines, and fwpCnfg_deComment. The end result is an array of config file lines with the comment lines already removed so the data can be used with a simple iterate without the need for the application code to test for comment lines.

Comments in the configuration lines can begin with # or //, empty lines are allowed, and the Lasso container [output_none]...[/output_none] can wrap the file contents. All of these non-data lines will be removed.

Syntax

var|local:varName = fwpCnfg_loadLines: fileName, -withoutCaching, -removeWhiteSpace;

Configuration file format:

[output_none]
# comments like this
// or like this
# blank lines allowed too

# format of each line is open to whatever you need

colors:::red, blue, yellow, green
shapes:::circle, square, triangle

code=# other stuff
pageName.lasso---params:a,b,c
[/output_none]

Parameters & Member Tags

file (unnamed) = required : either a complete filename with extension or a full pathname. If a file name is specified without any path component, the tag will search the /site/configs/ folder and the current /_resources/configs/ folder. If a file with a path is specified, the complete virtual host root relative path must be specified, and the tag will load that one specific file.

-withoutMerging = optional : if not specified, the default behavior is to append a file found in the /_resources/configs/ folder to the end of a file found in the /site/configs/ folder. If -withoutMerging is used, and a file is found in both folders, only the contents of the file from the /_resources/configs/ folder will be loaded. (Previous -nomerge param name is deprecated)

-removeWhiteSpace = optional : if specified, removes all spaces and tabs from each line. (Previous -despace param name is deprecated)

Examples

var:'myCnfgData' = fwpCnfg_loadLines:'custom.cnfg';

var:'myCnfgData' = fwpCnfg_loadLines:'custom.cnfg', -withoutMerging;

var:'myCnfgData' = fwpCnfg_loadLines:'custom.cnfg', -removeWhiteSpace;

var:'myCnfgData' = fwpCnfg_loadLines:'/nonstandard/config/path/custom.cnfg';

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpCnfg_loadLines.ctag }
    {rsrcType=        tag }
    {rsrcName=        fwpCnfg_loadLines }
    {rsrcHTTP=        www.pageblocks.org/refc/fwpCnfg_loadLines }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            This tag loads a configuration file,
                    removes comment lines, and 
                    splits the lined into an array }

    {maintvsrn=        1.3.0 }
    {maintrelease=    5.2.0 }
    {maintdate=        2007-06-09}
    {maintauthor=    Greg Willits }
    {maintnotes=    updated debug and error handling systems,
                     changed some internal vars for better readability }

    {maintvsrn=        1.2.0 }
    {maintrelease=    5.1.0 }
    {maintdate=        2006-05-30}
    {maintauthor=    Greg Willits }
    {maintnotes=    added tagTrace }

    {maintvsrn=        1.1 }
    {maintrelease=    5.0.0 b5 }
    {maintdate=        2006-01-27 }
    {maintauthor=    Greg Willits }
    {maintnotes=    changed some styntax for efficiency,
                    added -despace option,
                    eliminated code used by old RAMbucket caching }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release }

*/
//.............................................................................

define_tag:'fwpCnfg_loadLines', -priority='replace',
    -required='file',
    -optional='username',
    -optional='password';

//    -removeWhiteSpace (-despace deprecated) 
//    -withoutCaching (-nocache deprecated)

    ($fw_debug >= fw_kChatty) ? $fw_tagTracer->(add:'fwpCnfg_loadLines');

    local:
        'fileName'             = @#file,
        'withoutCaching'     = false,
        'removeWhiteSpace'    = false,
        'configData'         = string;

//    pull from cache if available
//    else pull from disk (and store to cache)

    #configData = $fw_gConfigCache->(restore:#fileName);

    if: #configData->size > 0;

        // pulled from cache, so we're done

    else;
    
//    load file data

        (params->find:'-withoutCaching') || (params->find:'-nocache')
            ? #withoutCaching = true;

        (params->find:'-removeWhiteSpace') || (params->find:'-despace')
            ? #removeWhiteSpace = true;

        #configData = (fwpCnfg_loadFile:
            -file        = #fileName,
            -username     = local:'username',
            -password     = local:'password');

//    remove whitespace

        if: #removeWhiteSpace;
            #configData->(replace:' ', '');
            #configData->(replace:'\t', '');
        /if;

//    convert to array so we can remove comments

        #configData = (fwpCnfg_splitLines: #configData);
        #configData = (fwpCnfg_deComment: #configData);
        
//    cache or not?
//    cached as an array

        !#withoutCaching
            ? $fw_gConfigCache->(add:
                -name  = #fileName,
                -value = #configData);
    /if;

    return: #configData;

/define_tag;
?>

© 2002-2012, pageblocks.org