summaryrefslogtreecommitdiff
path: root/doc/users-guide.html
blob: d707c7fe1ef34aa1edc1ef31a6d964e3a4acce05 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html">
  <title>Erubis Users' Guide</title>
  <meta name="generator" content="kwaser">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <link rel="stylesheet" href="docstyle.css" type="text/css">
 </head>
 <body>

  <blockquote>
   <div class="mainbody">

    <div align="left"><h1>Erubis Users' Guide</h1></div>
    <div align="left">
      last update: $Date$<br>
    </div>

<a name="preface"></a>
<h2 class="section1">Preface</h2>
<p>Erubis is an implementation of eRuby.
It has the following features.
</p>
<ul type="disc">
<li>Very fast, almost three times faster than ERB and even as fast as eruby (implemented in C)
</li>
<li>Auto escaping support
</li>
<li>Auto trimming spaces around '&lt;% %&gt;'
</li>
<li>Embedded pattern changeable (default '&lt;% %&gt;')
</li>
<li>Support multi-language (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
</li>
<li>Context object available and easy to combine eRuby template with YAML datafile
</li>
<li>Print statement available
</li>
<li>Easy to extend in subclass
</li>
</ul>
<p>Erubis is implemented in pure Ruby.  It requires Ruby 1.8 or higher.
</p>
<a name="toc"></a>
<h3 class="section2">Table of Contents</h3>
<ul>
  <li><a href="#preface">Preface</a>
  <ul>
    <li><a href="#toc">Table of Contents</a>
    </li>
  </ul>
  </li>
  <li><a href="#install">Installation</a>
  </li>
  <li><a href="#tutorial">Tutorial</a>
  <ul>
    <li><a href="#tut-basic">Basic Example</a>
    </li>
    <li><a href="#tut-trim">Trimming Spaces</a>
    </li>
    <li><a href="#tut-escape">Escape</a>
    </li>
    <li><a href="#tut-pattern">Embedded Pattern</a>
    </li>
    <li><a href="#tut-context">Context Object</a>
    </li>
    <li><a href="#tut-datafile">Context Data File</a>
    </li>
    <li><a href="#Preamble and Postamble">Preamble and Postamble</a>
    </li>
  </ul>
  </li>
  <li><a href="#enhancer">Enhancer</a>
  <ul>
    <li><a href="#escape-enhander">EscapeEnhancer</a>
    </li>
    <li><a href="#stdout-enhancer">StdoutEnhancer</a>
    </li>
    <li><a href="#printout-enhancer">PrintOutEnhancer</a>
    </li>
    <li><a href="#printenabled-enhancer">PrintEnabledEnhancer</a>
    </li>
    <li><a href="#array-enhancer">ArrayEnhancer</a>
    </li>
    <li><a href="#arraybuffer-enhancer">ArrayBufferEnhancer</a>
    </li>
    <li><a href="#stringbuffer-enhancer">StringBufferEnhancer</a>
    </li>
    <li><a href="#simplify-enhancer">SimplifyEnhancer</a>
    </li>
    <li><a href="#bipattern-enhancer">BiPatternEnhancer</a>
    </li>
    <li><a href="#percentline-enhancer">PercentLineEnhancer</a>
    </li>
    <li><a href="#headerfooter-enhancer">HeaderFooterEnhancer</a>
    </li>
  </ul>
  </li>
  <li><a href="#lang">Multi-Language</a>
  <ul>
    <li><a href="#lang-php">PHP</a>
    </li>
    <li><a href="#lang-c">C</a>
    </li>
    <li><a href="#lang-scheme">Scheme</a>
    </li>
    <li><a href="#lang-perl">Perl</a>
    </li>
    <li><a href="#lang-javascript">JavaScript</a>
    </li>
  </ul>
  </li>
  <li><a href="#Benchmark">Benchmark</a>
  </li>
  <li><a href="#command">Command Reference</a>
  <ul>
    <li><a href="#command-usage">Usage</a>
    </li>
    <li><a href="#command-options">Options</a>
    </li>
    <li><a href="#command-props">Properties</a>
    </li>
  </ul>
  </li>
</ul>
<br>


<br>


<a name="install"></a>
<h2 class="section1">Installation</h2>
<ul type="disc">
<li>If you have installed RubyGems, just type <code>gem install --remote erubis</code>.
<pre class="terminal">$ sudo gem install --remote erubis
</pre>
</li>
</ul>
<ul type="disc">
<li>Or if you can be root user, download erubis-X.X.X.tar.bz2 and install by setup.rb.
<pre class="terminal">$ tar xjf erubis-X.X.X.tar.bz2
$ cd erubis_X.X.X/
$ ruby setup.rb
</pre>
</li>
</ul>
<ul type="disc">
<li>Else you should copy 'lib/erubis.rb', 'lib/erubis/', and 'bin/erubis' into proper directory manually.
<pre class="terminal">$ tar xjf erubis-X.X.X.tar.bz2
$ cd erubis_X.X.X/
$ cp -r lib/erubis.rb lib/erubis /usr/local/lib/ruby/site_ruby/1.8
$ cp bin/erubis /usr/local/bin
</pre>
</li>
</ul>
<ul type="disc">
<li>(Optional) 'contrib/inline-require' enables you to merge 'lib/erubis.rb' into 'bin/erubis'.
<pre class="terminal">$ tar xjf erubis-X.X.X.tar.bz2
$ cd erubis_X.X.X/
$ unset RUBYLIB
$ contrib/inline-require -I lib bin/erubis &gt; contrib/erubis
</pre>
</li>
</ul>
<br>


<a name="tutorial"></a>
<h2 class="section1">Tutorial</h2>
<a name="tut-basic"></a>
<h3 class="section2">Basic Example</h3>
<p>Here is a most basic example of Erubis.
</p>
<a name="example1.eruby"></a>
<div class="program_caption">
example1.eruby</div>
<pre class="program">&lt;ul&gt;
  <b>&lt;% for item in list %&gt;</b>
  &lt;li&gt;
    <b>&lt;%= item %&gt;</b>
  &lt;/li&gt;
  <b>&lt;% end %&gt;</b>
  <b>&lt;%# here is ignored because starting with '#' %&gt;</b>
&lt;/ul&gt;
</pre>
<a name="example1.rb"></a>
<div class="program_caption">
example1.rb</div>
<pre class="program">require 'erubis'
input = File.read('example1.eruby')
eruby = <b>Erubis::Eruby.new(input)</b>    # create Eruby object

puts "---------- script source ---"
puts <b>eruby.src</b>                      # print script source

puts "---------- result ----------"
list = ['aaa', 'bbb', 'ccc']
puts <b>eruby.result(binding())</b>        # get result
</pre>
<div class="terminal_caption">
output</div>
<pre class="terminal">$ ruby example1.rb
---------- script source ---
_out = []; _out &lt;&lt; '&lt;ul&gt;
';   for item in list 
; _out &lt;&lt; '  &lt;li&gt;
'; _out &lt;&lt; '    '; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '
'; _out &lt;&lt; '  &lt;/li&gt;
';   end 
;
; _out &lt;&lt; '&lt;/ul&gt;
';
_out.join
---------- result ----------
&lt;ul&gt;
  &lt;li&gt;
    aaa
  &lt;/li&gt;
  &lt;li&gt;
    bbb
  &lt;/li&gt;
  &lt;li&gt;
    ccc
  &lt;/li&gt;
&lt;/ul&gt;
</pre>
<br>


<a name="tut-trim"></a>
<h3 class="section2">Trimming Spaces</h3>
<p>Erubis deletes spaces around '&lt;% %&gt;' automatically, while it leaves spaces around '&lt;%= %&gt;'.
If you want leave spaces around '&lt;% %&gt;', add <code>:trim=&gt;false</code> option to Erubis::Eruby.new().
</p>
<a name="example2.eruby"></a>
<div class="program_caption">
example2.eruby</div>
<pre class="program">&lt;ul&gt;
  &lt;% for item in list %&gt;
  &lt;li&gt;
    &lt;%= item %&gt;
  &lt;/li&gt;
  &lt;% end %&gt;
&lt;/ul&gt;
</pre>
<a name="example2.rb"></a>
<div class="program_caption">
example2.rb</div>
<pre class="program">require 'erubis'
input = File.read('example2.eruby')
eruby = Erubis::Eruby.new(input<b>, :trim=&gt;false</b>)

puts "---------- script source ---"
puts eruby.src                            # print script source

puts "---------- result ----------"
list = ['aaa', 'bbb', 'ccc']
puts eruby.result(binding())              # get result
</pre>
<div class="terminal_caption">
output</div>
<pre class="terminal">$ ruby example2.rb
---------- script source ---
_out = []; _out &lt;&lt; '&lt;ul&gt;
'; _out &lt;&lt; '  '; for item in list ; _out &lt;&lt; '
'; _out &lt;&lt; '  &lt;li&gt;
'; _out &lt;&lt; '    '; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '
'; _out &lt;&lt; '  &lt;/li&gt;
'; _out &lt;&lt; '  '; end ; _out &lt;&lt; '
'; _out &lt;&lt; '&lt;/ul&gt;
';
_out.join
---------- result ----------
&lt;ul&gt;
  
  &lt;li&gt;
    aaa
  &lt;/li&gt;
  
  &lt;li&gt;
    bbb
  &lt;/li&gt;
  
  &lt;li&gt;
    ccc
  &lt;/li&gt;
  
&lt;/ul&gt;
</pre>
<br>


<a name="tut-escape"></a>
<h3 class="section2">Escape</h3>
<p>Erubis have ability to escape (sanitize) expression.
Erubis::Eruby class act as the following:
</p>
<ul type="disc">
<li><code>&lt;%= <i>expr</i> %&gt;</code> -  not escaped.
</li>
<li><code>&lt;%== <i>expr</i> %&gt;</code> - escaped.
</li>
<li><code>&lt;%=== <i>expr</i> %&gt;</code> - out to $stderr.
</li>
<li><code>&lt;%==== <i>expr</i> %&gt;</code> - ignored.
</li>
</ul>
<p>Erubis::EscapedEruby<sup>(<a href="#fnref:1" name="fnlink:1">*1</a>)</sup> class handle '&lt;%= %&gt;' as escaped and '&lt;%== %&gt;' as not escaped.
It means that using Erubis::EscapedEruby you can escape expression by default.
Also Erubis::XmlEruby class (which is equivalent to Erubis::EscapedEruby) is provided for compatibility with Erubis 1.1.
</p>
<a name="example3.eruby"></a>
<div class="program_caption">
example3.eruby</div>
<pre class="program">&lt;% for item in list %&gt;
 - <b>&lt;%=</b> item <b>%&gt;</b>
 - <b>&lt;%==</b> item <b>%&gt;</b>
 - <b>&lt;%===</b> item <b>%&gt;</b>

&lt;% end %&gt;
</pre>
<a name="example3.rb"></a>
<div class="program_caption">
example3.rb</div>
<pre class="program">require 'erubis'
input = File.read('example3.eruby')
eruby = Erubis::<b>EscapedEruby</b>.new(input)           # or Erubis::XmlEruby

puts "---------- script source ---"
puts eruby.src                             # print script source

puts "---------- result ----------"
<b>list = ['&lt;aaa&gt;', 'b&amp;b', '"ccc"']</b>
puts eruby.result(binding())               # get result
</pre>
<div class="terminal_caption">
output</div>
<pre class="terminal">$ ruby example3.rb 2&gt; stderr.log
---------- script source ---
_out = []; for item in list 
; _out &lt;&lt; ' - '; _out &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _out &lt;&lt; '
'; _out &lt;&lt; ' - '; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '
'; _out &lt;&lt; ' - '; $stderr.puts("*** debug: item=#{(item).inspect}"); _out &lt;&lt; '
'; _out &lt;&lt; '
'; end 
;
_out.join
---------- result ----------
 - &amp;lt;aaa&amp;gt;
 - &lt;aaa&gt;
 - 

 - b&amp;amp;b
 - b&amp;b
 - 

 - &amp;quot;ccc&amp;quot;
 - "ccc"
 - 

$ cat stderr.log
*** debug: item="&lt;aaa&gt;"
*** debug: item="b&amp;b"
*** debug: item="\"ccc\""
</pre>
<p>The command-line option '-e Escape' will do the same action as Erubis::EscapedEruby.
This is available in any language.
</p>
<pre class="terminal">$ erubis -l ruby <b>-e Escape</b> example3.eruby
_out = []; for item in list 
; _out &lt;&lt; ' - '; _out &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _out &lt;&lt; '
'; _out &lt;&lt; ' - '; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '
'; _out &lt;&lt; ' - '; $stderr.puts("*** debug: item=#{(item).inspect}"); _out &lt;&lt; '
'; _out &lt;&lt; '
'; end 
;
_out.join
</pre>
<p>Escaping function (default 'Erubis::XmlHelper.escape_xml()') can be changed by command-line property '--escape=xxx' or by overriding Erubis::Eruby#escaped_expr() in subclass.
</p>
<div class="program_caption">
example to override Erubis::Eruby#escaped_expr()</div>
<pre class="program">class CGIEruby &lt; Erubis::Eruby
  def escaped_expr(code)
    return "CGI.escapeHTML((#{code.strip}).to_s)"
    #return "h(#{code.strip})"
  end
end

class LatexEruby &lt; Erubi::Eruby
  def escaped_expr(code)
    return "(#{code}).gsub(/[%\\]/,'\\\\\&amp;')"
  end
end
</pre>
<div class="footnote">
 <dl compact>
  <dt>(<a name="fnref:1" href="#fnlink:1">*1</a>)</dt>
  <dd>Erubis::EscapedEruby class includes Erubis::EscapeEnhancer which swtches the action of '&lt;%= %&gt;' and '&lt;%== %&gt;'.</dd>
 </dl>
</div>
<br>


<a name="tut-pattern"></a>
<h3 class="section2">Embedded Pattern</h3>
<p>You can change embedded pattern '<code>&lt;% %&gt;</code>' to another.
</p>
<a name="example4.eruby"></a>
<div class="program_caption">
example4.eruby</div>
<pre class="program"><b>&lt;!--%</b> for item in list <b>%--&gt;</b>
  &lt;p&gt;<b>&lt;!--%=</b> item <b>%--&gt;</b>&lt;/p&gt;
<b>&lt;!--%</b> end <b>%--&gt;</b>
</pre>
<a name="example4.rb"></a>
<div class="program_caption">
example4.rb</div>
<pre class="program">require 'erubis'
input = File.read('example4.eruby')
eruby = Erubis::Eruby.new(input<b>, :pattern=&gt;'&lt;!--% %--&gt;'</b>)
                                      # or '&lt;(?:!--)?% %(?:--)?&gt;'

puts "---------- script source ---"
puts eruby.src                            # print script source

puts "---------- result ----------"
list = ['aaa', 'bbb', 'ccc']
puts eruby.result(binding())              # get result
</pre>
<div class="terminal_caption">
output</div>
<pre class="terminal">$ ruby example4.rb
---------- script source ---
_out = []; for item in list 
; _out &lt;&lt; '  &lt;p&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/p&gt;
'; end 
;
_out.join
---------- result ----------
  &lt;p&gt;aaa&lt;/p&gt;
  &lt;p&gt;bbb&lt;/p&gt;
  &lt;p&gt;ccc&lt;/p&gt;
</pre>
<p>It is able to specify regular expression with :pattern option.
Notice that you must use '<code>(?: )</code>' instead of '<code>( )</code>' for grouping.
For example, '<code>&lt;(!--)?% %(--)?&gt;</code>' will not work while '<code>&lt;(?:!--)?% %(?:--)?&gt;</code>' will work.
</p>
<br>


<a name="tut-context"></a>
<h3 class="section2">Context Object</h3>
<p>Context object is a set of data which are used in eRuby script.
Using context object makes clear which data to be used.
In Erubis, Hash object and Erubis::Context object are available as context object.
</p>
<p>When using Hash as context object,
hash key means variable name and it should be string or symbol.
</p>
<a name="example5.eruby"></a>
<div class="program_caption">
example5.eruby</div>
<pre class="program">&lt;span&gt;&lt;%= val %&gt;&lt;/span&gt;
&lt;ul&gt;
 &lt;% for item in list %&gt;
  &lt;li&gt;&lt;%= item %&gt;&lt;/li&gt;
 &lt;% end %&gt;
&lt;/ul&gt;
</pre>
<a name="example5.rb"></a>
<div class="program_caption">
example5.rb</div>
<pre class="program">require 'erubis'
input = File.read('example5.eruby')
eruby = Erubis::Eruby.new(input)      # create Eruby object

## create context object
## (key means var name, which may be string or symbol.)
<b>context = {}</b>
<b>context[:val]   = 'Erubis Example'</b>
<b>context['list'] = ['aaa', 'bbb', 'ccc']</b>

puts <b>eruby.evaluate(context)</b>         # get result
</pre>
<div class="terminal_caption">
output</div>
<pre class="terminal">$ ruby example5.rb
&lt;span&gt;Erubis Example&lt;/span&gt;
&lt;ul&gt;
  &lt;li&gt;aaa&lt;/li&gt;
  &lt;li&gt;bbb&lt;/li&gt;
  &lt;li&gt;ccc&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>When using Erubis::Context object, context data is accessible via instance variables in eRuby template.
</p>
<a name="example6.eruby"></a>
<div class="program_caption">
example6.eruby</div>
<pre class="program">&lt;span&gt;&lt;%= <b>@val</b> %&gt;&lt;/span&gt;
&lt;ul&gt;
 &lt;% for item in <b>@list</b> %&gt;
  &lt;li&gt;&lt;%= item %&gt;&lt;/li&gt;
 &lt;% end %&gt;
&lt;/ul&gt;
</pre>
<a name="example6.rb"></a>
<div class="program_caption">
example6.rb</div>
<pre class="program">require 'erubis'
input = File.read('example6.eruby')
eruby = Erubis::Eruby.new(input)      # create Eruby object

## create context object
## (key means var name, which may be string or symbol.)
<b>context = Erubis::Context.new</b>
<b>context[:val]   = 'Erubis Example'</b>
<b>context['list'] = ['aaa', 'bbb', 'ccc']</b>

puts <b>eruby.evaluate(context)</b>         # get result
</pre>
<div class="terminal_caption">
output</div>
<pre class="terminal">$ ruby example6.rb
&lt;span&gt;Erubis Example&lt;/span&gt;
&lt;ul&gt;
  &lt;li&gt;aaa&lt;/li&gt;
  &lt;li&gt;bbb&lt;/li&gt;
  &lt;li&gt;ccc&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p><code>eruby.evaluate(context)</code> is almost equivalent to <code>context.instance_eval(eruby.src)</code>.
In fact, eruby.evaluate() can take any object.
</p>
<pre class="program">class MyData
  def initialize(val, list)
    @val = val
    @list = list
  end
end

<b>mydata = MyData.new</b>('Erubis Example', ['aaa', 'bbb', 'ccc'])

require 'erubis'
eruby = Erubis::Eruby.new(File.read('example6.eruby'))
puts eruby.evaluate(<b>mydata</b>)
</pre>
<br>


<a name="tut-datafile"></a>
<h3 class="section2">Context Data File</h3>
<p>It is very useful to import YAML document data into Hash context object.
</p>
<a name="example7.yaml"></a>
<div class="program_caption">
example7.yaml</div>
<pre class="program">title: Users List
users:
  - name:  foo
    mail:  foo@mail.com
  - name:  bar
    mail:  bar@mail.net
  - name:  baz
    mail:  baz@mail.org
</pre>
<a name="example7.eruby"></a>
<div class="program_caption">
example7.eruby</div>
<pre class="program">&lt;h1&gt;&lt;%= title %&gt;&lt;/h1&gt;
&lt;ul&gt;
 &lt;% for user in users %&gt;
  &lt;li&gt;
    &lt;a href="mailto:&lt;%= user['mail']%&gt;"&gt;&lt;%= user['name'] %&gt;&lt;/a&gt;
  &lt;/li&gt;
 &lt;% end %&gt;
&lt;/ul&gt;
</pre>
<a name="example7.rb"></a>
<div class="program_caption">
example7.rb</div>
<pre class="program">require 'erubis'
input = File.read('example7.eruby')
eruby = Erubis::Eruby.new(input)      # create Eruby object

## load YAML document as context object
<b>require 'yaml'</b>
<b>context = YAML.load_file('example7.yaml')</b>

puts <b>eruby.evaluate(context)</b>        # get result
</pre>
<div class="terminal_caption">
output</div>
<pre class="terminal">$ ruby example7.rb
&lt;h1&gt;Users List&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;a href="mailto:foo@mail.com"&gt;foo&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href="mailto:bar@mail.net"&gt;bar&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href="mailto:baz@mail.org"&gt;baz&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>It is able to specify YAML data file with the command-line option '-f'.
You don't have to write ruby script such as 'example7.rb'.
</p>
<div class="terminal_caption">
example of command-line option '-f'</div>
<pre class="terminal">$ erubis <b>-f example7.yaml</b> example7.eruby
&lt;h1&gt;Users List&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;a href="mailto:foo@mail.com"&gt;foo&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href="mailto:bar@mail.net"&gt;bar&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href="mailto:baz@mail.org"&gt;baz&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Command-line option '-S' converts keys of mapping in YAML data file from string into symbol.
Command-line option '-X' use Erubis::Context as context object.
</p>
<br>


<a name="Preamble and Postamble"></a>
<h3 class="section2">Preamble and Postamble</h3>
<p>The first line ('_out = [];') in the compiled source code is called preamble
and the last line ('_out.join') is called postamble.
</p>
<p>You can specify Eruby not to print preamble nor postamble with option :preamble and :postamble.
</p>
<a name="example8.eruby"></a>
<div class="program_caption">
example8.eruby</div>
<pre class="program">&lt;% for item in list %&gt;
 &lt;b&gt;&lt;%= item %&gt;&lt;/b&gt;
&lt;% end %&gt;
</pre>
<a name="example8.rb"></a>
<div class="program_caption">
example8.rb</div>
<pre class="program">require 'erubis'
input = File.read('example8.eruby')
eruby1 = Erubis::Eruby.new(input)
eruby2 = Erubis::Eruby.new(input, <b>:preamble=&gt;false, :postamble=&gt;false</b>)

puts eruby1.src   # print preamble and postamble
puts "--------------"
puts eruby2.src   # don't print preamble and postamble
</pre>
<div class="terminal_caption">
output</div>
<pre class="terminal">$ ruby example8.rb
_out = []; for item in list 
; _out &lt;&lt; ' &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
'; end 
;
_out.join
--------------
 for item in list 
; _out &lt;&lt; ' &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
'; end 
;
</pre>
<p>The command-line option '-b' specify both :preamble and :postamble to false.
</p>
<br>


<br>


<a name="enhancer"></a>
<h2 class="section1">Enhancer</h2>
<p>Enhancer is a module to add a certain feature into Erubis::Eruby class.
Enhancer may be language-independent or only for Eruby.
</p>
<p>To use enhancers, define subclass and include them.
The folloing is an example to use <a href="#escape-enhancer">EscapeEnhancer</a>, <a href="#percentline-enhancer">PercentLineEnhancer</a>, and <a href="#bipattern-enhancer">BiPatternEnhancer</a>.
</p>
<pre class="program">class MyEruby &lt; Erubis::Eruby
  include EscapeEnhancer
  include PercentLineEnhancer
  include BiPatternEnhancer
end
</pre>
<p>You can specify enhancers in command-line with option '-e'.
The following is an example to use some enhancers in command-line.
</p>
<pre class="terminal">$ erubis -l ruby -e Escape,PercentLine,BiPattern example.eruby
</pre>
<p>The following is the list of enhancers.
</p>
<dl class="dl1">
<dt class="dt1">
<b>EscapeEnhander</b> (language-independent)</dt>
<dd class="dd1">
	Switch '&lt;%= %&gt;' to escaped and '&lt;%== %&gt;' to unescaped.
</dd>
<dt class="dt1">
<b>StdoutEnhancer</b> (only for Eruby)</dt>
<dd class="dd1">
	Use $stdout instead of array buffer.
</dd>
<dt class="dt1">
<b>PrintOutEnhancer</b> (only for Eruby)</dt>
<dd class="dd1">
	Use "print(...)" statement insead of "_out &lt;&lt; ...".
</dd>
<dt class="dt1">
<b>PrintEnabledEnhancer</b> (only for Eruby)</dt>
<dd class="dd1">
	Enable to use print() in '&lt;% ... %&gt;'.
</dd>
<dt class="dt1">
<b>ArrayEnhancer</b> (only for Eruby)</dt>
<dd class="dd1">
	Return array of string instead of returning string.
</dd>
<dt class="dt1">
<b>ArrayBufferEnhancer</b> (only for Eruby)</dt>
<dd class="dd1">
	Use array buffer. This is included in Erubis::Eruby by default.
</dd>
<dt class="dt1">
<b>StringBufferEnhancer</b> (only for Eruby)</dt>
<dd class="dd1">
	Use string buffer. It is a little slower than ArrayBufferEnhancer.
</dd>
<dt class="dt1">
<b>SimplifiedEnhancer</b> (language-independent)</dt>
<dd class="dd1">
	Make compile faster but don't trim spaces around '&lt;% %&gt;'.
</dd>
<dt class="dt1">
<b>BiPatternEnhancer</b> (language-independent)</dt>
<dd class="dd1">
	[experimental] Enable to use another embedded pattern with '&lt;% %&gt;'.
</dd>
<dt class="dt1">
<b>PercentLineEnhancer</b> (language-independent)</dt>
<dd class="dd1">
	Regard lines starting with '%' as Ruby code. This is for compatibility with eruby and ERB.
</dd>
<dt class="dt1">
<b>HeaderFooterEnhancer</b> (language-independent)</dt>
<dd class="dd1">
	[experimental] Enable you to add header and footer in eRuby script.
</dd>
</dl>
<p>If you required 'erubis/engine/enhanced', Eruby subclasses which include each enhancers are defined.
For example, class BiPatternEruby includes BiPatternEnhancer.
</p>
<a name="escape-enhander"></a>
<h3 class="section2">EscapeEnhancer</h3>
<p>EscapeEnhancer switches '&lt;%= ... %&gt;' to escaped and '&lt;%== ... %&gt;' to unescaped.
</p>
<a name="example.eruby"></a>
<div class="program_caption">
example.eruby</div>
<pre class="program">&lt;% for item in list %&gt;
  &lt;b&gt;&lt;%= item %&gt;&lt;/b&gt;
  &lt;b&gt;&lt;%== item %&gt;&lt;/b&gt;
&lt;% end %&gt;
</pre>
<a name="escape-enhancer-test.rb"></a>
<div class="program_caption">
escape-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class EscapedEruby &lt; Erubis::Eruby
  include Erubis::EscapeEnhancer
end
eruby = EscapedEruby.new(File.read('example.eruby'))
print eruby.src
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby escape-enhancer-test.rb
_out = []; for item in list 
; _out &lt;&lt; '  &lt;b&gt;'; _out &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _out &lt;&lt; '&lt;/b&gt;
  &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
'; end 
;
_out.join
</pre>
<p>EscapeEnhancer is language-independent.
</p>
<br>


<a name="stdout-enhancer"></a>
<h3 class="section2">StdoutEnhancer</h3>
<p>StdoutEnhancer use $sdtdout instead of array buffer.
Therefore, you can use 'print' statement in embedded ruby code.
</p>
<a name="stdout-enhancer-test.rb"></a>
<div class="program_caption">
stdout-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class StdoutEruby &lt; Erubis::Eruby
  include Erubis::StdoutEnhancer
end
eruby = StdoutEruby.new(File.read('example.eruby'))
print eruby.src
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby stdout-enhancer-test.rb
_out = $stdout; for item in list 
; _out &lt;&lt; '  &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
  &lt;b&gt;'; _out &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _out &lt;&lt; '&lt;/b&gt;
'; end 
;
''
</pre>
<p>StdoutEnhancer is only for Eruby.
</p>
<br>


<a name="printout-enhancer"></a>
<h3 class="section2">PrintOutEnhancer</h3>
<p>PrintOutEnhancer makes compiled source code to use 'print(...)' instead of '_out &lt;&lt; ...'.
</p>
<a name="printstatement-enhancer-test.rb"></a>
<div class="program_caption">
printstatement-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class PrintOutEruby &lt; Erubis::Eruby
  include Erubis::PrintOutEnhancer
end
eruby = PrintOutEruby.new(File.read('example.eruby'))
print eruby.src
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby printstatement-enhancer-test.rb
 for item in list 
; print '  &lt;b&gt;'; print(( item ).to_s); print '&lt;/b&gt;
  &lt;b&gt;'; print Erubis::XmlHelper.escape_xml( item ); print '&lt;/b&gt;
'; end 
;
</pre>
<p>PrintOutEnhancer is only for Eruby.
</p>
<br>


<a name="printenabled-enhancer"></a>
<h3 class="section2">PrintEnabledEnhancer</h3>
<p>PrintEnabledEnhancer enables you to use print() method in '&lt;% ... %&gt;'.
</p>
<a name="printenabled-enhancer-test.eruby"></a>
<div class="program_caption">
printenabled-enhancer-test.eruby</div>
<pre class="program">&lt;% for item in list %&gt;
  &lt;b&gt;<b>&lt;% print item %&gt;</b>&lt;/b&gt;
&lt;% end %&gt;
</pre>
<a name="printenabled-enhancer-test.rb"></a>
<div class="program_caption">
printenabled-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class PrintEnabledEruby &lt; Erubis::Eruby
  include Erubis::PrintEnabledEnhancer
end
input = File.read('printenabled-enhancer-test.eruby')
eruby = PrintEnabledEruby.new(input)
list = ['aaa', 'bbb', 'ccc']
print eruby.evaluate(:list=&gt;list)
</pre>
<div class="terminal_caption">
output result</div>
<pre class="terminal">$ ruby printenabled-enhancer-test.rb
  &lt;b&gt;aaa&lt;/b&gt;
  &lt;b&gt;bbb&lt;/b&gt;
  &lt;b&gt;ccc&lt;/b&gt;
</pre>
<p>Notice to use Eruby#evaluate() and not to use Eruby#result(),
because print() method in '&lt;% ... %&gt;' invokes not Kernel#print() but PrintEnabledEnhancer#print().
</p>
<p>PrintEnabledEnhancer is only for Eruby.
</p>
<br>


<a name="array-enhancer"></a>
<h3 class="section2">ArrayEnhancer</h3>
<p>ArrayEnhancer makes Eruby to return an array of strings.
</p>
<a name="array-enhancer-test.rb"></a>
<div class="program_caption">
array-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class ArrayEruby &lt; Erubis::Eruby
  include Erubis::ArrayEnhancer
end
eruby = ArrayEruby.new(File.read('example.eruby'))
print eruby.src
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby array-enhancer-test.rb
_out = []; for item in list 
; _out &lt;&lt; '  &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
  &lt;b&gt;'; _out &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _out &lt;&lt; '&lt;/b&gt;
'; end 
;
_out
</pre>
<p>ArrayEnhancer is only for Eruby.
</p>
<br>


<a name="arraybuffer-enhancer"></a>
<h3 class="section2">ArrayBufferEnhancer</h3>
<p>Arraybufferenhancer makes Eruby to use array buffer.
Array buffer is a litte faster than String buffer.
Erubis::Eruby includes this enhancer by default.
</p>
<p>ArrayBufferEnhancer is only for Eruby.
</p>
<br>


<a name="stringbuffer-enhancer"></a>
<h3 class="section2">StringBufferEnhancer</h3>
<p>StringBufferEnhancer makes Eruby to use string buffer.
</p>
<a name="stringbuffer-enhancer-test.rb"></a>
<div class="program_caption">
stringbuffer-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class StringBufferEruby &lt; Erubis::Eruby
  include Erubis::StringBufferEnhancer
end
eruby = StringBufferEruby.new(File.read('example.eruby'))
print eruby.src
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby stringbuffer-enhancer-test.rb
_out = ''; for item in list 
; _out &lt;&lt; '  &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
  &lt;b&gt;'; _out &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _out &lt;&lt; '&lt;/b&gt;
'; end 
;
_out
</pre>
<br>


<a name="simplify-enhancer"></a>
<h3 class="section2">SimplifyEnhancer</h3>
<p>SimplifyEnhancer makes compiling a little faster but don't trim spaces around '&lt;% %&gt;'.
</p>
<a name="simplify-enhancer-test.rb"></a>
<div class="program_caption">
simplify-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class SimplifiedEruby &lt; Erubis::Eruby
  include Erubis::SimplifyEnhancer
end
eruby = SimplifiedEruby.new(File.read('example.eruby'))
print eruby.src
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby simplify-enhancer-test.rb
_out = []; for item in list ; _out &lt;&lt; '
  &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
  &lt;b&gt;'; _out &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _out &lt;&lt; '&lt;/b&gt;
'; end ; _out &lt;&lt; '
';
_out.join
</pre>
<br>


<a name="bipattern-enhancer"></a>
<h3 class="section2">BiPatternEnhancer</h3>
<p>BiPatternEnhancer enables to use another embedded pattern with '&lt;% %&gt;'.
By Default, '[= ... =]' is available for expression.
You can specify pattern by :bipattern property.
</p>
<a name="bipattern-enhancer-test.rb"></a>
<div class="program_caption">
bipattern-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class BiPatternEruby &lt; Erubis::Eruby
  include Erubis::BiPatternEnhancer
end

input = File.read('bipattern-enhancer-test.rhtml')
eruby = BiPatternEruby.new(input)
print eruby.src
</pre>
<a name="bipattern-enhancer-test.rhtml"></a>
<div class="program_caption">
bipattern-enhancer-test.rhtml</div>
<pre class="program">&lt;% for item in list %&gt;
  &lt;b&gt;<b>[= item =]</b>&lt;/b&gt;
  &lt;b&gt;<b>[== item =]</b>&lt;/b&gt;
&lt;% end %&gt;
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby bipattern-enhancer-test.rb
_out = []; for item in list 
; _out &lt;&lt; '  &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
  &lt;b&gt;'; _out &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _out &lt;&lt; '&lt;/b&gt;
'; end 
;
_out.join
</pre>
<p>BiPatternEnhancer is language-independent.
</p>
<br>


<a name="percentline-enhancer"></a>
<h3 class="section2">PercentLineEnhancer</h3>
<p>PercentLineEnhancer regards lines starting with '%' as Ruby code.
This is for compatibility with eruby and ERB.
</p>
<a name="percentline-enhancer-test.rb"></a>
<div class="program_caption">
percentline-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class PercentLineEruby &lt; Erubis::Eruby
  include Erubis::PercentLineEnhancer
end

input = File.read('percentline-enhancer-test.rhtml')
eruby = PercentLineEruby.new(input)
print eruby.src
</pre>
<a name="percentline-enhancer-test.rhtml"></a>
<div class="program_caption">
percentline-enhancer-test.rhtml</div>
<pre class="program"><b>% for item in list</b>
  &lt;b&gt;&lt;%= item %&gt;&lt;/b&gt;
<b>% end</b>
%% lines with '%%'
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby percentline-enhancer-test.rb
_out = []; for item in list
; _out &lt;&lt; '  &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
'; end
; _out &lt;&lt; '% lines with \'%%\'
';
_out.join
</pre>
<p>PercentLineEnhancer is language-independent.
</p>
<br>


<a name="headerfooter-enhancer"></a>
<h3 class="section2">HeaderFooterEnhancer</h3>
<p>[experimental]
</p>
<p>HeaderFooterEnhancer enables you to add header and footer in eRuby script.
</p>
<a name="headerfooter-enhancer-test.rb"></a>
<div class="program_caption">
headerfooter-enhancer-test.rb</div>
<pre class="program">require 'erubis'
class HeaderFooterEruby &lt; Erubis::Eruby
  include Erubis::HeaderFooterEnhancer
end

input = File.read('headerfooter-enhancer-test.eruby')
eruby = HeaderFooterEruby.new(input)
print eruby.src
</pre>
<a name="headerfooter-enhancer-test.eruby"></a>
<div class="program_caption">
headerfooter-enhancer-test.eruby</div>
<pre class="program"><b>&lt;!--#header:</b>
<b>def list_items(items)</b>
<b>#--&gt;</b>
&lt;% for item in items %&gt;
  &lt;b&gt;&lt;%= item %&gt;&lt;/b&gt;
&lt;% end %&gt;
<b>&lt;!--#footer:</b>
<b>end</b>
<b>#--&gt;</b>
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby headerfooter-enhancer-test.rb

def list_items(items)

_out = []; for item in items 
; _out &lt;&lt; '  &lt;b&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/b&gt;
'; end 
;
_out.join

end

</pre>
<p>Compare to the following:
</p>
<a name="normal-eruby-test.eruby"></a>
<div class="program_caption">
normal-eruby-test.eruby</div>
<pre class="program"><b>&lt;%</b>
<b>def list_items(items)</b>
<b>%&gt;</b>
&lt;% for item in items %&gt;
&lt;li&gt;&lt;%= item %&gt;&lt;/li&gt;
&lt;% end %&gt;
<b>&lt;%</b>
<b>end</b>
<b>%&gt;</b>
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ erubis -s normal-eruby-test.eruby
_out = [];
def list_items(items)

; for item in items 
; _out &lt;&lt; '&lt;li&gt;'; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; '&lt;/li&gt;
'; end 
;
end

;
_out.join
</pre>
<p>Header and footer can be in any position in eRuby script,
that is, header is no need to be in the head of eRuby script.
</p>
<a name="headerfooter-enhancer-test2.rhtml"></a>
<div class="program_caption">
headerfooter-enhancer-test2.rhtml</div>
<pre class="program">&lt;?xml version="1.0"?&gt;
&lt;html&gt;
<b>&lt;!--#header:</b>
<b>def page(list)</b>
<b>#--&gt;</b>
 :
<b>&lt;!--#footer:</b>
<b>end</b>
<b>#--&gt;</b>
&lt;/html&gt;
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ ruby headerfooter-enhancer-test2.rb

def page(list)

_out = []; _out &lt;&lt; '&lt;?xml version="1.0"?&gt;
&lt;html&gt;
'; _out &lt;&lt; ' :
'; _out &lt;&lt; '&lt;/html&gt;
';
_out.join

end

</pre>
<p>HeaderFooterEnhancer is experimental and is language-independent.
</p>
<br>


<br>


<a name="lang"></a>
<h2 class="section1">Multi-Language</h2>
<p>Erubis supports the following language currently:
</p>
<ul type="disc">
<li>Ruby
</li>
<li>PHP
</li>
<li>C
</li>
<li>Java
</li>
<li>Scheme
</li>
<li>Perl
</li>
<li>JavaScript
</li>
</ul>
<a name="lang-php"></a>
<h3 class="section2">PHP</h3>
<a name="example.ephp"></a>
<div class="program_caption">
example.ephp</div>
<pre class="program">&lt;?xml version="1.0"?&gt;
&lt;html&gt;
 &lt;body&gt;
  &lt;p&gt;Hello <b>&lt;%= $user %&gt;</b>!&lt;/p&gt;
  &lt;table&gt;
   &lt;tbody&gt;
    <b>&lt;% $i = 0 %&gt;</b>
    <b>&lt;% foreach ($list as $item) { %&gt;</b>
    <b>&lt;%   $i++; %&gt;</b>
    &lt;tr bgcolor=<b>"&lt;%= $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;"</b>&gt;
     &lt;td&gt;<b>&lt;%= $i %&gt;</b>&lt;/td&gt;
     &lt;td&gt;<b>&lt;%== $item %&gt;</b>&lt;/td&gt;
    &lt;/tr&gt;
    &lt;% } %&gt;
   &lt;/tbody&gt;
  &lt;/table&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ erubis -l php example.ephp
&lt;&lt;?php ?&gt;?xml version="1.0"?&gt;
&lt;html&gt;
 &lt;body&gt;
  &lt;p&gt;Hello &lt;?php echo $user; ?&gt;!&lt;/p&gt;
  &lt;table&gt;
   &lt;tbody&gt;
&lt;?php     $i = 0 ?&gt;
&lt;?php     foreach ($list as $item) { ?&gt;
&lt;?php       $i++; ?&gt;
    &lt;tr bgcolor="&lt;?php echo $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'; ?&gt;"&gt;
     &lt;td&gt;&lt;?php echo $i; ?&gt;&lt;/td&gt;
     &lt;td&gt;&lt;?php echo htmlspecialchars($item); ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;?php     } ?&gt;
   &lt;/tbody&gt;
  &lt;/table&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<br>


<a name="lang-c"></a>
<h3 class="section2">C</h3>
<a name="example.ec"></a>
<div class="program_caption">
example.ec</div>
<pre class="program"><b>&lt;%
#include &lt;stdio.h&gt;

int main(int argc, char *argv[])
{
    int i;

%&gt;</b>
&lt;html&gt;
 &lt;body&gt;
  &lt;p&gt;Hello <b>&lt;%= "%s", argv[0] %&gt;</b>!&lt;/p&gt;
  &lt;table&gt;
   &lt;tbody&gt;
    <b>&lt;% for (i = 1; i &lt; argc; i++) { %&gt;</b>
    &lt;tr bgcolor="<b>&lt;%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %&gt;</b>"&gt;
      &lt;td&gt;<b>&lt;%= "%d", i %&gt;</b>&lt;/td&gt;
      &lt;td&gt;<b>&lt;%= "%s", argv[i] %&gt;</b>&lt;/td&gt;
    &lt;/tr&gt;
    <b>&lt;% } %&gt;</b>
   &lt;/tbody&gt;
  &lt;/table&gt;
 &lt;/body&gt;
&lt;/html&gt;
<b>&lt;%
    return 0; 
}
%&gt;</b>
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ erubis -l c example.ec
#line 1 "example.ec"

#include &lt;stdio.h&gt;

int main(int argc, char *argv[])
{
    int i;


fputs("&lt;html&gt;\n"
      " &lt;body&gt;\n"
      "  &lt;p&gt;Hello ", stdout); fprintf(stdout, "%s", argv[0]); fputs("!&lt;/p&gt;\n"
      "  &lt;table&gt;\n"
      "   &lt;tbody&gt;\n", stdout);
     for (i = 1; i &lt; argc; i++) { 
fputs("    &lt;tr bgcolor=\"", stdout); fprintf(stdout, i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); fputs("\"&gt;\n"
      "      &lt;td&gt;", stdout); fprintf(stdout, "%d", i); fputs("&lt;/td&gt;\n"
      "      &lt;td&gt;", stdout); fprintf(stdout, "%s", argv[i]); fputs("&lt;/td&gt;\n"
      "    &lt;/tr&gt;\n", stdout);
     } 
fputs("   &lt;/tbody&gt;\n"
      "  &lt;/table&gt;\n"
      " &lt;/body&gt;\n"
      "&lt;/html&gt;\n", stdout);

    return 0; 
}

</pre>
<a name="Example.ejava"></a>
<div class="program_caption">
Example.ejava</div>
<pre class="program"><b>&lt;%
import java.util.*;

public class Example {
  private String user;
  private String[] list;
  public example(String user, String[] list) {
    this.user = user;
    this.list = list;
  }

  public String view() {
%&gt;</b>
&lt;html&gt;
 &lt;body&gt;
  &lt;p&gt;Hello <b>&lt;%= user %&gt;</b>!&lt;/p&gt;
  &lt;table&gt;
   &lt;tbody&gt;
    <b>&lt;% for (int i = 0; i &lt; list.length; i++) { %&gt;</b>
    &lt;tr bgcolor=<b>"&lt;%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %&gt;"</b>&gt;
     &lt;td&gt;<b>&lt;%= i + 1 %&gt;</b>&lt;/td&gt;
     &lt;td&gt;<b>&lt;%== list[i] %&gt;</b>&lt;/td&gt;
    &lt;/tr&gt;
    <b>&lt;% } %&gt;</b>
   &lt;/tbody&gt;
  &lt;/table&gt;
 &lt;body&gt;
&lt;/html&gt;
<b>&lt;%
  }

  public static void main(String[] args) {
    String[] list = { "&lt;aaa&gt;", "b&amp;b", "\"ccc\"" };
    Example ex = Example.new("Erubis", list);
    System.out.print(ex.view());
  }

  public static String escape(String s) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i &lt; s.length(); i++) {
      char ch = s.charAt(i);
      switch (ch) {
      case '&lt;':   sb.append("&amp;lt;"); break;
      case '&gt;':   sb.append("&amp;gt;"); break;
      case '&amp;':   sb.append("&amp;amp;"); break;
      case '"':   sb.append("&amp;quot;"); break;
      default:    sb.append(ch);
      }
    }
    return sb.toString();
  }
}
%&gt;</b>
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ erubis -l java example.ejava
StringBuffer _out = new StringBuffer();
import java.util.*;

public class Example {
  private String user;
  private String[] list;
  public example(String user, String[] list) {
    this.user = user;
    this.list = list;
  }

  public String view() {

_out.append("&lt;html&gt;\n"
          + " &lt;body&gt;\n"
          + "  &lt;p&gt;Hello "); _out.append(user); _out.append("!&lt;/p&gt;\n"
          + "  &lt;table&gt;\n"
          + "   &lt;tbody&gt;\n");
     for (int i = 0; i &lt; list.length; i++) { 
_out.append("    &lt;tr bgcolor=\""); _out.append(i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); _out.append("\"&gt;\n"
          + "     &lt;td&gt;"); _out.append(i + 1); _out.append("&lt;/td&gt;\n"
          + "     &lt;td&gt;"); _out.append(escape(list[i])); _out.append("&lt;/td&gt;\n"
          + "    &lt;/tr&gt;\n");
     } 
_out.append("   &lt;/tbody&gt;\n"
          + "  &lt;/table&gt;\n"
          + " &lt;body&gt;\n"
          + "&lt;/html&gt;\n");

  }

  public static void main(String[] args) {
    String[] list = { "&lt;aaa&gt;", "b&amp;b", "\"ccc\"" };
    Example ex = Example.new("Erubis", list);
    System.out.print(ex.view());
  }

  public static String escape(String s) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i &lt; s.length(); i++) {
      char ch = s.charAt(i);
      switch (ch) {
      case '&lt;':   sb.append("&amp;lt;"); break;
      case '&gt;':   sb.append("&amp;gt;"); break;
      case '&amp;':   sb.append("&amp;amp;"); break;
      case '"':   sb.append("&amp;quot;"); break;
      default:    sb.append(ch);
      }
    }
    return sb.toString();
  }
}

return _out.toString();
</pre>
<br>


<a name="lang-scheme"></a>
<h3 class="section2">Scheme</h3>
<a name="example.escheme"></a>
<div class="program_caption">
example.escheme</div>
<pre class="program">&lt;html&gt;
 &lt;body&gt;
<b>&lt;%
(let ((user "Erubis")
      (items '("&lt;aaa&gt;" "b&amp;b" "\"ccc\""))
      (i 0))
 %&gt;</b>
  &lt;p&gt;Hello <b>&lt;%= user %&gt;</b>!&lt;/p&gt;
  &lt;table&gt;
<b>&lt;%
  (for-each
   (lambda (item)
     (set! i (+ i 1))
 %&gt;</b>
   &lt;tr bgcolor="<b>&lt;%= (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF") %&gt;</b>"&gt;
    &lt;td&gt;<b>&lt;%= i %&gt;</b>&lt;/td&gt;
    &lt;td&gt;<b>&lt;%= item %&gt;</b>&lt;/td&gt;
   &lt;/tr&gt;
<b>&lt;%
   ) ; lambda end
   items) ; for-each end
 %&gt;</b>
  &lt;/table&gt;
<b>&lt;%
) ; let end
%&gt;</b>
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ erubis -l scheme example.escheme
(let ((_out '())) (define (_add x) (set! _out (cons x _out))) (_add "&lt;html&gt;
 &lt;body&gt;\n")

(let ((user "Erubis")
      (items '("&lt;aaa&gt;" "b&amp;b" "\"ccc\""))
      (i 0))
 
(_add "  &lt;p&gt;Hello ")(_add user)(_add "!&lt;/p&gt;
  &lt;table&gt;\n")

  (for-each
   (lambda (item)
     (set! i (+ i 1))
 
(_add "   &lt;tr bgcolor=\"")(_add (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF"))(_add "\"&gt;
    &lt;td&gt;")(_add i)(_add "&lt;/td&gt;
    &lt;td&gt;")(_add item)(_add "&lt;/td&gt;
   &lt;/tr&gt;\n")

   ) ; lambda end
   items) ; for-each end
 
(_add "  &lt;/table&gt;\n")

) ; let end

(_add " &lt;/body&gt;
&lt;/html&gt;\n")
  (reverse _out))
</pre>
<div class="terminal_caption">
compiled source code (with --func=display property)</div>
<pre class="terminal">$ erubis -l scheme --func=display example.escheme
(display "&lt;html&gt;
 &lt;body&gt;\n")

(let ((user "Erubis")
      (items '("&lt;aaa&gt;" "b&amp;b" "\"ccc\""))
      (i 0))
 
(display "  &lt;p&gt;Hello ")(display user)(display "!&lt;/p&gt;
  &lt;table&gt;\n")

  (for-each
   (lambda (item)
     (set! i (+ i 1))
 
(display "   &lt;tr bgcolor=\"")(display (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF"))(display "\"&gt;
    &lt;td&gt;")(display i)(display "&lt;/td&gt;
    &lt;td&gt;")(display item)(display "&lt;/td&gt;
   &lt;/tr&gt;\n")

   ) ; lambda end
   items) ; for-each end
 
(display "  &lt;/table&gt;\n")

) ; let end

(display " &lt;/body&gt;
&lt;/html&gt;\n")
</pre>
<br>


<a name="lang-perl"></a>
<h3 class="section2">Perl</h3>
<a name="example.eperl"></a>
<div class="program_caption">
example.eprl</div>
<pre class="program"><b>&lt;%
   my $user = 'Erubis';
   my @list = ('&lt;aaa&gt;', 'b&amp;b', '"ccc"');
%&gt;</b>
&lt;html&gt;
 &lt;body&gt;
  &lt;p&gt;Hello <b>&lt;%= $user %&gt;</b>!&lt;/p&gt;
  &lt;table&gt;
   <b>&lt;% $i = 0; %&gt;</b>
   <b>&lt;% for $item (@list) { %&gt;</b>
   &lt;tr bgcolor=<b>&lt;%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;</b>"&gt;
    &lt;td&gt;<b>&lt;%= $i %&gt;</b>&lt;/td&gt;
    &lt;td&gt;<b>&lt;%= $item %&gt;</b>&lt;/td&gt;
   &lt;/tr&gt;
   <b>&lt;% } %&gt;</b>
  &lt;/table&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ erubis -l perl example.eperl

   my $user = 'Erubis';
   my @list = ('&lt;aaa&gt;', 'b&amp;b', '"ccc"');

print('&lt;html&gt;
 &lt;body&gt;
  &lt;p&gt;Hello '); print($user); print('!&lt;/p&gt;
  &lt;table&gt;
');     $i = 0; 
    for $item (@list) { 
print('   &lt;tr bgcolor='); print(++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); print('"&gt;
    &lt;td&gt;'); print($i); print('&lt;/td&gt;
    &lt;td&gt;'); print($item); print('&lt;/td&gt;
   &lt;/tr&gt;
');     } 
print('  &lt;/table&gt;
 &lt;/body&gt;
&lt;/html&gt;
'); 
</pre>
<br>


<a name="lang-javascript"></a>
<h3 class="section2">JavaScript</h3>
<p>example.ejs
</p>
<a name="example.ejs"></a>
<pre class="program"><b>&lt;%
   var user = 'Erubis';
   var list = ['&lt;aaa&gt;', 'b&amp;b', '"ccc"'];
 %&gt;</b>
&lt;html&gt;
 &lt;body&gt;
  &lt;p&gt;Hello <b>&lt;%= user %&gt;</b>!&lt;/p&gt;
  &lt;table&gt;
   &lt;tbody&gt;
    <b>&lt;% var i; %&gt;</b>
    <b>&lt;% for (i = 0; i &lt; list.length; i++) { %&gt;</b>
    &lt;tr bgcolor="<b>&lt;%= i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;</b>"&gt;
     &lt;td&gt;<b>&lt;%= i + 1 %&gt;</b>&lt;/td&gt;
     &lt;td&gt;<b>&lt;%= list[i] %&gt;</b>&lt;/td&gt;
    &lt;/tr&gt;
    <b>&lt;% } %&gt;</b>
   &lt;/tbody&gt;
  &lt;/table&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<div class="terminal_caption">
compiled source code</div>
<pre class="terminal">$ erubis -l js example.ejs
_out = [];
   var user = 'Erubis';
   var list = ['&lt;aaa&gt;', 'b&amp;b', '"ccc"'];
 
_out.push("&lt;html&gt;\n\
 &lt;body&gt;\n\
  &lt;p&gt;Hello "); _out.push(user); _out.push("!&lt;/p&gt;\n\
  &lt;table&gt;\n\
   &lt;tbody&gt;\n");
     var i; 
     for (i = 0; i &lt; list.length; i++) { 
_out.push("    &lt;tr bgcolor=\""); _out.push(i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _out.push("\"&gt;\n\
     &lt;td&gt;"); _out.push(i + 1); _out.push("&lt;/td&gt;\n\
     &lt;td&gt;"); _out.push(list[i]); _out.push("&lt;/td&gt;\n\
    &lt;/tr&gt;\n");
     } 
_out.push("   &lt;/tbody&gt;\n\
  &lt;/table&gt;\n\
 &lt;/body&gt;\n\
&lt;/html&gt;\n");
document.write(_out.join(""));
</pre>
<br>


<br>


<a name="Benchmark"></a>
<h2 class="section1">Benchmark</h2>
<p>A benchmark script is included in Erubis package at erubis-X.X.X/benchark directory.
Here is an example result of benchmark.
</p>
<div class="output_caption">
Env: Linux FedoraCore4, Celeron 667MHz, Mem512MB, Ruby1.8.4</div>
<pre class="output">                                        user     system      total        real
ERuby                             138.280000   1.900000 140.180000 (141.470426)
ERB                               402.220000   3.190000 405.410000 (408.886894)
Erubis::Eruby                     147.080000   2.400000 149.480000 (150.752255)
Erubis::StringBufferEruby         186.130000   2.600000 188.730000 (190.374098)
Erubis::SimplifiedEruby           130.100000   2.210000 132.310000 (133.426010)
Erubis::StdoutEruby               106.010000   2.130000 108.140000 (108.999193)
Erubis::StdoutSimplifiedEruby      97.130000   2.180000  99.310000 (100.104433)
Erubis::PrintOutEruby             109.900000   2.090000 111.990000 (112.854442)
Erubis::PrintOutSimplifiedEruby    93.120000   2.140000  95.260000 ( 96.002970)
Erubis::TinyEruby                 118.740000   2.360000 121.100000 (122.141380)
Erubis::TinyStdoutEruby            86.140000   1.840000  87.980000 ( 88.679196)
Erubis::TinyPrintEruby             86.540000   1.970000  88.510000 ( 89.208078)
</pre>
<div class="output_caption">
Env: MacOS X 10.4, PowerPC 1.42GHz, Mem1.5GB, Ruby1.8.4</div>
<pre class="output">                                        user     system      total        real
ERuby                              55.040000   2.120000  57.160000 ( 89.311397)
ERB                               103.960000   3.480000 107.440000 (159.231792)
Erubis::Eruby                      36.130000   1.570000  37.700000 ( 52.188574)
Erubis::StringBufferEruby          47.270000   1.980000  49.250000 ( 73.867537)
Erubis::SimplifiedEruby            34.310000   1.600000  35.910000 ( 51.762841)
Erubis::StdoutEruby                26.240000   1.490000  27.730000 ( 41.840430)
Erubis::StdoutSimplifiedEruby      25.380000   1.340000  26.720000 ( 37.231918)
Erubis::PrintOutEruby              26.850000   1.260000  28.110000 ( 38.378227)
Erubis::PrintOutSimplifiedEruby    24.160000   1.280000  25.440000 ( 40.048199)
Erubis::TinyEruby                  31.690000   1.590000  33.280000 ( 49.862091)
Erubis::TinyStdoutEruby            22.550000   1.230000  23.780000 ( 33.316978)
Erubis::TinyPrintEruby             22.340000   1.150000  23.490000 ( 33.577150)
</pre>
<p>This shows that:
</p>
<ul type="disc">
<li>Erubis::Eruby is about 2.7 or 2.9 times faster than ERB.
</li>
<li>Erubis::Eruby is about 6% slower in linux or 1.5 times faster than ERuby in Mac.
</li>
<li>Erubis::SimplifiedEruby (which incudes SimplifiedEnhander) is faster than ERuby.
</li>
<li>String buffer (StringBufferEnhancer) is slower than array buffer (ArrayBufferEnhancer which Erubis::Eruby includes)
</li>
<li>Using print statement or $stdout is faster than array buffer and string buffer.
</li>
<li>Erubis::TinyEruby (at 'erubis/tiny.rb') and it's subclasses are the fastest in all eRuby implementation.
</li>
</ul>
<br>


<a name="command"></a>
<h2 class="section1">Command Reference</h2>
<a name="command-usage"></a>
<h3 class="section2">Usage</h3>
<p>erubis [-hvsT] [-p <i>pattern</i>] [-c <i>class</i>] [-K <i>kanji</i>] [-f <i>file.yaml</i>] [<i>file</i> ...]
</p>
<br>


<a name="command-options"></a>
<h3 class="section2">Options</h3>
  <dl class="dl3" compact>
  <dt class="dt3"><b>
-h, --help    </b></dt>
  <dd class="dd3">
  	Help.
  </dd>
  <dt class="dt3"><b>
-v            </b></dt>
  <dd class="dd3">
  	Release version.
  </dd>
  <dt class="dt3"><b>
-s            </b></dt>
  <dd class="dd3">
  	Show script source.
  </dd>
  <dt class="dt3"><b>
-x            </b></dt>
  <dd class="dd3">
  	Show script source, removing the last '_out' line.
  </dd>
  <dt class="dt3"><b>
-T            </b></dt>
  <dd class="dd3">
  	No trimming spaces around '&lt;% %&gt;'.
			This is equivarent to '--trim=false'.
  </dd>
  <dt class="dt3"><b>
-b            </b></dt>
  <dd class="dd3">
  	Body only (no preamble nor postamble).
			This is equivarent to '--preamble=false --postamble=false'.
  </dd>
  <dt class="dt3"><b>
-p pattern    </b></dt>
  <dd class="dd3">
  	Embedded pattern (default '&lt;% %&gt;').
			This is equivarent to '--pattern=<i>pattern</i>'.
  </dd>
  <dt class="dt3"><b>
-l lang       </b></dt>
  <dd class="dd3">
  	Language name.
			This option makes erubis command to compile script but no execute.
  </dd>
  <dt class="dt3"><b>
-c class      </b></dt>
  <dd class="dd3">
  	Class name (Eruby, XmlEruby, ...) to compile. (default Eruby).
  </dd>
  <dt class="dt3"><b>
-e enhacers   </b></dt>
  <dd class="dd3">
  	Enhancer name (Escape, PercentLine, ...).
			It is able to specify several enhancer name separating with ','
			(ex. -f Escape,PercentLine,HeaderFooter).
  </dd>
  <dt class="dt3"><b>
-E            </b></dt>
  <dd class="dd3">
  	Show all enhancers.
  </dd>
  <dt class="dt3"><b>
-I path       </b></dt>
  <dd class="dd3">
  	Require library path ($:).
			It is able to specify several paths separating with ','
			(ex. -f path1,path2,path3).
  </dd>
  <dt class="dt3"><b>
-K kanji      </b></dt>
  <dd class="dd3">
  	Kanji code (euc, sjis, utf8, or none) (default none).
  </dd>
  <dt class="dt3"><b>
-f file.yaml  </b></dt>
  <dd class="dd3">
  	YAML file for context values (read stdin if filename is '-').
			It is able to specify several filenames separating with ','
			(ex. -f file1,file2,file3).
  </dd>
  <dt class="dt3"><b>
-t            </b></dt>
  <dd class="dd3">
  	Expand tab character in YAML file.
  </dd>
  <dt class="dt3"><b>
-S            </b></dt>
  <dd class="dd3">
  	Convert mapping key from string to symbol in YAML file.
  </dd>
  </dl>
<br>


<a name="command-props"></a>
<h3 class="section2">Properties</h3>
<p>Some Eruby classes can take optional properties to change it's compile option.
For example, property '--indent="  "' may change indentation of compiled source code.
Try 'eruby -h' for details.
</p>
<br>


<br>



   </div>
  </blockquote>

 </body>
</html>