erubis 2.2.0 → 2.3.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/CHANGES +120 -3
- data/README.txt +1 -1
- data/benchmark/Makefile +6 -0
- data/benchmark/bench.rb +306 -0
- data/benchmark/{erubybench.yaml → bench_context.yaml} +20 -20
- data/benchmark/templates/_footer.html +4 -0
- data/benchmark/{erubybench.rhtml → templates/_header.html} +1 -34
- data/benchmark/templates/bench_erb.rhtml +29 -0
- data/benchmark/templates/bench_erubis.rhtml +29 -0
- data/benchmark/templates/bench_eruby.rhtml +29 -0
- data/bin/erubis +2 -2
- data/contrib/erubis +3 -3114
- data/contrib/erubis-run.rb +132 -0
- data/contrib/inline-require +1 -1
- data/doc-api/classes/{ERB.html → ActionView/Base/ERB.html} +3 -3
- data/doc-api/classes/Erubis.html +8 -1
- data/doc-api/classes/Erubis/ArrayEnhancer.html +12 -12
- data/doc-api/classes/Erubis/Basic/Converter.html +24 -24
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
- data/doc-api/classes/Erubis/CGenerator.html +60 -60
- data/doc-api/classes/Erubis/Context.html +42 -42
- data/doc-api/classes/Erubis/Converter.html +27 -27
- data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +150 -0
- data/doc-api/classes/Erubis/DeleteIndentEruby.html +120 -0
- data/doc-api/classes/Erubis/Engine.html +31 -31
- data/doc-api/classes/Erubis/ErboutEnhancer.html +175 -0
- data/doc-api/classes/Erubis/ErboutEruby.html +120 -0
- data/doc-api/classes/Erubis/Eruby.html +5 -0
- data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
- data/doc-api/classes/Erubis/Evaluator.html +19 -19
- data/doc-api/classes/Erubis/FastEruby.html +131 -0
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +14 -14
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +49 -45
- data/doc-api/classes/Erubis/InterpolationEnhancer.html +304 -0
- data/doc-api/classes/Erubis/InterpolationEruby.html +120 -0
- data/doc-api/classes/Erubis/JavaGenerator.html +54 -54
- data/doc-api/classes/Erubis/JavascriptGenerator.html +60 -60
- data/doc-api/classes/Erubis/Main.html +35 -27
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +5 -5
- data/doc-api/classes/Erubis/NoTextEnhancer.html +7 -7
- data/doc-api/classes/Erubis/OptimizedEruby.html +6 -6
- data/doc-api/classes/Erubis/OptimizedGenerator.html +72 -72
- data/doc-api/classes/Erubis/OptimizedXmlEruby.html +6 -6
- data/doc-api/classes/Erubis/PI/Converter.html +18 -18
- data/doc-api/classes/Erubis/PI/Ec.html +6 -6
- data/doc-api/classes/Erubis/PI/Ejava.html +6 -6
- data/doc-api/classes/Erubis/PI/Ejavascript.html +6 -6
- data/doc-api/classes/Erubis/PI/Eperl.html +6 -6
- data/doc-api/classes/Erubis/PI/Ephp.html +6 -6
- data/doc-api/classes/Erubis/PI/Eruby.html +7 -7
- data/doc-api/classes/Erubis/PI/Escheme.html +6 -6
- data/doc-api/classes/Erubis/PI/TinyEruby.html +24 -24
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +8 -8
- data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
- data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +20 -20
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +30 -30
- data/doc-api/classes/Erubis/RubyEvaluator.html +12 -12
- data/doc-api/classes/Erubis/RubyGenerator.html +48 -48
- data/doc-api/classes/Erubis/SchemeGenerator.html +60 -60
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +8 -8
- data/doc-api/classes/Erubis/StdoutEnhancer.html +12 -12
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +12 -12
- data/doc-api/classes/Erubis/TinyEruby.html +24 -24
- data/doc-api/classes/Erubis/XmlHelper.html +14 -14
- data/doc-api/created.rid +1 -1
- data/doc-api/files/README_txt.html +4 -4
- data/doc-api/files/erubis/context_rb.html +2 -2
- data/doc-api/files/erubis/converter_rb.html +2 -2
- data/doc-api/files/erubis/engine/ec_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
- data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
- data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
- data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
- data/doc-api/files/erubis/engine/eruby_rb.html +2 -2
- data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
- data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
- data/doc-api/files/erubis/engine_rb.html +2 -2
- data/doc-api/files/erubis/enhancer_rb.html +2 -2
- data/doc-api/files/erubis/error_rb.html +2 -2
- data/doc-api/files/erubis/evaluator_rb.html +2 -2
- data/doc-api/files/erubis/generator_rb.html +2 -2
- data/doc-api/files/erubis/helper_rb.html +2 -2
- data/doc-api/files/erubis/helpers/rails_helper_rb.html +2 -2
- data/doc-api/files/erubis/local-setting_rb.html +2 -2
- data/doc-api/files/erubis/main_rb.html +2 -2
- data/doc-api/files/erubis/tiny_rb.html +2 -2
- data/doc-api/files/erubis_rb.html +1 -1
- data/doc-api/fr_class_index.html +8 -1
- data/doc-api/fr_method_index.html +166 -158
- data/doc/users-guide.html +623 -215
- data/lib/erubis.rb +2 -2
- data/lib/erubis/context.rb +2 -2
- data/lib/erubis/converter.rb +2 -2
- data/lib/erubis/engine.rb +3 -3
- data/lib/erubis/engine/ec.rb +2 -2
- data/lib/erubis/engine/ejava.rb +2 -2
- data/lib/erubis/engine/ejavascript.rb +2 -2
- data/lib/erubis/engine/enhanced.rb +17 -2
- data/lib/erubis/engine/eperl.rb +2 -2
- data/lib/erubis/engine/ephp.rb +2 -2
- data/lib/erubis/engine/eruby.rb +10 -2
- data/lib/erubis/engine/escheme.rb +2 -2
- data/lib/erubis/engine/optimized.rb +2 -2
- data/lib/erubis/enhancer.rb +134 -25
- data/lib/erubis/error.rb +2 -2
- data/lib/erubis/evaluator.rb +2 -2
- data/lib/erubis/generator.rb +2 -2
- data/lib/erubis/helper.rb +2 -2
- data/lib/erubis/helpers/rails_helper.rb +19 -75
- data/lib/erubis/local-setting.rb +2 -2
- data/lib/erubis/main.rb +63 -36
- data/lib/erubis/tiny.rb +2 -2
- data/test/assert-text-equal.rb +2 -2
- data/test/data/users-guide/Example.ejava +55 -0
- data/test/data/users-guide/array_example.result +9 -0
- data/test/data/users-guide/arraybuffer_example.result +9 -0
- data/test/data/users-guide/bipattern-example.rhtml +4 -0
- data/test/data/users-guide/bipattern_example.result +6 -0
- data/test/data/users-guide/context.rb +6 -0
- data/test/data/users-guide/context.yaml +8 -0
- data/test/data/users-guide/escape_example.result +9 -0
- data/test/data/users-guide/example.ec +27 -0
- data/test/data/users-guide/example.ejs +20 -0
- data/test/data/users-guide/example.eperl +18 -0
- data/test/data/users-guide/example.ephp +18 -0
- data/test/data/users-guide/example.eruby +6 -0
- data/test/data/users-guide/example.escheme +28 -0
- data/test/data/users-guide/example1.eruby +6 -0
- data/test/data/users-guide/example1.rb +16 -0
- data/test/data/users-guide/example1.result +16 -0
- data/test/data/users-guide/example10.rb +4 -0
- data/test/data/users-guide/example10.result +17 -0
- data/test/data/users-guide/example10.xhtml +14 -0
- data/test/data/users-guide/example10_x.result +17 -0
- data/test/data/users-guide/example11.php +20 -0
- data/test/data/users-guide/example11.result +23 -0
- data/test/data/users-guide/example11.rhtml +21 -0
- data/test/data/users-guide/example11_C.result +10 -0
- data/test/data/users-guide/example11_N.result +16 -0
- data/test/data/users-guide/example11_U.result +16 -0
- data/test/data/users-guide/example11_php.result +15 -0
- data/test/data/users-guide/example1_x.result +9 -0
- data/test/data/users-guide/example2.eruby +7 -0
- data/test/data/users-guide/example2.rb +10 -0
- data/test/data/users-guide/example2.result +27 -0
- data/test/data/users-guide/example2_trim.result +10 -0
- data/test/data/users-guide/example2_x.result +10 -0
- data/test/data/users-guide/example3.eruby +6 -0
- data/test/data/users-guide/example3.rb +10 -0
- data/test/data/users-guide/example31.result +22 -0
- data/test/data/users-guide/example32.result +4 -0
- data/test/data/users-guide/example3_e.result +8 -0
- data/test/data/users-guide/example4.eruby +3 -0
- data/test/data/users-guide/example4.rb +11 -0
- data/test/data/users-guide/example4.result +10 -0
- data/test/data/users-guide/example4_x.result +5 -0
- data/test/data/users-guide/example5.eruby +6 -0
- data/test/data/users-guide/example5.rb +16 -0
- data/test/data/users-guide/example5.result +7 -0
- data/test/data/users-guide/example6.rb +12 -0
- data/test/data/users-guide/example6.result +7 -0
- data/test/data/users-guide/example7.eruby +8 -0
- data/test/data/users-guide/example71.result +13 -0
- data/test/data/users-guide/example72.result +13 -0
- data/test/data/users-guide/example8.eruby +6 -0
- data/test/data/users-guide/example8_ruby.result +7 -0
- data/test/data/users-guide/example8_yaml.result +7 -0
- data/test/data/users-guide/example9.eruby +3 -0
- data/test/data/users-guide/example9.rb +8 -0
- data/test/data/users-guide/example9.result +9 -0
- data/test/data/users-guide/example91.result +5 -0
- data/test/data/users-guide/example92.result +4 -0
- data/test/data/users-guide/example_c.result +29 -0
- data/test/data/users-guide/example_java.result +56 -0
- data/test/data/users-guide/example_js.result +22 -0
- data/test/data/users-guide/example_perl.result +20 -0
- data/test/data/users-guide/example_php.result +19 -0
- data/test/data/users-guide/example_scheme.result +30 -0
- data/test/data/users-guide/example_scheme_display.result +29 -0
- data/test/data/users-guide/fasteruby.rb +11 -0
- data/test/data/users-guide/fasteruby.result +38 -0
- data/test/data/users-guide/fasteruby.rhtml +15 -0
- data/test/data/users-guide/headerfooter-example.eruby +9 -0
- data/test/data/users-guide/headerfooter-example2.rb +8 -0
- data/test/data/users-guide/headerfooter-example2.rhtml +10 -0
- data/test/data/users-guide/headerfooter_example.result +11 -0
- data/test/data/users-guide/headerfooter_example2.result +13 -0
- data/test/data/users-guide/interpolation_example.result +9 -0
- data/test/data/users-guide/nocode-example.eruby +14 -0
- data/test/data/users-guide/nocode-php.result +20 -0
- data/test/data/users-guide/nocode_example.result +15 -0
- data/test/data/users-guide/normal-eruby-test.eruby +9 -0
- data/test/data/users-guide/normal_eruby_test.result +11 -0
- data/test/data/users-guide/notext-example.eruby +14 -0
- data/test/data/users-guide/notext-example.php +19 -0
- data/test/data/users-guide/notext-php.result +20 -0
- data/test/data/users-guide/notext_example.result +16 -0
- data/test/data/users-guide/percentline-example.rhtml +4 -0
- data/test/data/users-guide/percentline_example.result +7 -0
- data/test/data/users-guide/printenable_example.result +4 -0
- data/test/data/users-guide/printenabled-example.eruby +3 -0
- data/test/data/users-guide/printenabled-example.rb +8 -0
- data/test/data/users-guide/printstatement_example.result +8 -0
- data/test/data/users-guide/simplify_example.result +9 -0
- data/test/data/users-guide/stdout_exmple.result +9 -0
- data/test/data/users-guide/stringbuffer_example.result +9 -0
- data/test/test-engines.rb +2 -2
- data/test/test-enhancers.rb +569 -0
- data/test/test-erubis.rb +3 -380
- data/test/test-main.rb +39 -15
- data/test/test-users-guide.rb +56 -0
- data/test/test.rb +4 -3
- data/test/testutil.rb +2 -2
- metadata +166 -57
- data/benchmark/erubybench-lib.rb +0 -189
- data/benchmark/erubybench.rb +0 -600
- data/bin/notext +0 -154
- data/test/test-notext.rb +0 -27
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'erubis'
|
|
2
|
+
input = File.read('example1.eruby')
|
|
3
|
+
eruby = Erubis::Eruby.new(input) # create Eruby object
|
|
4
|
+
|
|
5
|
+
puts "---------- script source ---"
|
|
6
|
+
puts eruby.src # print script source
|
|
7
|
+
|
|
8
|
+
puts "---------- result ----------"
|
|
9
|
+
list = ['aaa', 'bbb', 'ccc']
|
|
10
|
+
puts eruby.result(binding()) # get result
|
|
11
|
+
|
|
12
|
+
## # or
|
|
13
|
+
## eruby = Erubis::Eruby.new
|
|
14
|
+
## input = File.read('example1.eruby')
|
|
15
|
+
## src = eruby.convert(input)
|
|
16
|
+
## eval src
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
$ ruby example1.rb
|
|
2
|
+
---------- script source ---
|
|
3
|
+
_buf = ''; _buf << '<ul>
|
|
4
|
+
'; for item in list
|
|
5
|
+
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
|
|
6
|
+
'; end
|
|
7
|
+
|
|
8
|
+
_buf << '</ul>
|
|
9
|
+
';
|
|
10
|
+
_buf.to_s
|
|
11
|
+
---------- result ----------
|
|
12
|
+
<ul>
|
|
13
|
+
<li>aaa</li>
|
|
14
|
+
<li>bbb</li>
|
|
15
|
+
<li>ccc</li>
|
|
16
|
+
</ul>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
$ ruby example10.rb
|
|
2
|
+
_buf = ''; _buf << '<?xml version="1.0" ?>
|
|
3
|
+
';
|
|
4
|
+
lang = 'en'
|
|
5
|
+
list = ['<aaa>', 'b&b', '"ccc"']
|
|
6
|
+
|
|
7
|
+
_buf << '<html lang="'; _buf << (lang).to_s; _buf << '">
|
|
8
|
+
<body>
|
|
9
|
+
<ul>
|
|
10
|
+
'; for item in list
|
|
11
|
+
_buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << '</li>
|
|
12
|
+
'; end
|
|
13
|
+
_buf << ' </ul>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
16
|
+
';
|
|
17
|
+
_buf.to_s
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
$ erubis -x --pi example10.xhtml
|
|
2
|
+
_buf = ''; _buf << '<?xml version="1.0" ?>
|
|
3
|
+
';
|
|
4
|
+
lang = 'en'
|
|
5
|
+
list = ['<aaa>', 'b&b', '"ccc"']
|
|
6
|
+
|
|
7
|
+
_buf << '<html lang="'; _buf << (lang).to_s; _buf << '">
|
|
8
|
+
<body>
|
|
9
|
+
<ul>
|
|
10
|
+
'; for item in list
|
|
11
|
+
_buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << '</li>
|
|
12
|
+
'; end
|
|
13
|
+
_buf << ' </ul>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
16
|
+
';
|
|
17
|
+
_buf.to_s
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0"?>
|
|
2
|
+
<html>
|
|
3
|
+
<body>
|
|
4
|
+
<h3>List</h3>
|
|
5
|
+
<?php if (!$list) { ?>
|
|
6
|
+
<p>not found.</p>
|
|
7
|
+
<?php } else { ?>
|
|
8
|
+
<table>
|
|
9
|
+
<tbody>
|
|
10
|
+
<?php $i = 0; ?>
|
|
11
|
+
<?php foreach ($list as $item) { ?>
|
|
12
|
+
<tr bgcolor="<?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?>">
|
|
13
|
+
<td><?php echo $item; ?></td>
|
|
14
|
+
</tr>
|
|
15
|
+
<?php } ?>
|
|
16
|
+
</tbody>
|
|
17
|
+
</table>
|
|
18
|
+
<?php } ?>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
$ erubis -X example11.rhtml
|
|
2
|
+
_buf = '';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if @list.nil? || @list.empty?
|
|
9
|
+
|
|
10
|
+
else
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@list.each_with_index do |item, i|
|
|
14
|
+
_buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s;
|
|
15
|
+
_buf << ( item ).to_s;
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
_buf.to_s
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
5
|
+
<body>
|
|
6
|
+
<h3>List</h3>
|
|
7
|
+
<% if @list.nil? || @list.empty? %>
|
|
8
|
+
<p>not found.</p>
|
|
9
|
+
<% else %>
|
|
10
|
+
<table>
|
|
11
|
+
<tbody>
|
|
12
|
+
<% @list.each_with_index do |item, i| %>
|
|
13
|
+
<tr bgcolor="<%= i % 2 == 0 ? '#FCC' : '#CCF' %>">
|
|
14
|
+
<td><%= item %></td>
|
|
15
|
+
</tr>
|
|
16
|
+
<% end %>
|
|
17
|
+
</tbody>
|
|
18
|
+
</table>
|
|
19
|
+
<% end %>
|
|
20
|
+
</body>
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
$ erubis -XNU example11.rhtml
|
|
2
|
+
1: _buf = '';
|
|
3
|
+
|
|
4
|
+
7: if @list.nil? || @list.empty?
|
|
5
|
+
|
|
6
|
+
9: else
|
|
7
|
+
|
|
8
|
+
12: @list.each_with_index do |item, i|
|
|
9
|
+
13: _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s;
|
|
10
|
+
14: _buf << ( item ).to_s;
|
|
11
|
+
|
|
12
|
+
16: end
|
|
13
|
+
|
|
14
|
+
19: end
|
|
15
|
+
|
|
16
|
+
22: _buf.to_s
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
$ erubis -XNU -l php --pi=php --trim=false example11.php
|
|
2
|
+
|
|
3
|
+
5: <?php if (!$list) { ?>
|
|
4
|
+
|
|
5
|
+
7: <?php } else { ?>
|
|
6
|
+
|
|
7
|
+
10: <?php $i = 0; ?>
|
|
8
|
+
11: <?php foreach ($list as $item) { ?>
|
|
9
|
+
12: <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?>
|
|
10
|
+
13: <?php echo $item; ?>
|
|
11
|
+
|
|
12
|
+
15: <?php } ?>
|
|
13
|
+
|
|
14
|
+
18: <?php } ?>
|
|
15
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'erubis'
|
|
2
|
+
input = File.read('example2.eruby')
|
|
3
|
+
eruby = Erubis::Eruby.new(input, :trim=>false)
|
|
4
|
+
|
|
5
|
+
puts "----- script source ---"
|
|
6
|
+
puts eruby.src # print script source
|
|
7
|
+
|
|
8
|
+
puts "----- result ----------"
|
|
9
|
+
list = ['aaa', 'bbb', 'ccc']
|
|
10
|
+
puts eruby.result(binding()) # get result
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
$ ruby example2.rb
|
|
2
|
+
----- script source ---
|
|
3
|
+
_buf = ''; _buf << '<ul>
|
|
4
|
+
'; _buf << ' '; for item in list ; _buf << '
|
|
5
|
+
'; _buf << ' <li>
|
|
6
|
+
'; _buf << ( item ).to_s; _buf << '
|
|
7
|
+
'; _buf << ' </li>
|
|
8
|
+
'; _buf << ' '; end ; _buf << '
|
|
9
|
+
'; _buf << '</ul>
|
|
10
|
+
';
|
|
11
|
+
_buf.to_s
|
|
12
|
+
----- result ----------
|
|
13
|
+
<ul>
|
|
14
|
+
|
|
15
|
+
<li>
|
|
16
|
+
aaa
|
|
17
|
+
</li>
|
|
18
|
+
|
|
19
|
+
<li>
|
|
20
|
+
bbb
|
|
21
|
+
</li>
|
|
22
|
+
|
|
23
|
+
<li>
|
|
24
|
+
ccc
|
|
25
|
+
</li>
|
|
26
|
+
|
|
27
|
+
</ul>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
$ erubis -x --trim=false example2.eruby
|
|
2
|
+
_buf = ''; _buf << '<ul>
|
|
3
|
+
'; _buf << ' '; for item in list ; _buf << '
|
|
4
|
+
'; _buf << ' <li>
|
|
5
|
+
'; _buf << ( item ).to_s; _buf << '
|
|
6
|
+
'; _buf << ' </li>
|
|
7
|
+
'; _buf << ' '; end ; _buf << '
|
|
8
|
+
'; _buf << '</ul>
|
|
9
|
+
';
|
|
10
|
+
_buf.to_s
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'erubis'
|
|
2
|
+
input = File.read('example3.eruby')
|
|
3
|
+
eruby = Erubis::EscapedEruby.new(input) # or Erubis::XmlEruby
|
|
4
|
+
|
|
5
|
+
puts "----- script source ---"
|
|
6
|
+
puts eruby.src # print script source
|
|
7
|
+
|
|
8
|
+
puts "----- result ----------"
|
|
9
|
+
list = ['<aaa>', 'b&b', '"ccc"']
|
|
10
|
+
puts eruby.result(binding()) # get result
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
$ ruby example3.rb 2> stderr.log
|
|
2
|
+
----- script source ---
|
|
3
|
+
_buf = ''; for item in list
|
|
4
|
+
_buf << ' <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p>
|
|
5
|
+
<p>'; _buf << ( item ).to_s; _buf << '</p>
|
|
6
|
+
<p>'; $stderr.puts("*** debug: item=#{(item).inspect}"); _buf << '</p>
|
|
7
|
+
|
|
8
|
+
'; end
|
|
9
|
+
_buf.to_s
|
|
10
|
+
----- result ----------
|
|
11
|
+
<p><aaa></p>
|
|
12
|
+
<p><aaa></p>
|
|
13
|
+
<p></p>
|
|
14
|
+
|
|
15
|
+
<p>b&b</p>
|
|
16
|
+
<p>b&b</p>
|
|
17
|
+
<p></p>
|
|
18
|
+
|
|
19
|
+
<p>"ccc"</p>
|
|
20
|
+
<p>"ccc"</p>
|
|
21
|
+
<p></p>
|
|
22
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
$ erubis -l ruby -e example3.eruby
|
|
2
|
+
_buf = ''; for item in list
|
|
3
|
+
_buf << ' <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p>
|
|
4
|
+
<p>'; _buf << ( item ).to_s; _buf << '</p>
|
|
5
|
+
<p>'; $stderr.puts("*** debug: item=#{(item).inspect}"); _buf << '</p>
|
|
6
|
+
|
|
7
|
+
'; end
|
|
8
|
+
_buf.to_s
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'erubis'
|
|
2
|
+
input = File.read('example4.eruby')
|
|
3
|
+
eruby = Erubis::Eruby.new(input, :pattern=>'<!--% %-->')
|
|
4
|
+
# or '<(?:!--)?% %(?:--)?>'
|
|
5
|
+
|
|
6
|
+
puts "---------- script source ---"
|
|
7
|
+
puts eruby.src # print script source
|
|
8
|
+
|
|
9
|
+
puts "---------- result ----------"
|
|
10
|
+
list = ['aaa', 'bbb', 'ccc']
|
|
11
|
+
puts eruby.result(binding()) # get result
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'erubis'
|
|
2
|
+
input = File.read('example5.eruby')
|
|
3
|
+
eruby = Erubis::Eruby.new(input) # create Eruby object
|
|
4
|
+
|
|
5
|
+
## create context object
|
|
6
|
+
## (key means var name, which may be string or symbol.)
|
|
7
|
+
context = {
|
|
8
|
+
:val => 'Erubis Example',
|
|
9
|
+
'list' => ['aaa', 'bbb', 'ccc'],
|
|
10
|
+
}
|
|
11
|
+
## or
|
|
12
|
+
# context = Erubis::Context.new()
|
|
13
|
+
# context['val'] = 'Erubis Example'
|
|
14
|
+
# context[:list] = ['aaa', 'bbb', 'ccc'],
|
|
15
|
+
|
|
16
|
+
puts eruby.evaluate(context) # get result
|