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
data/CHANGES
CHANGED
|
@@ -1,8 +1,125 @@
|
|
|
1
|
-
# $Rev:
|
|
2
|
-
# $Release: 2.
|
|
1
|
+
# $Rev: 78 $
|
|
2
|
+
# $Release: 2.3.0 $
|
|
3
3
|
# copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
#
|
|
7
|
+
- release: 2.3.0
|
|
8
|
+
date:
|
|
9
|
+
enhancements:
|
|
10
|
+
- |
|
|
11
|
+
New class 'Erubis::FastEruby' is added.
|
|
12
|
+
It is a subclass of Erubis::Eruby and includes InterpolationEnhancer.
|
|
13
|
+
Erubis::FastEruby is compatible with and faster than Erubis::Eruby.
|
|
14
|
+
|
|
15
|
+
- |
|
|
16
|
+
New enhancer 'InterpolationEnhancer' is added.
|
|
17
|
+
This enhancer uses expression interpolation to eliminate method call
|
|
18
|
+
of String#<<. In the result, this enhancer makes Eruby a little faster.
|
|
19
|
+
|
|
20
|
+
--------------------
|
|
21
|
+
## Assume that input is '<a href="<%=url%>"><%=name%></a>'.
|
|
22
|
+
## Eruby convert input into the following code. String#<< is called 5 times.
|
|
23
|
+
_buf << '<a href="'; _buf << (url).to_s; _buf << '">'; _buf << (name).to_s; _buf << '</a>';
|
|
24
|
+
|
|
25
|
+
## When InterpolationEnhancer is used, String#<< is called only once.
|
|
26
|
+
_buf << %Q`<a href="#{url}">#{name}</a>`;
|
|
27
|
+
--------------------
|
|
28
|
+
|
|
29
|
+
- |
|
|
30
|
+
New enhancer 'ErboutEnhancer' is added.
|
|
31
|
+
ErboutEnhancer set '_erbout' as well as '_buf' to be compatible with ERB.
|
|
32
|
+
|
|
33
|
+
ex.
|
|
34
|
+
====================
|
|
35
|
+
$ cat ex.rhtml
|
|
36
|
+
<p>Hello</p>
|
|
37
|
+
$ erubis -x ex.rhtml
|
|
38
|
+
_buf = ''; _buf << '<p>Hello</p>
|
|
39
|
+
';
|
|
40
|
+
_buf.to_s
|
|
41
|
+
$ erubis -xE Erbout ex.rhtml
|
|
42
|
+
_erbout = _buf = ''; _buf << '<p>Hello</p>
|
|
43
|
+
';
|
|
44
|
+
_buf.to_s
|
|
45
|
+
====================
|
|
46
|
+
|
|
47
|
+
- |
|
|
48
|
+
[experimental]
|
|
49
|
+
New enhancer 'DeleteIndentEnhancer' is added.
|
|
50
|
+
This enhancer deletes indentation of HTML file.
|
|
51
|
+
|
|
52
|
+
ex.
|
|
53
|
+
====================
|
|
54
|
+
$ cat ex.rhtml
|
|
55
|
+
<div>
|
|
56
|
+
<ul>
|
|
57
|
+
<% for item in ['AAA', 'BBB', 'CCC'] %>
|
|
58
|
+
<li><%= item %></li>
|
|
59
|
+
<% end %>
|
|
60
|
+
</ul>
|
|
61
|
+
</div>
|
|
62
|
+
$ erubis ex.rhtml
|
|
63
|
+
<div>
|
|
64
|
+
<ul>
|
|
65
|
+
<li>AAA</li>
|
|
66
|
+
<li>BBB</li>
|
|
67
|
+
<li>CCC</li>
|
|
68
|
+
</ul>
|
|
69
|
+
</div>
|
|
70
|
+
$ erubis -E DeleteIndent ex.rhtml
|
|
71
|
+
<div>
|
|
72
|
+
<ul>
|
|
73
|
+
<li>AAA</li>
|
|
74
|
+
<li>BBB</li>
|
|
75
|
+
<li>CCC</li>
|
|
76
|
+
</ul>
|
|
77
|
+
</div>
|
|
78
|
+
====================
|
|
79
|
+
|
|
80
|
+
- |
|
|
81
|
+
Mod_ruby is supported (very thanks to Andrew R Jackson!).
|
|
82
|
+
See users-guide and 'contrib/erubis-run.rb' for details.
|
|
83
|
+
|
|
84
|
+
- |
|
|
85
|
+
New command-line option '-X', '-N', '-U', and '-C' are added.
|
|
86
|
+
These are intended to be a replacement of 'notext' command.
|
|
87
|
+
'-X' shows only ruby statements and expressions.
|
|
88
|
+
'-N' adds line numbers.
|
|
89
|
+
'-U' compress empty lines into a line.
|
|
90
|
+
'-C' removes empty lines.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
changes:
|
|
94
|
+
|
|
95
|
+
- |
|
|
96
|
+
'helpers/rails_helper.rb' is changed to use ErboutEnhancer.
|
|
97
|
+
The following is an examle to use Erubis with Ruby on Rails.
|
|
98
|
+
|
|
99
|
+
File 'config/environment.rb':
|
|
100
|
+
----------------------------------------
|
|
101
|
+
require 'erubis/helpers/rails_helper'
|
|
102
|
+
#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
|
|
103
|
+
#Erubis::Helpers::RailsHelper.init_properties = {}
|
|
104
|
+
#Erubis::Helpers::RailsHelper.show_src = false # set true for debugging
|
|
105
|
+
----------------------------------------
|
|
106
|
+
|
|
107
|
+
- |
|
|
108
|
+
Command 'notext' has been removed. Use '-X', '-N', '-U', and '-C'
|
|
109
|
+
instead.
|
|
110
|
+
|
|
111
|
+
- |
|
|
112
|
+
Tab characters in YAML file are expaneded automatically.
|
|
113
|
+
If you want not to expand tab characters, add command-line optio '-T'.
|
|
114
|
+
|
|
115
|
+
- |
|
|
116
|
+
Benchmark scripts (benchmark/bench.*) are rewrited.
|
|
117
|
+
|
|
118
|
+
- |
|
|
119
|
+
Users-guide (doc/users-guide.html) is updated.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
6
123
|
#
|
|
7
124
|
- release: 2.2.0
|
|
8
125
|
date: 2007-02-11
|
|
@@ -78,7 +195,7 @@
|
|
|
78
195
|
$ erubis -c '{title: Example, list: [AAA, BBB, CCC]}' example.rhtml
|
|
79
196
|
====================
|
|
80
197
|
|
|
81
|
-
ex.
|
|
198
|
+
ex. Ruby style
|
|
82
199
|
====================
|
|
83
200
|
$ erubis -c '@title="Example"; @list=%w[AAA BBB CCC]' example.rhtml
|
|
84
201
|
====================
|
data/README.txt
CHANGED
data/benchmark/Makefile
ADDED
data/benchmark/bench.rb
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
###
|
|
4
|
+
### $Rev: 77 $
|
|
5
|
+
### $Release: 2.3.0 $
|
|
6
|
+
### copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
7
|
+
###
|
|
8
|
+
|
|
9
|
+
require 'erb'
|
|
10
|
+
require 'erubis'
|
|
11
|
+
require 'erubis/tiny'
|
|
12
|
+
require 'erubis/engine/enhanced'
|
|
13
|
+
require 'yaml'
|
|
14
|
+
require 'cgi'
|
|
15
|
+
include ERB::Util
|
|
16
|
+
|
|
17
|
+
begin
|
|
18
|
+
require 'eruby'
|
|
19
|
+
rescue LoadError
|
|
20
|
+
ERuby = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def File.write(filename, content)
|
|
24
|
+
File.open(filename, 'w') { |f| f.write(content) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## change benchmark library to use $stderr instead of $stdout
|
|
29
|
+
require 'benchmark'
|
|
30
|
+
module Benchmark
|
|
31
|
+
class Report
|
|
32
|
+
def print(*args)
|
|
33
|
+
$stderr.print(*args)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
module_function
|
|
37
|
+
def print(*args)
|
|
38
|
+
$stderr.print(*args)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class BenchmarkApplication
|
|
44
|
+
|
|
45
|
+
TARGETS = %w[eruby
|
|
46
|
+
ERB ERB(cached)
|
|
47
|
+
Erubis::Eruby Erubis::Eruby(cached)
|
|
48
|
+
Erubis::FastEruby Erubis::FastEruby(cached)
|
|
49
|
+
Erubis::TinyEruby
|
|
50
|
+
Erubis::ArrayBufferEruby
|
|
51
|
+
Erubis::PrintOutEruby
|
|
52
|
+
Erubis::StdoutEruby
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
def initialize(ntimes, context, targets=nil, params={})
|
|
56
|
+
@ntimes = ntimes
|
|
57
|
+
@context = context
|
|
58
|
+
@targets = targets && !targets.empty? ? targets : TARGETS.dup
|
|
59
|
+
@testmode = params[:testmode] || 'execute'
|
|
60
|
+
@erubyfile = params[:erubyfile] || 'erubybench.rhtml'
|
|
61
|
+
@printout = params[:printout] || false
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
attr_accessor :ntimes, :targets
|
|
65
|
+
attr_accessor :testmode, :erubyfile, :contextfile, :printout
|
|
66
|
+
|
|
67
|
+
def context2code(context, varname='context')
|
|
68
|
+
s = ''
|
|
69
|
+
context.each { |k, | s << "#{k} = #{varname}[#{k.inspect}]; " }
|
|
70
|
+
return s
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def perform_benchmark
|
|
74
|
+
width = 30
|
|
75
|
+
$stderr.puts "*** ntimes=#{@ntimes}, testmode=#{@testmode}"
|
|
76
|
+
Benchmark.bm(width) do |job|
|
|
77
|
+
for target in @targets do
|
|
78
|
+
method = "#{@testmode}_#{target.gsub(/::|-|\(/, '_').gsub(/\)/, '').downcase}"
|
|
79
|
+
#$stderr.puts "*** debug: method=#{method.inspect}"
|
|
80
|
+
next unless self.respond_to?(method)
|
|
81
|
+
filename = "bench_#{(target =~ /^(\w+)/) && $1.downcase}.rhtml"
|
|
82
|
+
title = target
|
|
83
|
+
output = nil
|
|
84
|
+
job.report(title) do
|
|
85
|
+
output = self.__send__(method, filename, @context)
|
|
86
|
+
end
|
|
87
|
+
File.write("output.#{target.gsub(/[^\w]/,'')}", output) if @printout && output && !output.empty?
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
##
|
|
93
|
+
|
|
94
|
+
def execute_eruby(filename, context)
|
|
95
|
+
return unless ERuby
|
|
96
|
+
eval context2code(context)
|
|
97
|
+
@ntimes.times do
|
|
98
|
+
ERuby.import(filename)
|
|
99
|
+
end
|
|
100
|
+
return nil
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def execute_erb(filename, context)
|
|
104
|
+
eval context2code(context)
|
|
105
|
+
output = nil
|
|
106
|
+
@ntimes.times do
|
|
107
|
+
eruby = ERB.new(File.read(filename))
|
|
108
|
+
output = eruby.result(binding())
|
|
109
|
+
print output
|
|
110
|
+
end
|
|
111
|
+
return output
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def execute_erb_cached(filename, context)
|
|
115
|
+
eval context2code(context)
|
|
116
|
+
output = nil
|
|
117
|
+
cachefile = filename + '.cache'
|
|
118
|
+
File.unlink(cachefile) if test(?f, cachefile)
|
|
119
|
+
@ntimes.times do
|
|
120
|
+
if !test(?f, cachefile) || File.mtime(filename) > File.mtime(cachefile)
|
|
121
|
+
eruby = ERB.new(File.read(filename))
|
|
122
|
+
File.write(cachefile, eruby.src)
|
|
123
|
+
else
|
|
124
|
+
eruby = ERB.new('')
|
|
125
|
+
#eruby.src = File.read(cachefile)
|
|
126
|
+
eruby.instance_variable_set("@src", File.read(cachefile))
|
|
127
|
+
end
|
|
128
|
+
output = eruby.result(binding())
|
|
129
|
+
print output
|
|
130
|
+
end
|
|
131
|
+
return output
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
## no cached
|
|
135
|
+
for klass in %w[Eruby FastEruby TinyEruby ArrayBufferEruby PrintOutEruby StdoutEruby] do
|
|
136
|
+
s = <<-END
|
|
137
|
+
def execute_erubis_#{klass.downcase}(filename, context)
|
|
138
|
+
eval context2code(context)
|
|
139
|
+
output = nil
|
|
140
|
+
@ntimes.times do
|
|
141
|
+
eruby = Erubis::#{klass}.new(File.read(filename))
|
|
142
|
+
output = eruby.result(binding())
|
|
143
|
+
print output
|
|
144
|
+
end
|
|
145
|
+
return output
|
|
146
|
+
end
|
|
147
|
+
END
|
|
148
|
+
eval s
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
## cached
|
|
152
|
+
for klass in %w[Eruby FastEruby] do
|
|
153
|
+
s = <<-END
|
|
154
|
+
def execute_erubis_#{klass.downcase}_cached(filename, context)
|
|
155
|
+
eval context2code(context)
|
|
156
|
+
cachefile = filename + '.cache'
|
|
157
|
+
File.unlink(cachefile) if test(?f, cachefile)
|
|
158
|
+
output = nil
|
|
159
|
+
@ntimes.times do
|
|
160
|
+
eruby = Erubis::#{klass}.load_file(filename)
|
|
161
|
+
output = eruby.result(binding())
|
|
162
|
+
print output
|
|
163
|
+
end
|
|
164
|
+
savefile = cachefile.sub(/\\.cache$/, '.#{klass.downcase}.cache')
|
|
165
|
+
File.rename(cachefile, savefile)
|
|
166
|
+
return output
|
|
167
|
+
end
|
|
168
|
+
END
|
|
169
|
+
eval s
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
##
|
|
173
|
+
|
|
174
|
+
def convert_eruby(filename, context)
|
|
175
|
+
return unless ERuby
|
|
176
|
+
eval context2code(context)
|
|
177
|
+
output = nil
|
|
178
|
+
@ntimes.times do
|
|
179
|
+
output = ERuby::Compiler.new.compile_string(File.read(filename))
|
|
180
|
+
end
|
|
181
|
+
return output
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def convert_erb(filename, context)
|
|
185
|
+
eval context2code(context)
|
|
186
|
+
output = nil
|
|
187
|
+
@ntimes.times do
|
|
188
|
+
eruby = ERB.new(File.read(filename))
|
|
189
|
+
output = eruby.src
|
|
190
|
+
end
|
|
191
|
+
return output
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
for klass in %w[Eruby FastEruby TinyEruby]
|
|
195
|
+
s = <<-END
|
|
196
|
+
def convert_erubis_#{klass.downcase}(filename, context)
|
|
197
|
+
eval context2code(context)
|
|
198
|
+
output = nil
|
|
199
|
+
@ntimes.times do
|
|
200
|
+
eruby = Erubis::#{klass}.new(File.read(filename))
|
|
201
|
+
output = eruby.src
|
|
202
|
+
end
|
|
203
|
+
return output
|
|
204
|
+
end
|
|
205
|
+
END
|
|
206
|
+
eval s
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
require 'optparse'
|
|
213
|
+
|
|
214
|
+
class MainApplication
|
|
215
|
+
|
|
216
|
+
def parse_argv(argv=ARGV)
|
|
217
|
+
optparser = OptionParser.new
|
|
218
|
+
options = {}
|
|
219
|
+
['-h', '-n N', '-t erubyfile', '-f contextfile', '-A', '-e',
|
|
220
|
+
'-x exclude', '-m testmode', '-X', '-p', '-D'].each do |opt|
|
|
221
|
+
optparser.on(opt) { |val| options[opt[1].chr] = val }
|
|
222
|
+
end
|
|
223
|
+
begin
|
|
224
|
+
targets = optparser.parse!(argv)
|
|
225
|
+
rescue => ex
|
|
226
|
+
$stderr.puts "#{@script}: #{ex.to_s}"
|
|
227
|
+
exit(1)
|
|
228
|
+
end
|
|
229
|
+
return options, targets
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def execute
|
|
233
|
+
@script = File.basename($0)
|
|
234
|
+
ntimes = 1000
|
|
235
|
+
targets = BenchmarkApplication::TARGETS.dup
|
|
236
|
+
testmode = 'execute'
|
|
237
|
+
contextfile = 'bench_context.yaml'
|
|
238
|
+
#
|
|
239
|
+
options, args = parse_argv(ARGV)
|
|
240
|
+
ntimes = options['n'].to_i if options['n']
|
|
241
|
+
targets = args if args && !args.empty?
|
|
242
|
+
targets = targets - options['x'].split(/,/) if options['x']
|
|
243
|
+
testmode = options['m'] if options['m']
|
|
244
|
+
contextfile = options['f'] if options['f']
|
|
245
|
+
erubyfile = options['t'] if options['t']
|
|
246
|
+
#
|
|
247
|
+
if options['h']
|
|
248
|
+
$stderr.puts "Usage: ruby #{@script} [..options..] [..targets..]"
|
|
249
|
+
$stderr.puts " -h : help"
|
|
250
|
+
$stderr.puts " -n N : loop N times"
|
|
251
|
+
$stderr.puts " -f datafile : context data filename (*.yaml)"
|
|
252
|
+
$stderr.puts " -x exclude : exclude target name"
|
|
253
|
+
$stdout.puts " -m testmode : 'execute' or 'convert' (default 'execute')"
|
|
254
|
+
$stderr.puts " -p : print output to file (filename: 'output.TARGETNAME')"
|
|
255
|
+
return
|
|
256
|
+
end
|
|
257
|
+
#
|
|
258
|
+
#if ! options['t']
|
|
259
|
+
for item in %w[eruby erb erubis]
|
|
260
|
+
fname = "bench_#{item}.rhtml"
|
|
261
|
+
header = File.read("templates/_header.html")
|
|
262
|
+
#body = File.read("templates/#{erubyfile}")
|
|
263
|
+
body = File.read("templates/#{fname}")
|
|
264
|
+
footer = File.read("templates/_footer.html")
|
|
265
|
+
content = header + body + footer
|
|
266
|
+
File.write(fname, content)
|
|
267
|
+
end
|
|
268
|
+
#
|
|
269
|
+
if options['e'] # escape
|
|
270
|
+
tuples = [
|
|
271
|
+
[ 'bench_eruby.rhtml', '<%= CGI.escapeHTML((\1).to_s) %>' ],
|
|
272
|
+
[ 'bench_erb.rhtml', '<%=h \1 %>' ],
|
|
273
|
+
[ 'bench_erubis.rhtml', '<%== \1 %>' ],
|
|
274
|
+
]
|
|
275
|
+
for fname, replace in tuples
|
|
276
|
+
content = File.read(fname).gsub(/<%= ?(.*?) ?%>/, replace)
|
|
277
|
+
File.write(fname, content)
|
|
278
|
+
end
|
|
279
|
+
targets.delete('Erubis::TinyEruby') ## because TinyEruby doesn't support '<%== =>'
|
|
280
|
+
end
|
|
281
|
+
#
|
|
282
|
+
context = YAML.load_file(contextfile)
|
|
283
|
+
#
|
|
284
|
+
params = {
|
|
285
|
+
:printout=>options['p'],
|
|
286
|
+
:testmode=>testmode,
|
|
287
|
+
}
|
|
288
|
+
app = BenchmarkApplication.new(ntimes, context, targets, params)
|
|
289
|
+
app.perform_benchmark()
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
if __FILE__ == $0
|
|
296
|
+
|
|
297
|
+
## open /dev/null
|
|
298
|
+
$stdout = File.open('/dev/null', 'w')
|
|
299
|
+
at_exit do
|
|
300
|
+
$stdout.close()
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
## start benchmark
|
|
304
|
+
MainApplication.new().execute()
|
|
305
|
+
|
|
306
|
+
end
|