Lasso Soft Inc. > Home

[CodeControl]

LinkCodeControl
AuthorMark Kawakami
CategoryOutput
Version8.x
LicensePublic Domain
Posted16 Jan 2006
Updated09 Feb 2006
More by this author...

Description

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)

Sample Usage

// instantiate codeControl object and the current 
// indent level to 2
var('cc') = codeControl(2); 

// output a new line, indented to current level
$cc->codeIndent();
'
    '; // output a new line, with an indent level increased by 1 $cc->addIndent(); '
  • '; $cc->addIndent(); // increase indent again '

    My List

    '; $cc->subIndent(); // decrease indent '
  • '; loop(5); $cc->codeIndent(); // output current indent level '
  • Item ' + loop_count + '
  • '; /loop; $cc->subIndent(); // decrease indent level '
';

Source Code

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;

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft