Link | CodeControl |
Author | Mark Kawakami |
Category | Output |
Version | 8.x |
License | Public Domain |
Posted | 16 Jan 2006 |
Updated | 09 Feb 2006 |
More by this author... |
This class eases outputting readable HTML (and XML) code from LassoScript. Ordinarily, getting nicely formatted indents in HTML from Lassoscript involves a lot of extraneous output clutter in your lassoScript code. With CodeControl, all the line feeds and indenting are handled with a few simple commands to one object. Incidentally, the line-breaks generated by this are the backslash-r character (character 13, I believe), which may or may not properly break lines depending on OS. So if anyone wants to offer up some more comprehensive code for determining line-break character, go right ahead (though in all fairness, we work in a mixed environment and have not hand trouble with these tags)
// instantiate codeControl object and the current // indent level to 2 var('cc') = codeControl(2); // output a new line, indented to current level $cc->codeIndent(); '
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_type('codeControl', -priority='replace', -description='Generic utility object for formatting code indenting in a structured manner.' ); local:'baseIndent' = 0; local:'curIndent' = 0; local:'spacer' = '\t'; define_tag('onCreate', -optional='indent', -type='integer', -description='Constructor accepts an integer parameter, which specifies the minimum indent level. All indent string will be at least baseLevel * spacer long' ); if(local_defined('indent')); self->'baseIndent' = #indent; /if; /define_tag; define_tag('incrementIndent', -optional='indent', -type='integer', -description='Adds #indent (or 1 if not specified) to the curIndent property' ); local:'addTo' = (local_defined('indent') ? #indent | 1); self->'curIndent' += #addTo; /define_tag; define_tag('decrementIndent', -optional='indent', -type='integer', -description='Subtracts #indent (or 1 if not specified) from the curIndent property unless self->curIndent <= 0' ); local:'subTo' = (local_defined('indent') ? #indent | 1); local:'newIndent' = (self->'curIndent') - integer(#subTo); self->'curIndent' = (#newIndent > 0 ? #newIndent | 0); /define_tag; define_tag('setIndent', -required='indent', -type='integer', -description='Sets the indent level to the integer specified' ); self->'curIndent' = math_abs(#indent); /define_tag; define_tag('addIndent', -description='calls incrementIndent and codeIndent in succession, which increments the indent level and returns a formatted string' ); self->incrementIndent; return(self->codeIndent); /define_tag; define_tag('subIndent', -description='calls decrementIndent and codeIndent in succession, which decrements the indent level and returns a formatted string' ); self->decrementIndent; return(self->codeIndent); /define_tag; define_tag('codeIndent', -optional='indent', -type='integer', -returnType='string', -description='returns a string which is (baseLevel + curIndent) * spacer. Optional indent parameter sets the curIndent level.' ); if(local_defined('indent')); self->'curIndent' = math_abs(#indent); /if; local:'ret' = '\r'; local:'indAmt' = (self->'curIndent') + (self->'baseIndent'); #ret += ((self->'spacer') * #indAmt); return(#ret); /define_tag; /define_type;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft