[CodeControl]

Description

Link: [CodeControl]
Author: Mark Kawakami
Category: Output
Version: 8.x
License: Public Domain
Posted: Jan. 16, 2006
Updated: Feb. 09, 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)

Parameters

none


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();
'<ul>';

// output a new line, with an indent level increased by 1
$cc->addIndent();
'<li>';
$cc->addIndent(); // increase indent again
'<h2>My List</h2>';
$cc->subIndent(); // decrease indent
'</li>';

loop(5);
$cc->codeIndent(); // output current indent level
'<li>Item ' + loop_count + '</li>';
/loop;

$cc->subIndent(); // decrease indent level
'</ul>';
						

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net