erubis 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +9 -1
- data/README +1 -1
- data/bin/erubis +2 -2
- data/doc/users-guide.html +162 -46
- data/lib/erubis.rb +59 -9
- data/test/test-bin.rb +4 -4
- data/test/test-erubis.rb +103 -27
- metadata +6 -4
data/ChangeLog
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# $Rev$
|
2
|
-
# $Release: 1.0
|
2
|
+
# $Release: 1.1.0 $
|
3
3
|
# copyright(c) 2006 kuwata-lab all rights reserved.
|
4
4
|
|
5
|
+
- release: 1.1
|
6
|
+
date: 205-03-05
|
7
|
+
desc:
|
8
|
+
- tag: enhance
|
9
|
+
text: '<%# ... %>' is supported
|
10
|
+
- tag: enhance
|
11
|
+
text: PrintEnhancer, PrintEruby, and PrintXmlEruby added
|
12
|
+
|
5
13
|
- release: 1.0.1
|
6
14
|
date: 2005-02-01
|
7
15
|
desc:
|
data/README
CHANGED
data/bin/erubis
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
###
|
4
4
|
### $Rev: 4 $
|
5
|
-
### $Release: 1.0
|
5
|
+
### $Release: 1.1.0 $
|
6
6
|
### copyright(c) 2006 kuwata-lab all rights reserved.
|
7
7
|
###
|
8
8
|
|
@@ -113,7 +113,7 @@ END
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def version
|
116
|
-
release = ('$Release: 1.0
|
116
|
+
release = ('$Release: 1.1.0 $' =~ /([.\d]+)/) && $1
|
117
117
|
return release
|
118
118
|
end
|
119
119
|
|
data/doc/users-guide.html
CHANGED
@@ -23,14 +23,16 @@
|
|
23
23
|
It has the following features.
|
24
24
|
</p>
|
25
25
|
<ul type="disc">
|
26
|
-
<li>Auto
|
26
|
+
<li>Auto sanitizing support
|
27
27
|
</li>
|
28
|
-
<li>Auto
|
28
|
+
<li>Auto trimming spaces around '<% %>'
|
29
29
|
</li>
|
30
|
-
<li>
|
30
|
+
<li>Embedded pattern changeable (default '<% %>')
|
31
31
|
</li>
|
32
32
|
<li>Context object available
|
33
33
|
</li>
|
34
|
+
<li>Print statement available
|
35
|
+
</li>
|
34
36
|
<li>Easy to expand in subclass
|
35
37
|
</li>
|
36
38
|
</ul>
|
@@ -63,6 +65,8 @@ It has the following features.
|
|
63
65
|
</li>
|
64
66
|
<li><a href="#tut-stdout">Stdout Eruby</a>
|
65
67
|
</li>
|
68
|
+
<li><a href="#tut-print">Print Avairable Eruby</a>
|
69
|
+
</li>
|
66
70
|
</ul>
|
67
71
|
</li>
|
68
72
|
<li><a href="#command">Command Reference</a>
|
@@ -127,11 +131,12 @@ $ contrib/inline-require -I lib bin/erubis > contrib/erubis
|
|
127
131
|
<div class="program_caption">
|
128
132
|
example1.eruby</div>
|
129
133
|
<pre class="program"><ul>
|
130
|
-
<
|
134
|
+
<b><% for item in list %></b>
|
131
135
|
<li>
|
132
|
-
<
|
136
|
+
<b><%= item %></b>
|
133
137
|
</li>
|
134
|
-
<
|
138
|
+
<b><% end %></b>
|
139
|
+
<b><%# here is ignored because starting with '#' %></b>
|
135
140
|
</ul>
|
136
141
|
</pre>
|
137
142
|
<a name="example1.rb"></a>
|
@@ -140,16 +145,16 @@ example1.rb</div>
|
|
140
145
|
<pre class="program">## create Eruby object
|
141
146
|
require 'erubis'
|
142
147
|
input = File.read('example1.eruby')
|
143
|
-
eruby = <
|
148
|
+
eruby = <b>Erubis::Eruby.new(input)</b>
|
144
149
|
|
145
150
|
## print script source
|
146
151
|
puts "--- script source ---"
|
147
|
-
puts <
|
152
|
+
puts <b>eruby.src</b>
|
148
153
|
|
149
154
|
## get result
|
150
155
|
puts "--- result ---"
|
151
156
|
list = ['aaa', 'bbb', 'ccc']
|
152
|
-
puts <
|
157
|
+
puts <b>eruby.result(binding())</b>
|
153
158
|
</pre>
|
154
159
|
<div class="terminal_caption">
|
155
160
|
output</div>
|
@@ -161,6 +166,7 @@ _out << " <li>\n"
|
|
161
166
|
_out << " "; _out << ( item ).to_s; _out << "\n"
|
162
167
|
_out << " </li>\n"
|
163
168
|
end
|
169
|
+
|
164
170
|
_out << "</ul>\n"
|
165
171
|
_out
|
166
172
|
--- result ---
|
@@ -201,7 +207,7 @@ example2.rb</div>
|
|
201
207
|
<pre class="program">## create Eruby object
|
202
208
|
require 'erubis'
|
203
209
|
input = File.read('example2.eruby')
|
204
|
-
eruby = Erubis::Eruby.new(input<
|
210
|
+
eruby = Erubis::Eruby.new(input<b>, :trim=>false</b>)
|
205
211
|
|
206
212
|
## print script source
|
207
213
|
puts "--- script source ---"
|
@@ -217,11 +223,11 @@ output</div>
|
|
217
223
|
<pre class="terminal">$ ruby example2.rb
|
218
224
|
--- script source ---
|
219
225
|
_out = ''; _out << "<ul>\n"
|
220
|
-
<
|
226
|
+
<b>_out << " ";</b> for item in list <b>; _out << "\n"</b>
|
221
227
|
_out << " <li>\n"
|
222
228
|
_out << " "; _out << ( item ).to_s; _out << "\n"
|
223
229
|
_out << " </li>\n"
|
224
|
-
<
|
230
|
+
<b>_out << " ";</b> end <b>; _out << "\n"</b>
|
225
231
|
_out << "</ul>\n"
|
226
232
|
_out
|
227
233
|
--- result ---
|
@@ -251,13 +257,13 @@ _out
|
|
251
257
|
<p>Erubis::XmlEruby acts the following:
|
252
258
|
</p>
|
253
259
|
<ul type="disc">
|
254
|
-
<li><code><%= <
|
260
|
+
<li><code><%= <i>expr</i> %></code> will be sanitized.
|
255
261
|
</li>
|
256
|
-
<li><code><%== <
|
262
|
+
<li><code><%== <i>expr</i> %></code> will be out as it is.
|
257
263
|
</li>
|
258
|
-
<li><code><%=== <
|
264
|
+
<li><code><%=== <i>expr</i> %></code> will be out to $stderr.
|
259
265
|
</li>
|
260
|
-
<li><code><%==== <
|
266
|
+
<li><code><%==== <i>expr</i> %></code> will be ignored.
|
261
267
|
</li>
|
262
268
|
</ul>
|
263
269
|
<a name="example3.eruby"></a>
|
@@ -265,9 +271,9 @@ _out
|
|
265
271
|
example3.eruby</div>
|
266
272
|
<pre class="program"><ul>
|
267
273
|
<% for item in list %>
|
268
|
-
<li><
|
269
|
-
<li><
|
270
|
-
<li><
|
274
|
+
<li><b><%=</b> item <b>%></b></li>
|
275
|
+
<li><b><%==</b> item <b>%></b></li>
|
276
|
+
<li><b><%===</b> item <b>%></b></li>
|
271
277
|
|
272
278
|
<% end %>
|
273
279
|
</ul>
|
@@ -278,7 +284,7 @@ example3.rb</div>
|
|
278
284
|
<pre class="program">## create Eruby object
|
279
285
|
require 'erubis'
|
280
286
|
input = File.read('example3.eruby')
|
281
|
-
eruby = Erubis::<
|
287
|
+
eruby = Erubis::<b>XmlEruby</b>.new(input)
|
282
288
|
|
283
289
|
## print script source
|
284
290
|
puts "--- script source ---"
|
@@ -286,7 +292,7 @@ puts eruby.src
|
|
286
292
|
|
287
293
|
## get result
|
288
294
|
puts "--- result ---"
|
289
|
-
<
|
295
|
+
<b>list = ['<aaa>', 'b&b', '"ccc"']</b>
|
290
296
|
puts eruby.result(binding())
|
291
297
|
</pre>
|
292
298
|
<div class="terminal_caption">
|
@@ -295,24 +301,24 @@ output</div>
|
|
295
301
|
--- script source ---
|
296
302
|
_out = ''; _out << "<ul>\n"
|
297
303
|
for item in list
|
298
|
-
_out << " <li>"; <
|
304
|
+
_out << " <li>"; <b>_out << Erubis::XmlEruby.escape( item )</b>; _out << "</li>\n"
|
299
305
|
_out << " <li>"; _out << ( item ).to_s; _out << "</li>\n"
|
300
|
-
_out << " <li>"; <
|
306
|
+
_out << " <li>"; <b>$stderr.puts("** erubis: item = #{(item).inspect}")</b>; _out << "</li>\n"
|
301
307
|
_out << "\n"
|
302
308
|
end
|
303
309
|
_out << "</ul>\n"
|
304
310
|
_out
|
305
311
|
--- result ---
|
306
312
|
<ul>
|
307
|
-
<li><
|
313
|
+
<li><b>&lt;aaa&gt;</b></li>
|
308
314
|
<li><aaa></li>
|
309
315
|
<li></li>
|
310
316
|
|
311
|
-
<li><
|
317
|
+
<li><b>b&amp;b</b></li>
|
312
318
|
<li>b&b</li>
|
313
319
|
<li></li>
|
314
320
|
|
315
|
-
<li><
|
321
|
+
<li><b>&quot;ccc&quot;</b></li>
|
316
322
|
<li>"ccc"</li>
|
317
323
|
<li></li>
|
318
324
|
|
@@ -333,9 +339,9 @@ $ cat stderr.log
|
|
333
339
|
<div class="program_caption">
|
334
340
|
example4.eruby</div>
|
335
341
|
<pre class="program"><ul>
|
336
|
-
<
|
337
|
-
<li><
|
338
|
-
<
|
342
|
+
<b><!--%</b> for item in list <b>%--></b>
|
343
|
+
<li><b><!--%=</b> item <b>%--></b></li>
|
344
|
+
<b><!--%</b> end <b>%--></b>
|
339
345
|
</ul>
|
340
346
|
</pre>
|
341
347
|
<a name="example4.rb"></a>
|
@@ -344,7 +350,7 @@ example4.rb</div>
|
|
344
350
|
<pre class="program">## create Eruby object
|
345
351
|
require 'erubis'
|
346
352
|
input = File.read('example4.eruby')
|
347
|
-
eruby = Erubis::Eruby.new(input<
|
353
|
+
eruby = Erubis::Eruby.new(input<b>, :pattern=>'<!--% %-->'</b>)
|
348
354
|
# or '<(?:!--)?% %(?:--)?>'
|
349
355
|
|
350
356
|
## print script source
|
@@ -375,7 +381,7 @@ _out
|
|
375
381
|
</pre>
|
376
382
|
<p>It is able to specify regular expression with :pattern option.
|
377
383
|
Notice that you must use '<code>(?: )</code>' instead of '<code>( )</code>' for grouping.
|
378
|
-
For example, '<code><(!--)?% %(--)?></code>' will not work
|
384
|
+
For example, '<code><(!--)?% %(--)?></code>' will not work while '<code><(?:!--)?% %(?:--)?></code>' will work.
|
379
385
|
</p>
|
380
386
|
<br>
|
381
387
|
|
@@ -408,13 +414,13 @@ eruby = Erubis::Eruby.new(input)
|
|
408
414
|
|
409
415
|
## create context object
|
410
416
|
## (key means var name, which may be string or symbol.)
|
411
|
-
<
|
412
|
-
<
|
413
|
-
<
|
417
|
+
<b>context = {}</b>
|
418
|
+
<b>context[:val] = 'Erubis Example'</b>
|
419
|
+
<b>context['list'] = ['aaa', 'bbb', 'ccc']</b>
|
414
420
|
|
415
421
|
## get result
|
416
422
|
puts "--- result ---"
|
417
|
-
puts <
|
423
|
+
puts <b>eruby.evaluate(context)</b>
|
418
424
|
</pre>
|
419
425
|
<div class="terminal_caption">
|
420
426
|
output</div>
|
@@ -462,11 +468,11 @@ input = File.read('example6.eruby')
|
|
462
468
|
eruby = Erubis::Eruby.new(input)
|
463
469
|
|
464
470
|
## load YAML document as context object
|
465
|
-
<
|
466
|
-
<
|
471
|
+
<b>require 'yaml'</b>
|
472
|
+
<b>context = YAML.load_file('example6.yaml')</b>
|
467
473
|
|
468
474
|
## get result
|
469
|
-
puts <
|
475
|
+
puts <b>eruby.evaluate(context)</b>
|
470
476
|
</pre>
|
471
477
|
<div class="terminal_caption">
|
472
478
|
output</div>
|
@@ -516,7 +522,7 @@ puts "--- script source (Eruby) ---"
|
|
516
522
|
puts eruby.src
|
517
523
|
|
518
524
|
## print script source with FastEruby
|
519
|
-
eruby = Erubis::<
|
525
|
+
eruby = Erubis::<b>FastEruby</b>.new(input)
|
520
526
|
puts "--- script source (FastEruby) ---"
|
521
527
|
puts eruby.src
|
522
528
|
</pre>
|
@@ -546,6 +552,21 @@ _out << " </tbody>\n</table>\n"
|
|
546
552
|
|
547
553
|
_out
|
548
554
|
</pre>
|
555
|
+
<p>Here is the definition of FastEruby or FastXmlEruby.
|
556
|
+
They are subclass of Eruby and XmlEruby respectively and only include FastEnhancer module.
|
557
|
+
It shows that Erubis is extensible.
|
558
|
+
</p>
|
559
|
+
<div class="program_caption">
|
560
|
+
definition of FastEruby and FastXmlEruby</div>
|
561
|
+
<pre class="program">module Erubis
|
562
|
+
class FastEruby < Eruby
|
563
|
+
<b>include FastEnhancer</b>
|
564
|
+
end
|
565
|
+
class FastXmlEruby < XmlEruby
|
566
|
+
<b>include FastEnhancer</b>
|
567
|
+
end
|
568
|
+
end
|
569
|
+
</pre>
|
549
570
|
<br>
|
550
571
|
|
551
572
|
|
@@ -559,7 +580,7 @@ Therefore, you can use 'print' statement in embedded ruby code.
|
|
559
580
|
example8.eruby</div>
|
560
581
|
<pre class="program"><ul>
|
561
582
|
<% for item in list %>
|
562
|
-
<li><
|
583
|
+
<li><b><% print item %></b></li>
|
563
584
|
<% end %>
|
564
585
|
</ul>
|
565
586
|
</pre>
|
@@ -569,7 +590,7 @@ example8.rb</div>
|
|
569
590
|
<pre class="program">## create Eruby object
|
570
591
|
require 'erubis'
|
571
592
|
input = File.read('example8.eruby')
|
572
|
-
eruby = Erubis::<
|
593
|
+
eruby = Erubis::<b>StdoutEruby</b>.new(input)
|
573
594
|
|
574
595
|
## print script source
|
575
596
|
puts "--- script source ---"
|
@@ -579,18 +600,18 @@ puts eruby.src
|
|
579
600
|
puts "--- result ---"
|
580
601
|
list = ['aaa', 'bbb', 'ccc']
|
581
602
|
#puts eruby.result(binding())
|
582
|
-
<
|
603
|
+
<b>eruby.result(binding())</b> # returns nil
|
583
604
|
</pre>
|
584
605
|
<div class="terminal_caption">
|
585
606
|
output</div>
|
586
607
|
<pre class="terminal">$ ruby example8.rb
|
587
608
|
--- script source ---
|
588
|
-
<
|
609
|
+
<b>_out = $stdout</b>; _out << "<ul>\n"
|
589
610
|
for item in list
|
590
|
-
_out << " <li>"; <
|
611
|
+
_out << " <li>"; <b>print item</b> ; _out << "</li>\n"
|
591
612
|
end
|
592
613
|
_out << "</ul>\n"
|
593
|
-
nil
|
614
|
+
<b>nil</b>
|
594
615
|
--- result ---
|
595
616
|
<ul>
|
596
617
|
<li>aaa</li>
|
@@ -598,6 +619,101 @@ nil
|
|
598
619
|
<li>ccc</li>
|
599
620
|
</ul>
|
600
621
|
</pre>
|
622
|
+
<p>Here is the definition of StdoutEruby or StdoutXmlEruby.
|
623
|
+
They are subclass of Eruby and XmlEruby respectively and only include StdoutEnhancer module.
|
624
|
+
It shows that Erubis is extensible.
|
625
|
+
</p>
|
626
|
+
<div class="program_caption">
|
627
|
+
definition of StdoutEruby and StdoutXmlEruby</div>
|
628
|
+
<pre class="program">module Erubis
|
629
|
+
class StdoutEruby < Eruby
|
630
|
+
<b>include StdoutEnhancer</b>
|
631
|
+
end
|
632
|
+
class StdoutXmlEruby < XmlEruby
|
633
|
+
<b>include StdoutEnhancer</b>
|
634
|
+
end
|
635
|
+
end
|
636
|
+
</pre>
|
637
|
+
<br>
|
638
|
+
|
639
|
+
|
640
|
+
<a name="tut-print"></a>
|
641
|
+
<h3 class="section2">Print Avairable Eruby</h3>
|
642
|
+
<p>Erubis::PrintEruby and Erubis::PrintXmlEruby enables you to use print statement.
|
643
|
+
You can get output as String because Erubis::PrintEruby and Erubis::PrintXmlEruby doesn't use $stdout.
|
644
|
+
</p>
|
645
|
+
<p>Notice:
|
646
|
+
</p>
|
647
|
+
<ul type="disc">
|
648
|
+
<li>Use evaluate() and don't use result().
|
649
|
+
</li>
|
650
|
+
<li>Only print() is available, put() or p() are not available.
|
651
|
+
</li>
|
652
|
+
<li>PrintEruby and PrintXmlEruby has instance method 'print()'.
|
653
|
+
It means that print statement invokes PrintEruby#print() or PrintXmlEruby#print(),
|
654
|
+
and Kernel#print() is not invoked.
|
655
|
+
</li>
|
656
|
+
<li>PrintEruby#print() and PrintXmlEruby#print() can take just an argument.
|
657
|
+
</li>
|
658
|
+
</ul>
|
659
|
+
<a name="example9.eruby"></a>
|
660
|
+
<div class="program_caption">
|
661
|
+
example9.eruby</div>
|
662
|
+
<pre class="program"><ul>
|
663
|
+
<% for item in list %>
|
664
|
+
<li><b><% print item %></b></li>
|
665
|
+
<% end %>
|
666
|
+
</ul>
|
667
|
+
</pre>
|
668
|
+
<a name="example9.rb"></a>
|
669
|
+
<div class="program_caption">
|
670
|
+
example9.rb</div>
|
671
|
+
<pre class="program">## create Eruby object
|
672
|
+
require 'erubis'
|
673
|
+
input = File.read('example9.eruby')
|
674
|
+
eruby = Erubis::<b>PrintEruby</b>.new(input)
|
675
|
+
|
676
|
+
## print script source
|
677
|
+
puts "--- script source ---"
|
678
|
+
puts eruby.src
|
679
|
+
|
680
|
+
## get result
|
681
|
+
puts "--- result ---"
|
682
|
+
list = ['aaa', 'bbb', 'ccc']
|
683
|
+
puts <b>eruby.evaluate(:list => list)</b> # don't use result()!
|
684
|
+
</pre>
|
685
|
+
<div class="terminal_caption">
|
686
|
+
output</div>
|
687
|
+
<pre class="terminal">$ ruby example9.rb
|
688
|
+
--- script source ---
|
689
|
+
<b>@_out =</b> _out = ''; _out << "<ul>\n"
|
690
|
+
for item in list
|
691
|
+
_out << " <li>"; <b>print item</b> ; _out << "</li>\n"
|
692
|
+
end
|
693
|
+
_out << "</ul>\n"
|
694
|
+
_out
|
695
|
+
--- result ---
|
696
|
+
<ul>
|
697
|
+
<li>aaa</li>
|
698
|
+
<li>bbb</li>
|
699
|
+
<li>ccc</li>
|
700
|
+
</ul>
|
701
|
+
</pre>
|
702
|
+
<p>Here is the definition of PrintEruby or PrintXmlEruby.
|
703
|
+
They are subclass of Eruby and XmlEruby respectively and only include PrintEnhancer module.
|
704
|
+
It shows that Erubis is extensible.
|
705
|
+
</p>
|
706
|
+
<div class="program_caption">
|
707
|
+
definition of PrintEruby and PrintXmlEruby</div>
|
708
|
+
<pre class="program">module Erubis
|
709
|
+
class PrintEruby < Eruby
|
710
|
+
<b>include PrintEnhancer</b>
|
711
|
+
end
|
712
|
+
class PrintXmlEruby < XmlEruby
|
713
|
+
<b>include PrintEnhancer</b>
|
714
|
+
end
|
715
|
+
end
|
716
|
+
</pre>
|
601
717
|
<br>
|
602
718
|
|
603
719
|
|
@@ -608,7 +724,7 @@ nil
|
|
608
724
|
<h2 class="section1">Command Reference</h2>
|
609
725
|
<a name="command-usage"></a>
|
610
726
|
<h3 class="section2">Usage</h3>
|
611
|
-
<p>erubis [-hvsT] [-p <
|
727
|
+
<p>erubis [-hvsT] [-p <i>pattern</i>] [-c <i>class</i>] [-K <i>kanji</i>] [-f <i>file.yaml</i>] [<i>file</i> ...]
|
612
728
|
</p>
|
613
729
|
<br>
|
614
730
|
|
data/lib/erubis.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
##
|
2
|
-
## $Rev:
|
3
|
-
## $Release: 1.0
|
2
|
+
## $Rev: 5 $
|
3
|
+
## $Release: 1.1.0 $
|
4
4
|
## copyright(c) 2006 kuwata-lab all rights reserved.
|
5
5
|
##
|
6
6
|
|
7
7
|
##
|
8
8
|
## an implementation of eRuby
|
9
9
|
##
|
10
|
+
## * class Eruby - normal eRuby class
|
11
|
+
## * class XmlEruby - eRuby class which escape '&<>"' into '&<>"'
|
12
|
+
## * module FastEnhancer - make eRuby faster
|
13
|
+
## * module StdoutEnhance - use $stdout instead of String as output
|
14
|
+
## * module PrintEnhance - enable to write print statement in <% ... %>
|
15
|
+
##
|
10
16
|
## example:
|
11
17
|
## list = ['<aaa>', 'b&b', '"ccc"']
|
12
18
|
## input = <<-END
|
@@ -22,6 +28,7 @@
|
|
22
28
|
## puts eruby.src
|
23
29
|
## puts "--- result ---"
|
24
30
|
## puts eruby.result(binding())
|
31
|
+
## # or puts eruby.evaluate(:list=>list)
|
25
32
|
##
|
26
33
|
## result:
|
27
34
|
## --- source ---
|
@@ -88,19 +95,27 @@ module Erubis
|
|
88
95
|
src = ""
|
89
96
|
initialize_src(src)
|
90
97
|
prefix, postfix = @pattern.split()
|
91
|
-
regexp = /(.*?)(^[ \t]*)?#{prefix}(
|
98
|
+
regexp = /(.*?)(^[ \t]*)?#{prefix}(=+|\#)?(.*?)#{postfix}([ \t]*\r?\n)?/m
|
92
99
|
input.scan(regexp) do |text, head_space, indicator, code, tail_space|
|
93
100
|
## * when '<%= %>', do nothing
|
94
|
-
## * when '<% %>', delete spaces iff only spaces are around '<% %>'
|
95
|
-
|
101
|
+
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
|
102
|
+
if indicator && indicator[0] == ?=
|
103
|
+
flag_trim = false
|
104
|
+
else
|
105
|
+
flag_trim = @trim && head_space && tail_space
|
106
|
+
end
|
107
|
+
#flag_trim = @trim && !(indicator && indicator[0]==?=) && head_space && tail_space
|
96
108
|
add_src_text(src, text)
|
97
109
|
add_src_text(src, head_space) if !flag_trim && head_space
|
98
|
-
if indicator
|
110
|
+
if !indicator # <% %>
|
99
111
|
code = "#{head_space}#{code}#{tail_space}" if flag_trim
|
100
|
-
#code = "#{head_space}#{code}#\n" if flag_trim
|
101
112
|
add_src_code(src, code)
|
102
|
-
|
113
|
+
elsif indicator[0] == ?= # <%= %>
|
103
114
|
add_src_expr(src, code, indicator)
|
115
|
+
else # <%# %>
|
116
|
+
n = code.count("\n")
|
117
|
+
n += tail_space.count("\n") if tail_space
|
118
|
+
add_src_code(src, "\n" * n)
|
104
119
|
end
|
105
120
|
add_src_text(src, tail_space) if !flag_trim && tail_space
|
106
121
|
end
|
@@ -208,6 +223,30 @@ module Erubis
|
|
208
223
|
end
|
209
224
|
|
210
225
|
|
226
|
+
##
|
227
|
+
## print function is available.
|
228
|
+
##
|
229
|
+
## Notice: use Eruby#evaluate() and don't use Eruby#result()
|
230
|
+
## to be enable print function.
|
231
|
+
##
|
232
|
+
module PrintEnhancer
|
233
|
+
|
234
|
+
def initialize_src(src)
|
235
|
+
src << "@_out = _out = ''; "
|
236
|
+
end
|
237
|
+
|
238
|
+
def print(arg)
|
239
|
+
@_out << arg.to_s
|
240
|
+
end
|
241
|
+
|
242
|
+
def result(binding=TOPLEVEL_BINDING)
|
243
|
+
filename = @filename || '(erubis)'
|
244
|
+
eval @src, binding, filename
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
|
211
250
|
class FastEruby < Eruby
|
212
251
|
include FastEnhancer
|
213
252
|
end
|
@@ -218,6 +257,11 @@ module Erubis
|
|
218
257
|
end
|
219
258
|
|
220
259
|
|
260
|
+
class PrintEruby < Eruby
|
261
|
+
include PrintEnhancer
|
262
|
+
end
|
263
|
+
|
264
|
+
|
221
265
|
class FastXmlEruby < XmlEruby
|
222
266
|
include FastEnhancer
|
223
267
|
end
|
@@ -228,6 +272,11 @@ module Erubis
|
|
228
272
|
end
|
229
273
|
|
230
274
|
|
275
|
+
class PrintXmlEruby < XmlEruby
|
276
|
+
include PrintEnhancer
|
277
|
+
end
|
278
|
+
|
279
|
+
|
231
280
|
end
|
232
281
|
|
233
282
|
|
@@ -247,6 +296,7 @@ END
|
|
247
296
|
puts "--- source ---"
|
248
297
|
puts eruby.src
|
249
298
|
puts "--- result ---"
|
250
|
-
puts eruby.result(binding())
|
299
|
+
#puts eruby.result(binding())
|
300
|
+
puts eruby.evaluate(:list=>list)
|
251
301
|
|
252
302
|
end
|
data/test/test-bin.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
##
|
2
2
|
## $Rev: 3 $
|
3
|
-
## $Release: 1.0
|
3
|
+
## $Release: 1.1.0 $
|
4
4
|
## $Date: 2006-01-31 12:54:23 +0900 (Tue, 31 Jan 2006) $
|
5
5
|
##
|
6
6
|
|
@@ -20,7 +20,7 @@ end
|
|
20
20
|
|
21
21
|
require 'test/unit'
|
22
22
|
#require 'test/unit/ui/console/testrunner'
|
23
|
-
require 'assert-
|
23
|
+
require 'assert-text-equal'
|
24
24
|
require 'yaml'
|
25
25
|
require 'tempfile'
|
26
26
|
|
@@ -69,13 +69,13 @@ END
|
|
69
69
|
ensure
|
70
70
|
File.unlink(@filename) if @filename && test(?f, @filename)
|
71
71
|
end
|
72
|
-
|
72
|
+
assert_text_equal(@expected, output)
|
73
73
|
end
|
74
74
|
|
75
75
|
|
76
76
|
def test_version
|
77
77
|
@options = '-v'
|
78
|
-
@expected = (("$Release: 1.0
|
78
|
+
@expected = (("$Release: 1.1.0 $" =~ /[.\d]+/) && $&) + "\n"
|
79
79
|
@filename = false
|
80
80
|
_test()
|
81
81
|
end
|
data/test/test-erubis.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
##
|
2
|
-
## $Rev:
|
3
|
-
## $Release: 1.0
|
4
|
-
## $Date: 2006-
|
2
|
+
## $Rev: 5 $
|
3
|
+
## $Release: 1.1.0 $
|
4
|
+
## $Date: 2006-03-04 22:21:26 +0900 (Sat, 04 Mar 2006) $
|
5
5
|
##
|
6
6
|
|
7
7
|
testdir = File.dirname(__FILE__)
|
@@ -11,7 +11,7 @@ $: << libdir
|
|
11
11
|
|
12
12
|
require 'test/unit'
|
13
13
|
#require 'test/unit/ui/console/testrunner'
|
14
|
-
require 'assert-
|
14
|
+
require 'assert-text-equal'
|
15
15
|
require 'yaml'
|
16
16
|
require 'stringio'
|
17
17
|
|
@@ -22,7 +22,7 @@ class ErubisTest < Test::Unit::TestCase
|
|
22
22
|
#str = DATA.read()
|
23
23
|
str = File.read(__FILE__)
|
24
24
|
str.gsub!(/.*^__END__$/m, '')
|
25
|
-
|
25
|
+
|
26
26
|
@@ydocs = {}
|
27
27
|
YAML.load_documents(str) do |ydoc|
|
28
28
|
name = ydoc['name']
|
@@ -47,12 +47,12 @@ class ErubisTest < Test::Unit::TestCase
|
|
47
47
|
def _test()
|
48
48
|
ydoc = @@ydocs[@name]
|
49
49
|
input = ydoc['input']
|
50
|
-
src = ydoc['src'].gsub(
|
51
|
-
output = ydoc['output'].gsub(
|
50
|
+
src = ydoc['src'].gsub(/\^/, ' ')
|
51
|
+
output = ydoc['output'].gsub(/\^/, ' ')
|
52
52
|
klass = ydoc['class'] ? (eval "Erubis::#{ydoc['class']}") : Erubis::Eruby
|
53
53
|
options = ydoc['options'] || {}
|
54
54
|
testopt = ydoc['testopt']
|
55
|
-
|
55
|
+
|
56
56
|
if testopt != 'load_file'
|
57
57
|
eruby = klass.new(input, options)
|
58
58
|
else
|
@@ -64,16 +64,16 @@ class ErubisTest < Test::Unit::TestCase
|
|
64
64
|
File.unlink(filename) if test(?f, filename)
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
68
|
-
|
67
|
+
assert_text_equal(src, eruby.src)
|
68
|
+
|
69
69
|
return if testopt == 'skip_output'
|
70
|
-
|
70
|
+
|
71
71
|
context = {}
|
72
72
|
context[:list] = ['<aaa>', 'b&b', '"ccc"']
|
73
|
-
|
73
|
+
|
74
74
|
if testopt != 'stdout'
|
75
75
|
actual = eruby.evaluate(context)
|
76
|
-
|
76
|
+
assert_text_equal(output, actual)
|
77
77
|
else
|
78
78
|
begin
|
79
79
|
orig = $stdout
|
@@ -83,7 +83,7 @@ class ErubisTest < Test::Unit::TestCase
|
|
83
83
|
$stdout = orig if orig
|
84
84
|
end
|
85
85
|
assert_nil(actual)
|
86
|
-
|
86
|
+
assert_text_equal(output, stringio.string)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -128,7 +128,7 @@ src: |
|
|
128
128
|
i = 0
|
129
129
|
for item in list
|
130
130
|
i += 1
|
131
|
-
|
131
|
+
^^
|
132
132
|
_out << " <li>"; _out << ( item ).to_s; _out << "</li>\n"
|
133
133
|
end
|
134
134
|
_out << "</ul>\n"
|
@@ -224,13 +224,45 @@ src: |
|
|
224
224
|
_out
|
225
225
|
output: |
|
226
226
|
<ul>
|
227
|
-
|
227
|
+
^
|
228
228
|
<li><aaa></li>
|
229
|
-
|
229
|
+
^
|
230
230
|
<li>b&b</li>
|
231
|
-
|
231
|
+
^
|
232
232
|
<li>"ccc"</li>
|
233
|
-
|
233
|
+
^
|
234
|
+
</ul>
|
235
|
+
##
|
236
|
+
---
|
237
|
+
name: ignore1
|
238
|
+
input: |
|
239
|
+
<ul>
|
240
|
+
<%# i = 0 %>
|
241
|
+
<% for item in list %>
|
242
|
+
<%#
|
243
|
+
i += 1
|
244
|
+
color = i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'
|
245
|
+
%>
|
246
|
+
<li> <%#= i %> : <%= item %> </li>
|
247
|
+
<% end %>
|
248
|
+
</ul>
|
249
|
+
src: |
|
250
|
+
_out = ''; _out << "<ul>\n"
|
251
|
+
|
252
|
+
for item in list
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
_out << " <li> "; ; _out << " : "; _out << ( item ).to_s; _out << " </li>\n"
|
258
|
+
end
|
259
|
+
_out << "</ul>\n"
|
260
|
+
_out
|
261
|
+
output: |
|
262
|
+
<ul>
|
263
|
+
<li> : <aaa> </li>
|
264
|
+
<li> : b&b </li>
|
265
|
+
<li> : "ccc" </li>
|
234
266
|
</ul>
|
235
267
|
##
|
236
268
|
---
|
@@ -301,7 +333,7 @@ src: |
|
|
301
333
|
_out << " <tr>\n <td>"
|
302
334
|
_out << ( item ).to_s; _out << "</td>\n <td>"
|
303
335
|
_out << ( item ).to_s; _out << "</td>\n </tr>\n"
|
304
|
-
|
336
|
+
|
305
337
|
end
|
306
338
|
_out << "</table>\n<ul>"
|
307
339
|
for item in list ; _out << "<li>"; _out << ( item ).to_s; _out << "</li>"; end ; _out << "</ul>\n"
|
@@ -342,7 +374,7 @@ src: |
|
|
342
374
|
_out << " <tr>\n <td>"
|
343
375
|
_out << Erubis::XmlEruby.escape( item ); _out << "</td>\n <td>"
|
344
376
|
_out << ( item ).to_s; _out << "</td>\n </tr>\n"
|
345
|
-
|
377
|
+
|
346
378
|
end
|
347
379
|
_out << "</table>\n<ul>"
|
348
380
|
for item in list ; _out << "<li>"; _out << Erubis::XmlEruby.escape( item ); _out << "</li>"; end ; _out << "</ul>\n"
|
@@ -380,9 +412,9 @@ src: |
|
|
380
412
|
end
|
381
413
|
_out
|
382
414
|
# _out = ''; _out << "user = "; _out << ( "Foo" ).to_s; _out << "\n"
|
383
|
-
# _out << ""; for item in list
|
415
|
+
# _out << ""; for item in list
|
384
416
|
# _out << ""; _out << " "; _out << ( item ).to_s; _out << "\n"
|
385
|
-
# _out << ""; end
|
417
|
+
# _out << ""; end
|
386
418
|
# _out << ""; _out
|
387
419
|
output: |
|
388
420
|
user = Foo
|
@@ -414,6 +446,50 @@ output: |
|
|
414
446
|
<li>"ccc"</li>
|
415
447
|
</ul>
|
416
448
|
---
|
449
|
+
name: print1
|
450
|
+
class: PrintEruby
|
451
|
+
input: |
|
452
|
+
<ul>
|
453
|
+
<% for item in list %>
|
454
|
+
<li><% print item %></li>
|
455
|
+
<% end %>
|
456
|
+
</ul>
|
457
|
+
src: |
|
458
|
+
@_out = _out = ''; _out << "<ul>\n"
|
459
|
+
for item in list
|
460
|
+
_out << " <li>"; print item ; _out << "</li>\n"
|
461
|
+
end
|
462
|
+
_out << "</ul>\n"
|
463
|
+
_out
|
464
|
+
output: |
|
465
|
+
<ul>
|
466
|
+
<li><aaa></li>
|
467
|
+
<li>b&b</li>
|
468
|
+
<li>"ccc"</li>
|
469
|
+
</ul>
|
470
|
+
---
|
471
|
+
name: print2
|
472
|
+
class: PrintXmlEruby
|
473
|
+
input: |
|
474
|
+
<ul>
|
475
|
+
<% for item in list %>
|
476
|
+
<li><% print item %></li>
|
477
|
+
<% end %>
|
478
|
+
</ul>
|
479
|
+
src: |
|
480
|
+
@_out = _out = ''; _out << "<ul>\n"
|
481
|
+
for item in list
|
482
|
+
_out << " <li>"; print item ; _out << "</li>\n"
|
483
|
+
end
|
484
|
+
_out << "</ul>\n"
|
485
|
+
_out
|
486
|
+
output: |
|
487
|
+
<ul>
|
488
|
+
<li><aaa></li>
|
489
|
+
<li>b&b</li>
|
490
|
+
<li>"ccc"</li>
|
491
|
+
</ul>
|
492
|
+
---
|
417
493
|
name: loadfile1
|
418
494
|
testopt: load_file
|
419
495
|
#input: |
|
@@ -422,13 +498,13 @@ testopt: load_file
|
|
422
498
|
# <li><%= item %></li>
|
423
499
|
# <% end %>
|
424
500
|
# </ul>
|
425
|
-
input:
|
501
|
+
input:
|
426
502
|
"<ul>\r\n <% for item in list %>\r\n <li><%= item %></li>\r\n <% end %>\r\n</ul>\r\n"
|
427
503
|
#src: |
|
428
504
|
# _out = ''; _out << "<ul>\n"
|
429
|
-
# for item in list
|
505
|
+
# for item in list
|
430
506
|
# _out << " <li>"; _out << ( item ).to_s; _out << "</li>\n"
|
431
|
-
# end
|
507
|
+
# end
|
432
508
|
# _out << "</ul>\n"
|
433
509
|
# _out
|
434
510
|
src:
|
@@ -439,7 +515,7 @@ src:
|
|
439
515
|
# <li>b&b</li>
|
440
516
|
# <li>"ccc"</li>
|
441
517
|
# </ul>
|
442
|
-
output:
|
518
|
+
output:
|
443
519
|
"<ul>\r\n <li><aaa></li>\r\n <li>b&b</li>\r\n <li>\"ccc\"</li>\r\n</ul>\r\n"
|
444
520
|
##
|
445
521
|
---
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.11
|
3
3
|
specification_version: 1
|
4
4
|
name: erubis
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0
|
7
|
-
date: 2006-
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2006-03-05 00:00:00 +09:00
|
8
8
|
summary: an implementation of eRuby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -23,13 +23,15 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
23
23
|
version: 0.0.0
|
24
24
|
version:
|
25
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
26
28
|
authors:
|
27
29
|
- kwatch
|
28
30
|
files:
|
29
31
|
- lib/erubis.rb
|
30
32
|
- bin/erubis
|
31
|
-
- test/test-erubis.rb
|
32
33
|
- test/test-bin.rb
|
34
|
+
- test/test-erubis.rb
|
33
35
|
- doc/users-guide.html
|
34
36
|
- doc/docstyle.css
|
35
37
|
- README
|