-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEMPLATE_MANUAL.html
More file actions
1043 lines (751 loc) · 40.4 KB
/
Copy pathTEMPLATE_MANUAL.html
File metadata and controls
1043 lines (751 loc) · 40.4 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>LtdTemplate Manual</title>
<style type='text/css'>
table { border-collapse: collapse }
tr { border: solid 1px black }
td, th { padding-left: 1.5em; padding-right: 0.3em }
td:first-child, th:first-child { padding-left: 0.3em }
</style>
</head>
<body>
<h1 id='top'>LtdTemplate Manual<br>
<span style='font-size: smaller'>Version 1.0.0; 2014-05-07</span></h1>
<h2>Author(s)</h2>
<ul>
<li>Brian Katzung
<<a href='mailto:briank@kappacs.com'>briank@kappacs.com</a>>,
Kappa Computer Solutions, LLC (original author)</li>
</ul>
<h2 id='contents'>Contents</h2>
<ul>
<li><a href='#introduction'>Introduction</a></li>
<li><a href='#template_syntax'>Template Syntax</a></li>
<li><a href='#code_syntax'>Template Code Syntax</a></li>
<li><a href='#values_methods'>Values And Methods</a></li>
<li><a href='#examples'>(Some More) Examples</a></li>
</ul>
<h2 id='introduction'>Introduction</h2>
<p><a href='http://rubygems.org/gems/ltdtemplate'>LtdTemplate</a> is a
<a href='http://rugybems.org/'>Ruby Gem</a> implementing resource-limitable,
user-editable, textual templating.</p>
<p>Note that "user-editable" does not particularly refer to simplicity
(understanding most templates will be facilitated by having a programming
background), but rather that, with proper configuration, it can be used to
allow sophisticated users to edit their own templates (e.g. for message
localization) with limited risk of infinite execution loops or recursion,
excessively long strings, or other uncontrolled resource utilization.</p>
<p>This document describes the template syntax. See the Gem documentation
for information about the programming interface.</p>
<p>[<a href='#contents'>Contents</a>]</p>
<h2 id='template_syntax'>Template Syntax</h2>
<p>A template consists of inter-mixed sections of literal text and
template code. The shortest sequences between "<code><<</code>"
and "<code>>></code>" that don't contain "<code><<</code>"
or "<code>>></code>" are template code; the rest is literal
text. Given a sequence of the form:</p>
<blockquote>
<code>A<<B<<C>>D<<E>>F>>G<<<H>>>I</code>
</blockquote>
<p>template code cannot begin at "<<B" because it is not allowed
to contain "<code><<</code>" or "<code>>></code>", so the
first template code is "<code><<C>></code>", the second is
"<code><<E>></code>", and the last is
"<code><<H>></code>". Everything else ("<code>A<<B</code>",
"<code>D</code>", "<code>F>>G<</code>", and "<code>>I</code>")
is treated as literal text.</p>
<p>If template code begins with "<code><<.</code>" (with a period
immediately after the second "<code><</code>"), it strips any trailing
white space from immediately preceding literal text. Likewise, if template
code ends with "<code>.>></code>", it strips any leading white space
from immediately following literal text. Template code consisting of
only "<code><<.>></code>" is considered to meet both
conditions and is equivalent to "<code><<..>></code>".</p>
<p>There need not be any literal text before, after, or between template
code sequences. Template code sequences between delimiters may also be empty
(<code><<>></code>).</p>
<p>Unless otherwise stated, the remainder of this document will refer to
template code as the code between the "<code><<</code>"
(or "<code><<.</code>") and "<code>>></code>" (or
"<code>.>></code>") without reference to the delimiters
themselves.</p>
<p>[<a href='#contents'>Contents</a>]</p>
<h2 id='code_syntax'>Template Code Syntax</h2>
<ul>
<li><a href='#comment_syntax'>Comments</a></li>
<li><a href='#strlit_syntax'>String Literals</a></li>
<li><a href='#numlit_syntax'>Numeric Literals</a></li>
<li><a href='#variable_syntax'>Variables</a></li>
<li><a href='#call_syntax'>Method Calls</a></li>
<li><a href='#assignment_syntax'>Assignments</a></li>
<li><a href='#predefined_vars'>Pre-Defined Variables</a></li>
<li><a href='#codeseq_syntax'>Code Sequences</a></li>
<li><a href='#codeblock_syntax'>Code Blocks And Bindings</a></li>
<li><a href='#subscript_syntax'>Subscripts</a></li>
</ul>
<h3 id='comment_syntax'>Comments</h3>
<p>Comments begin with "<code>/*</code>" and end at the nearest
"<code>*/</code>".</p>
<blockquote><code>/* this is a comment */
/* and so is /* this */</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='strlit_syntax'>String Literals</h3>
<p>String literals are used to generate <a href='#string_values'>string
values</a>. LtdTemplate supports two forms: "short" and "regular".</p>
<p>Short string literals begin with a single quote (<code>'</code>) and
terminate before a period (<code>.</code>), comma (<code>,</code>), opening
or closing brackets, parentheses, or braces (<code>[](){}</code>), or white
space. However, any normally terminating character may be included by
preceding it with a backslash (<code>\</code>).</p>
<p>Regular string literals begin with a double quote (<code>"</code>) and
terminate at the next double quote. A double quote may be included by
preceding it with a backslash.</p>
<p>String literals may also contain other "escape sequences" like those in
Ruby double-quoted strings. Here is the full list:</p>
<table>
<tr><th>Sequence</th><th>Meaning</th></tr>
<tr><td>\M-\C-<i>x</i></td><td>meta-control-<i>x</i></td></tr>
<tr><td>\M-<i>x</i></td><td>meta-<i>x</i></td></tr>
<tr><td>\C-<i>x</i>, \C<i>x</i></td><td>control-<i>x</i></td></tr>
<tr><td>\u<i>dddd</i></td>
<td>Unicode four-digit, 16-bit hexadecimal code point <i>dddd</i></td></tr>
<tr><td>\x<i>dd</i></td><td>two-digit, 8-bit hexadecimal <i>dd</i></td></tr>
<tr><td>\<i>ddd</i></td>
<td>one, two, or three-digit, 8-bit octal <i>ddd</i></td></tr>
<tr><td>\a</td><td>alert (ASCII BEL)</td></tr>
<tr><td>\b</td><td>backspace (ASCII BS)</td></tr>
<tr><td>\e</td><td>escape (ASCII ESC)</td></tr>
<tr><td>\f</td><td>formfeed (ASCII FF)</td></tr>
<tr><td>\n</td><td>new-line/line-feed (ASCII LF)</td></tr>
<tr><td>\r</td><td>carriage return (ASCII CR)</td></tr>
<tr><td>\s</td><td>space (ASCII SP)</td></tr>
<tr><td>\t</td><td>horizontal tab (ASCII HT)</td></tr>
<tr><td>\v</td><td>vertical tab (ASCII VT)</td></tr>
<tr><td>\<i>c</i></td>
<td>any other character <i>c </i> is just itself</td></tr>
</table>
<p>Examples, with some comments added for annotation:</p>
<blockquote><code>' /* empty */ 'short '<\< '>\>
/* escaped code delimiters */ "\"regular\" string"</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='numlit_syntax'>Numeric Literals</h3>
<p>Numeric literals are used to generate typical integer or real (decimal)
<a href='#number_values'>numeric values</a> and consist of an optional
minus sign (<code>-</code>) followed by one or more digits, and optionally
followed by a decimal point (<code>.</code>) and one or more additional
digits.</p>
<blockquote><code>0.125 1 -2 3.0 -4.5</code></blockquote>
<p>LtdTemplate does not currently support numeric literals in scientific
notation or bases other than ten.</p>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='variable_syntax'>Variables</h3>
<p>Variables hold references to values, and can hold references to (be
bound to) different values at different times. They exist within the stack
of <a href='#namespace_values'>namespaces</a>. Referencing a variable
normally searches for it beginning in the most recent or "nearest"
namespace and works back to the first or "root" namespace until a
variable with that name is found. If the name begins with circumflex
(<code>^</code>), the search begins in the parent namespace (if there is
one) instead of the current namespace. If the name begins with at-sign
(<code>@</code>), only the root namespace is searched. If the variable
has not been <a href='#assignment_syntax'>assigned</a>, the
<a href='#nil_value'>nil</a> value is used.</p>
<p>Variable names must be in one of the following formats (unless accessed
as an <a href='#subscript_syntax'>element</a> of a specific
namespace—see last example) and are case-sensitive:</p>
<ol>
<li>A letter or an underscore (<code>_</code>), followed by zero
or more letters, numbers, or underscores</li>
<li>An at-sign or circumflex followed by one or more letters, numbers,
or underscores</li>
<li>An at-sign, circumflex, or dollar-sign (<code>$</code>) by itself</li>
</ol>
<blockquote><code>name item1 _2 ^parent @root $
@['<\<weird>\>]</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='call_syntax'>Method Calls</h3>
<p>A method call performs an action on, or returns information about,
a value. A method call consists of a value expression followed by a
period (<code>.</code>) followed by the desired method name, optionally
followed by an open parenthesis "<code>(</code>", zero or more method
call parameters separated by commas (<code>,</code>), and a closing
parenthesis "<code>)</code>". Parameters may be positional (also called
sequential) or named (also called random-access). Use the "dot dot"
symbol (<code>..</code>) to terminate the positional parameters and begin
the named parameters.</p>
<blockquote><code>value_expression.method_name(positional_1,
</code>...<code>, positional_N .. name_1, value_1,
</code>...<code>, name_N, value_N)</code></blockquote>
<p>Method names are case-sensitive and must be in one of the following
formats:</p>
<ol>
<li>A letter or underscore (<code>_</code>) followed by zero or more
letters, numbers, or underscores</li>
<li>One or more punctuation characters that don't have any other meaning
(these are often referred to as "operators" in other syntax definitions),
such as:</li>
</ol>
<blockquote><code>+ - * / % & | ! < <= =
== != >= ></code></blockquote>
<p>The parentheses are optional if no parameters are to be supplied to
the method call. The period is optional for "operator-style" method calls
if not immediately preceded by punctuation.</p>
<blockquote><code>3.type /* => number */<br>
3.type.length /* "chained" method calls; => 6 */<br>
1+(2,3,4) /* short for */ 1.+(2,3,4) /* => 10 */</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='assignment_syntax'>Assignments</h3>
<p>Variables (and array subscripts, covered later) support two assignment
method calls: unconditional (<code>=</code>) and conditional
(<code>?=</code>). A conditional assignment does nothing if the variable is
already bound to (holds a reference to) a value other than the nil
value. (This is a change from versions prior to 1.0.0; in those versions
even a nil value prevented a conditional assignment.) Assignments do not
render in the template output.</p>
<p>If called with a single parameter and no "dot dot" symbol, the value of
the single parameter is assigned. Otherwise, all the parameters are
assigned as an array. See also <a href='#array_values'>array values</a>.</p>
<blockquote><code>num=(5) num?=(6) /* num is still 5 */<br>
empty1= empty2=() /* empty arrays */<br>
single=(10 ..) /* one element */ double=(5, 10) /* two */<br>
matrix=($.*(1, 0), $.*(0, 1) .. 'type, 'identity)<br>
matrix[0, 0] /* => 1 */ matrix['type] /* => identity */</code></blockquote>
<p>Variables beginning with circumflex (<code>^</code>) will be created in
the parent namespace (if they do not already exist) and variables beginning
with at-sign (<code>@</code>) will be created in the root namespace. All
others will be created in the current namespace.</p>
<p>See also the <a href='#namespace_var_method'>var</a> method for
<a href='#namespace_values'>namespaces</a>.</p>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='predefined_vars'>Pre-Defined Variables</h3>
<p>The following variables are pre-defined by LtdTemplate:</p>
<table>
<tr><th>Name</th><th>Description</th></tr>
<tr><td><code>$</code></td>
<td>This is the current <a href='#namespace_values'>namespace</a>. A
new namespace is automatically created each time a
<a href='#codeblock_syntax'>code block</a> is executed and is
destroyed when the code block completes.</td></tr>
<tr><td><code>^</code></td>
<td>This variable refers to the previous (parent) namespace if there
is one, or <a href='#nil_value'>nil</a> if there isn't.</td></tr>
<tr><td><code>@</code></td>
<td>This variable refers to the first (also known as the "root" or
"top-level") namespace.</td></tr>
<tr><td><code>_</code></td>
<td>This variable refers to the array of positional and/or named
parameters passed into the template or current
<a href='#codeblock_syntax'>code block</a>.</td></tr>
</table>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='codeseq_syntax'>Code Sequences</h3>
<p>A code sequence refers to a sequence of zero or more template code
expressions. <a href='#template_syntax'>Templates</a>,
<a href='#call_syntax'>method call</a> parameters, and
<a href='#codeblock_syntax'>code block</a> bodies are all code sequences.</p>
<p>If a code sequence consists of a single value and does not constitute
the entire template code, it is retained as-is. Otherwise, the string
value of each element in the sequence, if any, is combined to
produce the result of the code sequence.</p>
<blockquote><code>'Hello $.true ", " num=(5) num-(4) " world!"<br>
/* 5 and 4 are single values in their code sequences */<br>
/* $.true and num=(5) render nothing */<br>
/* num-(4) returns the number 1 but it's string value gets used */<br>
/* => Hello, 1 world! */</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='codeblock_syntax'>Code Blocks And Bindings</h3>
<p>If you surround a <a href='#codeseq_syntax'>code sequence</a>
by braces (<code>{</code> and <code>}</code>), you create a code
block. A code block is a value which does not render directly, but
can be called as a <a href='#call_syntax'>method call</a>, executing
the code sequence within the code block.</p>
<blockquote><code>render_method=({ $.method })<br>
render_method.hi " " render_method.there
/* => hi there */</code></blockquote>
<p>Code blocks (or other values) may be bound to values using the
<code>methods</code> method and subsequently called like
<a href='#call_syntax'>methods</a>.
<p>The <code>methods</code> method takes any number of name-and-binding
pairs to be added or updated. If there are an odd number of parameters
(i.e. there is a final name without a binding), the existing binding, if any,
associated with that name is returned. Specifying nil ($.nil) as the
binding will actually delete any existing binding for the given name.</p>
<blockquote><code>@.methods('greet,{"Hello, "_[0]"."})<br>
@.greet('Dave) /* => Hello, Dave. */</code></blockquote>
<p>You can also bind code blocks to proxy objects to be used by an entire
class of values. For convenience, binding to an unset variable automatically
causes the variable to be set to an empty string.</p>
<blockquote><code>@Array?=(') /* bind the Array proxy to a unique object
(before 1.0.0) */<br>
@Array.methods('list, { $.target.join(", ") }) /* bind the list method */<br>
$.*(1, 2, 3).list /* => 1, 2, 3 */</code></blockquote>
<p>Methods added this way are only called if there is no standard method
with the same name.</p>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h3 id='subscript_syntax'>Subscripts</h3>
<p>Any expression that evaluates to an array (or tree of nested arrays)
may be subscripted to select a particular value or nested array from the
array. A subscript consists of an open bracket (<code>[</code>) followed
by one or more selector expressions separated by commas followed by a
closing bracket (<code>]</code>). Consecutive selector expressions are
used to traverse progressively more deeply nested arrays.</p>
<blockquote><code>array_var['items, 5] /* fetches item "5" (which
might also be an array) from array "items" in the array referenced by
array_var */<br>
array_var['items][5] /* as above - alternate syntax */</code></blockquote>
<p>If the requested item does not exist, the special value
"<a href='#nil_value'>nil</a>" is used instead.</p>
<p>Prior to version 1.0.0, subscript syntax could also be used to bind
<a href='#codeblock_syntax'>code blocks</a> to non-array values. The syntax
is shown here for historical reference but is <strong>no longer
supported</strong>:</p>
<blockquote><code>x['greeting]=({'hello}) /* where x is not an array
value */<br>/* this syntax is no longer supported! */</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#code_syntax'>Template Code Syntax</a>]</p>
<h2 id='values_methods'>Values And Methods</h2>
<ul>
<li><a href='#array_values'>Arrays</a></li>
<li><a href='#boolean_values'>Booleans (True And False)</a></li>
<li><a href='#codeblock_values'>Code Blocks</a></li>
<li><a href='#namespace_values'>Namespaces</a></li>
<li><a href='#nil_value'>Nil</a></li>
<li><a href='#number_values'>Numbers</a></li>
<li><a href='#string_values'>Strings</a></li>
<li><a href='#regexp_values'>Regular Expressions And Matches</a></li>
</ul>
<h3 id='array_values'>Arrays</h3>
<p>LtdTemplate does not have array literals, but you can construct arrays
using the variable assignment method (see <a href='#variable_syntax'>variable
syntax</a>) or via the <a href='#namespace_array_method'>array</a> method
on <a href='#namespace_values'>namespaces</a>:</p>
<blockquote><code>empty=() /* empty array */ single=(10 ..) /* one element */
double=(5, 10) /* two */<br>
matrix=($.*(1, 0), $.*(0, 1) .. 'type, 'identity)<br>
matrix[0, 0] /* => 1 */ matrix['type] /* => identity */</code></blockquote>
<p>Arrays render to the concatenation of the renderings of their sequential
(positional) elements; random-access (named) elements are ignored.</p>
<p>Standard methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td><code>call</code></td><td>Same as the array itself</td></tr>
<tr><td><code>class</code></td><td>Returns the string "Array"</td></tr>
<tr><td><code>each(</code><i>code_block</i><code>)</code></td>
<td>Executes <i>code_block</i><code>.each_seq(</code><i>index</i>,
<i>value</i><code>)</code> for each sequential index then
<i>code_block</i><code>.each_rnd(</code><i>key</i>,
<i>value</i><code>)</code> for each random-access key
and returns an array of results (since 0.2.1)</td></tr>
<tr><td><code>each_rnd(</code><i>code_block</i><code>)</code></td>
<td>Executes <i>code_block</i><code>.each_rnd(</code><i>key</i>,
<i>value</i><code>)</code> for each random-access key
and returns an array of results (since 0.2.1)</td></tr>
<tr><td><code>each_seq(</code><i>code_block</i><code>)</code></td>
<td>Executes <i>code_block</i><code>.each_seq(</code><i>index</i>,
<i>value</i><code>)</code> for each sequential index
and returns an array of results (since 0.2.1)</td></tr>
<tr><td><code>join</code></td><td>Joins sequential (positional)
elements</td></tr>
<tr><td><code>join(</code><i>separator</i><code>)</code></td><td>Join with
<i>separator</i> between sequential (positional) elements</td></tr>
<tr><td><code>join(</code><i>two</i><code>, </code><i>first</i><code>,
</code><i>middle</i><code>, </code><i>last</i><code>)</code></td>
<td>Joins two sequential elements with <i>two</i> as the separator or
more than two sequential elements with <i>first</i> as the first
separator, <i>last</i> as the last separator, and <i>middle</i> for
all other separators</td></tr>
<tr><td><code>pop</code>, <code>-></code></td><td>Pop the last sequential
element</td></tr>
<tr><td><code>push(</code><i>list</i><code>)</code>,
<code>+>(</code><i>list</i><code>)</code></td>
<td>Adds zero or more elements in the <i>list</i> to the end of the
array</td></tr>
<tr><td><code>rnd_size</code></td><td>The number of random-access (named)
elements</td></tr>
<tr><td><code>seq_size</code></td><td>The number of sequential (positional)
elements</td></tr>
<tr><td><code>shift</code>, <code><-</code></td><td>Shift the first
sequential element</td></tr>
<tr><td><code>size</code></td><td>The total number of elements in the
array</td></tr>
<tr><td><code>type</code></td><td>Returns the string "array"</td></tr>
<tr><td><code>unshift(</code><i>list</i><code>)</code>,
<code><+(</code><i>list</i><code>)</code></td>
<td>Adds zero or more elements in the <i>list</i> to the beginning of
the array</td></tr>
<tr><td><code>/</code></td><td>Interpolate the sequential and random-access
values of the array into the positional and named parameters of another
method call (since 0.2.1)</td></tr>
<tr><td><code>%</code></td>
<td>Interpolate pairs of sequential values in the array as named
parameters of another method call (since 0.2.1)</td></tr>
</table>
<p><a href='#codeblock_syntax'>Code blocks</a> may be bound as methods for
all array values as follows:</p>
<blockquote><code>@Array.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#values_methods'>Values And Methods</a>]</p>
<h3 id='boolean_values'>Booleans (True And False)</h3>
<p>LtdTemplate supports boolean values (true and false). They can be
accessed via the namespace method calls <code>$.true</code> and
<code>$.false</code>. There is only one true value and one false value,
although other values can be interpreted in boolean context (the nil
value is treated as false; all others, including the number 0 and
empty strings, are treated as true).</p>
<p>Standard methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td><code>call</code></td><td>Same as the boolean itself</td></tr>
<tr><td><code>class</code></td><td>Returns the string "Boolean"</td></tr>
<tr><td><code>string</code>, <code>str</code></td>
<td>Returns the string "true" for true and "false" for false</td></tr>
<tr><td><code>type</code></td><td>Returns the string "boolean"</td></tr>
<tr><td><code>+</code>, <code>|</code>, <code>or</code></td>
<td>Returns the "logical or" of the value and any supplied call
parameters (if <b>any are true</b>, the result is true, otherwise the
result is false)</td></tr>
<tr><td><code>*</code>, <code>&</code>, <code>and</code></td>
<td>Returns the "logical and" of the value and any supplied call
parameters (if <b>all are true</b>, the result is true, otherwise the
result is false)</td></tr>
<tr><td><code>!</code>, <code>not</code></td>
<td>Returns the "logical not and" of the value and any supplied call
parameters (if <b>all are false</b>, the result is true, otherwise the
result is false)</td></tr>
</table>
<p><a href='#codeblock_syntax'>Code blocks</a> may be bound as methods
for true, false, or both boolean
values as follows:</p>
<blockquote><code>$.true.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})<br>
$.false.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})<br>
@Boolean.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#values_methods'>Values And Methods</a>]</p>
<h3 id='codeblock_values'>Code Blocks</h3>
<p>Standard methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td><code>type</code></td><td>Returns the string "code"</td></tr>
</table>
<p>All other methods execute the code block in a new
<a href='#namespace_values'>namespace</a>.</p>
<p>[<a href='#contents'>Contents</a>] [<a href='#values_methods'>Values And Methods</a>]</p>
<h3 id='namespace_values'>Namespaces</h3>
<p>A namespace is a storage area for variables. A new namespace is created
each time the template is rendered or a <a href='#codeblock_values'>code
block</a> is executed. In the case of code blocks, the previously active
namespace becomes the parent (<code>^</code>) of the new namespace
(<code>$</code>).</p>
<p>Namespaces provide a number of <a href='#predefined_vars'>pre-defined
variables</a>, as well as <a href='#call_syntax'>method calls</a> for
loops and conditionals that are traditionally statements in other
programming environments.</p>
<p>Standard methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td id='namespace_array_method'><code>array(</code><i>elements</i><code>)</code>,
<code>*(</code><i>elements</i><code>)</code></td>
<td>Returns an anonymous array (see <a href='#array_values'>array
values</a>, <a href='#assignment_syntax'>assignments</a>, and
the <a href='#namespace_var_method'>var</a> method)</td></tr>
<tr><td><code>false</code></td><td>Returns the boolean false value</td></tr>
<tr><td><code>if(</code><i>condition_1</i><code>,
</code><i>return_1</i><code>,</code> ...<code>,</code>
<i>condition_N</i><code>,</code> <i>return_N</i><code>,</code>
<i>default</i><code>)</code></td>
<td>Processes each condition in turn. The return value
corresponding to the first condition that evaluates to true is
returned. If none of the conditions evaluate to true, the optional
<i>default</i> value (or the nil value, in the case of an even number
of parameters) is returned. Parameters can be supplied as
<a href='#codeblock_syntax'>code blocks</a> to avoid execution unless
and until needed.</td></tr>
<tr><td><code>loop(</code><i>before</i><code>,</code>
<i>body</i><code>,</code> <i>after</i><code>)</code></td>
<td>If the <i>before</i> condition evaluates to true, the
<i>body</i> is executed and the optional <i>after</i> condition is
evaluated. If the <i>after</i> condition is absent or evaluates to
true, the loop starts over with the <i>before</i> condition. The
<i>body</i> and non-constant conditions should be supplied as
<a href='#codeblock_syntax'>code blocks</a>. Returns an
<a href='#array_values'>array</a> of <i>body</i> results
(one element per loop iteration).</td></tr>
<tr><td><code>method</code></td><td>Returns the method name used to
call a <a href='#codeblock_syntax'>code block</a>, or "render" for
top-level template code</td></tr>
<tr><td><code>nil</code></td><td>Returns the nil value</td></tr>
<tr><td><code>target</code></td><td>Returns the target object in
a <a href='#codeblock_syntax'>code block</a> being called as
part of an object binding</td></tr>
<tr><td><code>true</code></td><td>Returns the boolean true value</td></tr>
<tr><td><code>use(</code><i>name</i><code>)</code></td>
<td>Calls the template loader to load resource <i>name</i></td></tr>
<tr><td id='namespace_var_method'><code>var(</code><i>name_1</i><code>,</code> ...<code>,</code>
<i>name_N</i> <code>..</code> <i>set_1</i><code>,</code>
<i>value_1</i><code>,</code> ...<code>,</code> <i>set_N</i><code>,</code>
<i>value_N</i><code>)</code></td>
<td>Creates and (re-)sets variables named by the supplied strings. The
variables in the sequential parameters section, <i>name_1</i> through
<i>name_N</i>, are assigned the nil value. The variables in the
random-access section, <i>set_1</i> through <i>set_N</i>, are assigned
the corresponding values from <i>value_1</i> through
<i>value_N</i>.</td></tr>
</table>
<p><a href='#codeblock_syntax'>Code blocks</a> may be bound as methods for
all namespaces as follows:</p>
<blockquote><code>@Namespace.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#values_methods'>Values And Methods</a>]</p>
<h3 id='nil_value'>Nil</h3>
<p>LtdTemplate supports a "nil" value to represent the lack of another
value. It can be accessed via the namespace method call
<code>$.nil</code>. There is only one nil value.</p>
<p>Standard methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td><code>type</code></td><td>Returns the string "nil"</td></tr>
</table>
<p><a href='#codeblock_syntax'>Code blocks</a> may be bound as methods
for the nil value as follows:</p>
<blockquote><code>$.nil.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#values_methods'>Values And Methods</a>]</p>
<h3 id='number_values'>Numbers</h3>
<p>Standard methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td><code>abs</code></td>
<td>Returns the absolute value of the number</td></tr>
<tr><td><code>call</code></td><td>Returns the number itself</td></tr>
<tr><td><code>ceil</code></td><td>Returns the closest greater or equal
integer</td></tr>
<tr><td><code>class</code></td><td>Returns the string "Number"</td></tr>
<tr><td><code>floor</code></td><td>Returns the closest lesser or equal
integer</td></tr>
<tr><td><code>flt, float</code></td><td>Returns the number as a
floating-point (decimal) number</td></tr>
<tr><td><code>int</code></td><td>Returns the integer portion of the number</td></tr>
<tr><td><code>str</code>, <code>string</code></td>
<td>Returns the number as a string</td></tr>
<tr><td><code>type</code></td><td>Returns the string "number"</td></tr>
<tr><td><code>+(</code><i>list</i><code>)</code></td>
<td>Returns the sum of the number and numeric items in
<i>list</i></td></tr>
<tr><td><code>-</code></td>
<td>With no parameters, returns the negative of the number</td></tr>
<tr><td><code>-(</code><i>list</i><code>)</code></td>
<td>Returns the difference of the number and the sum of numeric
items in the non-empty <i>list</i></td></tr>
<tr><td><code>*(</code><i>list</i><code>)</code></td>
<td>Returns the product of the number and the numeric items in
<i>list</i></td></tr>
<tr><td><code>/(</code><i>list</i><code>)</code></td>
<td>Returns the quotient of the number and the numeric items in
<i>list</i></td></tr>
<tr><td><code>%(</code><i>list</i><code>)</code></td>
<td>Returns the progressive remainder of the number and the
numeric items in <i>list</i></td></tr>
<tr><td><code>&(</code><i>list</i><code>)</code></td>
<td>Returns the bit-wise "AND" of the number and the numeric items
in <i>list</i></td></tr>
<tr><td><code>|(</code><i>list</i><code>)</code></td>
<td>Returns the bit-wise "OR" of the number and the numeric items
in <i>list</i></td></tr>
<tr><td><code>^(</code><i>list</i><code>)</code></td>
<td>Returns the bit-wise "exclusive OR" of the number and the numeric
items in <i>list</i></td></tr>
<tr><td><i>op</i> or <i>op</i><code>(</code><i>value</i><code>)</code> for
<i>op</i> in <code><=</code>, <code><</code>, <code>==</code>,
<code>!=</code>, <code>></code>, <code>>=</code></td>
<td>Returns whether the number is less than or equal to, less than,
equal to, not equal to, greater than, or greater than or equal to,
<i>value</i>. If <i>value</i> is not supplied or is not numeric, zero
is used.</td></tr>
</table>
<p><a href='#codeblock_syntax'>Code blocks</a> may be bound as methods for
all numeric values as follows:</p>
<blockquote><code>@Number.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#values_methods'>Values And Methods</a>]</p>
<h3 id='string_values'>Strings</h3>
<p>Standard methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td><code>call</code></td><td>Returns the string itself</td></tr>
<tr><td><code>class</code></td><td>Returns the string "String"</td></tr>
<tr><td><code>capcase</code></td>
<td>Returns the string with each space-separated word capitalized
(since 0.2.2)</td></tr>
<tr><td><code>downcase</code></td>
<td>Returns the string entirely in lowercase (since 0.2.2)</td></tr>
<tr><td><code>flt</code>, <code>float</code></td>
<td>Returns the floating-point value of the string</td></tr>
<tr><td><code>html</code></td>
<td>Returns the HTML encoding of the string (since 0.1.4)</td></tr>
<tr><td><code>idx(</code><i>target</i><code>,
</code><i>offset</i><code>)</code>,
<code>index(</code><i>target</i><code>,
</code><i>offset</i><code>)</code></td>
<td>Search for <i>target</i> left-to-right in the string beginning at
position <i>offset</i> (default 0) and return the offset from the start
of the string at which found (or -1 if not found)</td></tr>
<tr><td><code>int</code></td>
<td>Returns the integer value of the string</td></tr>
<tr><td><code>join(</code><i>list</i><code>)</code></td>
<td>Equivalent to
<code>$.array(<i>list</i><code>).join(</code><i>string</i><code>)</code>
(since 0.2.2)</td></tr>
<tr><td><code>len</code>, <code>length</code></td>
<td>Returns the length of the string</td></tr>
<tr><td><code>match(</code><i>regexp</i><code>,
</code><i>offset</i><code>)</code></td><
<td>Match a string against a <a href='#regexp_values'>regular
expression</a>. Returns MatchData if the pattern matches, or nil
if it doesn't.</td></tr>
<tr><td><code>pcte</code></td>
<td>Returns the "percent encoding" of the string
(for URI components; since 0.1.4)</td></tr>
<tr><td><code>regexp</code></td>
<td>Returns a "<a href='#regexp_values'>regular expression</a>"
version of the string (only if enabled by the calling program;
since 0.2.2)</td></tr>
<tr><td><code>rep(</code><i>pattern</i><code>,</code>
<i>replacement</i><code>)</code>,
<code>replace(</code><i>pattern</i><code>,</code>
<i>replacement</i><code>)</code></td>
<td>Returns a copy of the string with all occurrences of <i>pattern</i>
replaced with <i>replacement</i>; the <i>pattern</i> may be a
<a href='#regexp_values'>regular expression</a> (since 0.2.2)</td></tr>
<tr><td><code>rep1, replace1</code></td>
<td>Like <code>rep</code>/<code>replace</code>, but with only the
first occurrence replaced (since 0.2.2)</td></tr>
<tr><td><code>split(</code><i>pattern</i>, <i>limit</i><code>)</code></td>
<td>Returns an array of up to <i>limit</i> (default unlimited)
substrings split at <i>pattern</i> (since 0.2.2)</td></tr>
<tr><td><code>ridx(</code><i>string</i><code>,
</code><i>offset</i><code>)</code>,
<code>rindex(</code><i>string</i><code>,
</code><i>offset</i><code>)</code></td>
<td>Search for <i>target</i> right-to-left in the string beginning at
position <i>offset</i> (the end of the string by default) and return
the offset from the start of the string at which found (or -1 if not
found)</td></tr>
<tr><td><code>rng(</code><i>begin</i><code>,
</code><i>end</i><code>)</code>,
<code>range(</code><i>begin</i><code>,
</code><i>end</i><code>)</code></td>
<td>Returns characters <i>begin</i> through <i>end</i> of the string,
inclusive, counting from zero. Either may be negative, in which case
counting is backwards from the end of the string.</td></tr>
<tr><td><code>slc(</code><i>begin</i><code>,
</code><i>length</i><code>)</code>,
<code>slice(</code><i>begin</i><code>,
</code><i>length</i><code>)</code></td>
<td>Returns <i>length</i> characters beginning at <i>begin</i>,
counting from zero. <i>Begin</i> may be negative, in which case
counting is backwards from the end of the string.</td></tr>
<tr><td><code>str</code>, <code>string</code></td>
<td>Returns the string itself</td></tr>
<tr><td><code>type</code></td><td>Returns the string "string"</td></tr>
<tr><td><code>upcase</code></td>
<td>Returns the string entirely in uppercase</td></tr>
<tr><td><code>+(</code><i>list</i><code>)</code></td>
<td>Returns the concatenation of the string and the items in
<i>list</i></td></tr>
<tr><td><code>*(</code><i>value</i><code>)</code></td>
<td>Returns the concatenation of the string repeated <i>value</i>
times. If <i>value</i> is negative, the reverse of the string repeated
-<i>value</i> times is returned. If <i>value</i> is omitted or
not numeric, an empty string is returned.</td></tr>
<tr><td><i>op</i> or <i>op</i><code>(</code><i>value</i><code>)</code> for
<i>op</i> in <code><=</code>, <code><</code>, <code>==</code>,
<code>!=</code>, <code>></code>, <code>>=</code></td>
<td>Returns whether the string is less than or equal to, less than,
equal to, not equal to, greater than, or greater than or equal to,
<i>value</i>. If <i>value</i> is not supplied, the empty string
is used.</td></tr>
</table>
<p><a href='#codeblock_syntax'>Code blocks</a> may be bound as methods for
all string values as follows:</p>
<blockquote><code>@String.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})</code></blockquote>
<p>[<a href='#contents'>Contents</a>] [<a href='#values_methods'>Values And Methods</a>]</p>
<h3 id='regexp_values'>Regular Expressions And Matches</h3>
<p>"<a href='http://en.wikipedia.org/wiki/Regular_expression'>Regular
expressions</a>" ("regex" or "regexp" for short) in LtdTemplate are
generated from <a href='#string_values'>string values</a> using the
<code>regexp</code> method.</p>
<p>Regular expressions must be enabled by the calling program. See
the gem documentation for details.</p>
<p>Regexp-specific methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td><code>ci, ignorecase</code></td>
<td>Make pattern case-insensitive</td></tr>
<tr><td><code>class</code></td>
<td>Returns the string "Regexp"</td></tr>
<tr><td><code>ext, extended</code></td>
<td>Allow white space and comments in the pattern</td></tr>
<tr><td><code>match(</code><i>string</i><code>,
</code><i>offset</i><code>)</code></td>
<td>Match a <a href='#string_values'>string</a> against a regular
expression. Returns MatchData if the pattern matches, or nil if it
doesn't.</td></tr>
<tr><td><code>multi, multiline</code></td>
<td>Makes <code>.</code> match newlines too</td></tr>
<tr><td><code>type</code></td><td>Returns the string "regexp"</td></tr>
</table>
<blockquote><code>"Example".replace("[aeiou]".regexp.ci,'_)
/* => _x_mpl_ */</code></blockquote>
<p><a href='#codeblock_syntax'>Code blocks</a> may be bound as methods for
all regular expression values as follows:</p>
<blockquote><code>@Regexp.methods('</code><i>method_name</i><code>, {</code>
<i>code sequence</i> <code>})</code></blockquote>
<p>Regular expression match-result methods:</p>
<table>
<tr><th>Method</th><th>Description</th></tr>
<tr><td><code>[</code><i>index</i><code>]</code></td>
<td>Returns the entire (index 0) or specific sub-pattern match.</td></tr>
<tr><td><code>[</code><i>name</i><code>]</code></td>
<td>Returns the named sub-pattern match.</td></tr>
<tr><td><code>begin(</code><i>n</i><code>)</code></td>
<td>Returns the offset of the start of the <i>nth</i> match array
in the string (numeric index or named sub-match).</td></tr>
<tr><td><code>class</code></td>
<td>Returns the string "Match".</td></tr>
<tr><td><code>end(</code><i>n</i><code>)</code></td>
<td>Returns the offset of the character immediately following the
<i>nth</i> match in the string (numeric index or named