erubis 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,7 +1,15 @@
1
1
  # $Rev$
2
- # $Release: 1.0.1 $
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
@@ -1,5 +1,5 @@
1
1
  .=title: README
2
- .?release: $Release: 1.0.1 $
2
+ .?release: $Release: 1.1.0 $
3
3
  .?copyright: copyright(c) 2006 kuwata-lab all rights reserved.
4
4
 
5
5
 
data/bin/erubis CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ###
4
4
  ### $Rev: 4 $
5
- ### $Release: 1.0.1 $
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.1 $' =~ /([.\d]+)/) && $1
116
+ release = ('$Release: 1.1.0 $' =~ /([.\d]+)/) && $1
117
117
  return release
118
118
  end
119
119
 
@@ -23,14 +23,16 @@
23
23
  It has the following features.
24
24
  </p>
25
25
  <ul type="disc">
26
- <li>Auto trimming spaces around '&lt;% %&gt;'
26
+ <li>Auto sanitizing support
27
27
  </li>
28
- <li>Auto sanitizing
28
+ <li>Auto trimming spaces around '&lt;% %&gt;'
29
29
  </li>
30
- <li>Change embedded pattern (default '&lt;% %&gt;')
30
+ <li>Embedded pattern changeable (default '&lt;% %&gt;')
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 &gt; contrib/erubis
127
131
  <div class="program_caption">
128
132
  example1.eruby</div>
129
133
  <pre class="program">&lt;ul&gt;
130
- <strong>&lt;% for item in list %&gt;</strong>
134
+ <b>&lt;% for item in list %&gt;</b>
131
135
  &lt;li&gt;
132
- <strong>&lt;%= item %&gt;</strong>
136
+ <b>&lt;%= item %&gt;</b>
133
137
  &lt;/li&gt;
134
- <strong>&lt;% end %&gt;</strong>
138
+ <b>&lt;% end %&gt;</b>
139
+ <b>&lt;%# here is ignored because starting with '#' %&gt;</b>
135
140
  &lt;/ul&gt;
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 = <strong>Erubis::Eruby.new(input)</strong>
148
+ eruby = <b>Erubis::Eruby.new(input)</b>
144
149
 
145
150
  ## print script source
146
151
  puts "--- script source ---"
147
- puts <strong>eruby.src</strong>
152
+ puts <b>eruby.src</b>
148
153
 
149
154
  ## get result
150
155
  puts "--- result ---"
151
156
  list = ['aaa', 'bbb', 'ccc']
152
- puts <strong>eruby.result(binding())</strong>
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 &lt;&lt; " &lt;li&gt;\n"
161
166
  _out &lt;&lt; " "; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; "\n"
162
167
  _out &lt;&lt; " &lt;/li&gt;\n"
163
168
  end
169
+
164
170
  _out &lt;&lt; "&lt;/ul&gt;\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<strong>, :trim=&gt;false</strong>)
210
+ eruby = Erubis::Eruby.new(input<b>, :trim=&gt;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 &lt;&lt; "&lt;ul&gt;\n"
220
- <strong>_out &lt;&lt; " ";</strong> for item in list <strong>; _out &lt;&lt; "\n"</strong>
226
+ <b>_out &lt;&lt; " ";</b> for item in list <b>; _out &lt;&lt; "\n"</b>
221
227
  _out &lt;&lt; " &lt;li&gt;\n"
222
228
  _out &lt;&lt; " "; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; "\n"
223
229
  _out &lt;&lt; " &lt;/li&gt;\n"
224
- <strong>_out &lt;&lt; " ";</strong> end <strong>; _out &lt;&lt; "\n"</strong>
230
+ <b>_out &lt;&lt; " ";</b> end <b>; _out &lt;&lt; "\n"</b>
225
231
  _out &lt;&lt; "&lt;/ul&gt;\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>&lt;%= <em>expr</em> %&gt;</code> will be sanitized.
260
+ <li><code>&lt;%= <i>expr</i> %&gt;</code> will be sanitized.
255
261
  </li>
256
- <li><code>&lt;%== <em>expr</em> %&gt;</code> will be out as it is.
262
+ <li><code>&lt;%== <i>expr</i> %&gt;</code> will be out as it is.
257
263
  </li>
258
- <li><code>&lt;%=== <em>expr</em> %&gt;</code> will be out to $stderr.
264
+ <li><code>&lt;%=== <i>expr</i> %&gt;</code> will be out to $stderr.
259
265
  </li>
260
- <li><code>&lt;%==== <em>expr</em> %&gt;</code> will be ignored.
266
+ <li><code>&lt;%==== <i>expr</i> %&gt;</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">&lt;ul&gt;
267
273
  &lt;% for item in list %&gt;
268
- &lt;li&gt;<strong>&lt;%=</strong> item <strong>%&gt;</strong>&lt;/li&gt;
269
- &lt;li&gt;<strong>&lt;%==</strong> item <strong>%&gt;</strong>&lt;/li&gt;
270
- &lt;li&gt;<strong>&lt;%===</strong> item <strong>%&gt;</strong>&lt;/li&gt;
274
+ &lt;li&gt;<b>&lt;%=</b> item <b>%&gt;</b>&lt;/li&gt;
275
+ &lt;li&gt;<b>&lt;%==</b> item <b>%&gt;</b>&lt;/li&gt;
276
+ &lt;li&gt;<b>&lt;%===</b> item <b>%&gt;</b>&lt;/li&gt;
271
277
 
272
278
  &lt;% end %&gt;
273
279
  &lt;/ul&gt;
@@ -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::<strong>XmlEruby</strong>.new(input)
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
- <strong>list = ['&lt;aaa&gt;', 'b&amp;b', '"ccc"']</strong>
295
+ <b>list = ['&lt;aaa&gt;', 'b&amp;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 &lt;&lt; "&lt;ul&gt;\n"
297
303
  for item in list
298
- _out &lt;&lt; " &lt;li&gt;"; <strong>_out &lt;&lt; Erubis::XmlEruby.escape( item )</strong>; _out &lt;&lt; "&lt;/li&gt;\n"
304
+ _out &lt;&lt; " &lt;li&gt;"; <b>_out &lt;&lt; Erubis::XmlEruby.escape( item )</b>; _out &lt;&lt; "&lt;/li&gt;\n"
299
305
  _out &lt;&lt; " &lt;li&gt;"; _out &lt;&lt; ( item ).to_s; _out &lt;&lt; "&lt;/li&gt;\n"
300
- _out &lt;&lt; " &lt;li&gt;"; <strong>$stderr.puts("** erubis: item = #{(item).inspect}")</strong>; _out &lt;&lt; "&lt;/li&gt;\n"
306
+ _out &lt;&lt; " &lt;li&gt;"; <b>$stderr.puts("** erubis: item = #{(item).inspect}")</b>; _out &lt;&lt; "&lt;/li&gt;\n"
301
307
  _out &lt;&lt; "\n"
302
308
  end
303
309
  _out &lt;&lt; "&lt;/ul&gt;\n"
304
310
  _out
305
311
  --- result ---
306
312
  &lt;ul&gt;
307
- &lt;li&gt;<strong>&amp;lt;aaa&amp;gt;</strong>&lt;/li&gt;
313
+ &lt;li&gt;<b>&amp;lt;aaa&amp;gt;</b>&lt;/li&gt;
308
314
  &lt;li&gt;&lt;aaa&gt;&lt;/li&gt;
309
315
  &lt;li&gt;&lt;/li&gt;
310
316
 
311
- &lt;li&gt;<strong>b&amp;amp;b</strong>&lt;/li&gt;
317
+ &lt;li&gt;<b>b&amp;amp;b</b>&lt;/li&gt;
312
318
  &lt;li&gt;b&amp;b&lt;/li&gt;
313
319
  &lt;li&gt;&lt;/li&gt;
314
320
 
315
- &lt;li&gt;<strong>&amp;quot;ccc&amp;quot;</strong>&lt;/li&gt;
321
+ &lt;li&gt;<b>&amp;quot;ccc&amp;quot;</b>&lt;/li&gt;
316
322
  &lt;li&gt;"ccc"&lt;/li&gt;
317
323
  &lt;li&gt;&lt;/li&gt;
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">&lt;ul&gt;
336
- <strong>&lt;!--%</strong> for item in list <strong>%--&gt;</strong>
337
- &lt;li&gt;<strong>&lt;!--%=</strong> item <strong>%--&gt;</strong>&lt;/li&gt;
338
- <strong>&lt;!--%</strong> end <strong>%--&gt;</strong>
342
+ <b>&lt;!--%</b> for item in list <b>%--&gt;</b>
343
+ &lt;li&gt;<b>&lt;!--%=</b> item <b>%--&gt;</b>&lt;/li&gt;
344
+ <b>&lt;!--%</b> end <b>%--&gt;</b>
339
345
  &lt;/ul&gt;
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<strong>, :pattern=&gt;'&lt;!--% %--&gt;'</strong>)
353
+ eruby = Erubis::Eruby.new(input<b>, :pattern=&gt;'&lt;!--% %--&gt;'</b>)
348
354
  # or '&lt;(?:!--)?% %(?:--)?&gt;'
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>&lt;(!--)?% %(--)?&gt;</code>' will not work and '<code>&lt;(?:!--)?% %(?:--)?&gt;</code>' will work.
384
+ For example, '<code>&lt;(!--)?% %(--)?&gt;</code>' will not work while '<code>&lt;(?:!--)?% %(?:--)?&gt;</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
- <strong>context = {}</strong>
412
- <strong>context[:val] = 'Erubis Example'</strong>
413
- <strong>context['list'] = ['aaa', 'bbb', 'ccc']</strong>
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 <strong>eruby.evaluate(context)</strong>
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
- <strong>require 'yaml'</strong>
466
- <strong>context = YAML.load_file('example6.yaml')</strong>
471
+ <b>require 'yaml'</b>
472
+ <b>context = YAML.load_file('example6.yaml')</b>
467
473
 
468
474
  ## get result
469
- puts <strong>eruby.evaluate(context)</strong>
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::<strong>FastEruby</strong>.new(input)
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 &lt;&lt; " &lt;/tbody&gt;\n&lt;/table&gt;\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 &lt; Eruby
563
+ <b>include FastEnhancer</b>
564
+ end
565
+ class FastXmlEruby &lt; 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">&lt;ul&gt;
561
582
  &lt;% for item in list %&gt;
562
- &lt;li&gt;<strong>&lt;% print item %&gt;</strong>&lt;/li&gt;
583
+ &lt;li&gt;<b>&lt;% print item %&gt;</b>&lt;/li&gt;
563
584
  &lt;% end %&gt;
564
585
  &lt;/ul&gt;
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::<strong>StdoutEruby</strong>.new(input)
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
- <strong>eruby.result(binding())</strong> # returns nil
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
- <strong>_out = $stdout</strong>; _out &lt;&lt; "&lt;ul&gt;\n"
609
+ <b>_out = $stdout</b>; _out &lt;&lt; "&lt;ul&gt;\n"
589
610
  for item in list
590
- _out &lt;&lt; " &lt;li&gt;"; <strong>print item</strong> ; _out &lt;&lt; "&lt;/li&gt;\n"
611
+ _out &lt;&lt; " &lt;li&gt;"; <b>print item</b> ; _out &lt;&lt; "&lt;/li&gt;\n"
591
612
  end
592
613
  _out &lt;&lt; "&lt;/ul&gt;\n"
593
- nil
614
+ <b>nil</b>
594
615
  --- result ---
595
616
  &lt;ul&gt;
596
617
  &lt;li&gt;aaa&lt;/li&gt;
@@ -598,6 +619,101 @@ nil
598
619
  &lt;li&gt;ccc&lt;/li&gt;
599
620
  &lt;/ul&gt;
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 &lt; Eruby
630
+ <b>include StdoutEnhancer</b>
631
+ end
632
+ class StdoutXmlEruby &lt; 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">&lt;ul&gt;
663
+ &lt;% for item in list %&gt;
664
+ &lt;li&gt;<b>&lt;% print item %&gt;</b>&lt;/li&gt;
665
+ &lt;% end %&gt;
666
+ &lt;/ul&gt;
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 =&gt; 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 &lt;&lt; "&lt;ul&gt;\n"
690
+ for item in list
691
+ _out &lt;&lt; " &lt;li&gt;"; <b>print item</b> ; _out &lt;&lt; "&lt;/li&gt;\n"
692
+ end
693
+ _out &lt;&lt; "&lt;/ul&gt;\n"
694
+ _out
695
+ --- result ---
696
+ &lt;ul&gt;
697
+ &lt;li&gt;aaa&lt;/li&gt;
698
+ &lt;li&gt;bbb&lt;/li&gt;
699
+ &lt;li&gt;ccc&lt;/li&gt;
700
+ &lt;/ul&gt;
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 &lt; Eruby
710
+ <b>include PrintEnhancer</b>
711
+ end
712
+ class PrintXmlEruby &lt; 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 <em>pattern</em>] [-c <em>class</em>] [-K <em>kanji</em>] [-f <em>file.yaml</em>] [<em>file</em> ...]
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
 
@@ -1,12 +1,18 @@
1
1
  ##
2
- ## $Rev: 4 $
3
- ## $Release: 1.0.1 $
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 '&amp;&lt;&gt;&quot;'
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}(=*)(.*?)#{postfix}([ \t]*\r?\n)?/m
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
- flag_trim = @trim && indicator.empty? && head_space && tail_space
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.empty? # <% %>
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
- else # <%= %>
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
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 3 $
3
- ## $Release: 1.0.1 $
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-diff'
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
- assert_equal_with_diff(@expected, output)
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.1 $" =~ /[.\d]+/) && $&) + "\n"
78
+ @expected = (("$Release: 1.1.0 $" =~ /[.\d]+/) && $&) + "\n"
79
79
  @filename = false
80
80
  _test()
81
81
  end
@@ -1,7 +1,7 @@
1
1
  ##
2
- ## $Rev: 3 $
3
- ## $Release: 1.0.1 $
4
- ## $Date: 2006-01-31 12:54:23 +0900 (Tue, 31 Jan 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-diff'
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
- assert_equal_with_diff(src, eruby.src)
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
- assert_equal_with_diff(output, actual)
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
- assert_equal_with_diff(output, stringio.string)
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.10
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.1
7
- date: 2006-02-01
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