erubis 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/benchmark/erubybench.rb
DELETED
@@ -1,600 +0,0 @@
|
|
1
|
-
##
|
2
|
-
## $Rev: 64 $
|
3
|
-
## $Release: 2.2.0 $
|
4
|
-
## copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
5
|
-
##
|
6
|
-
|
7
|
-
require 'eruby'
|
8
|
-
require 'erb'
|
9
|
-
require 'stringio'
|
10
|
-
require 'cgi'
|
11
|
-
include ERB::Util
|
12
|
-
#module ERB::Util
|
13
|
-
# ESCAPE_TABLE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
|
14
|
-
# def h(value)
|
15
|
-
# value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] }
|
16
|
-
# end
|
17
|
-
# module_function :h
|
18
|
-
#end
|
19
|
-
|
20
|
-
require 'erubis'
|
21
|
-
require 'erubis/engine/enhanced'
|
22
|
-
require 'erubis/engine/optimized'
|
23
|
-
require 'erubis/tiny'
|
24
|
-
require 'erubybench-lib'
|
25
|
-
|
26
|
-
|
27
|
-
## default value
|
28
|
-
defaults = {
|
29
|
-
:ntimes => 1000,
|
30
|
-
:erubyfile => 'erubybench.rhtml',
|
31
|
-
:datafile => 'erubybench.yaml',
|
32
|
-
:testmode => 'execute',
|
33
|
-
:outfile => '/dev/null',
|
34
|
-
}
|
35
|
-
|
36
|
-
|
37
|
-
## usage
|
38
|
-
def usage(defaults)
|
39
|
-
script = File.basename($0)
|
40
|
-
s = <<END
|
41
|
-
Usage: ruby #{script} [..options..] [..testnames..] > /dev/null 2> bench.log
|
42
|
-
-h : help
|
43
|
-
-n N : number of times to loop (default #{defaults[:ntimes]})
|
44
|
-
-t erubyfile : eruby filename (default '#{defaults[:erubyfile]}')
|
45
|
-
-f datafile : data filename (default '#{defaults[:datafile]}')
|
46
|
-
-o outfile : output filename (default '#{defaults[:outfile]}')
|
47
|
-
-A : test all targets
|
48
|
-
-x testname,.. : exclude testnames
|
49
|
-
-m testmode : execute/convert/func (default '#{defaults[:testmode]}')
|
50
|
-
-X : expand loop
|
51
|
-
-p : print output
|
52
|
-
END
|
53
|
-
return s
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
## parse command-line options
|
58
|
-
require 'optparse'
|
59
|
-
optparser = OptionParser.new
|
60
|
-
options = {}
|
61
|
-
['-h', '-n N', '-t erubyfile', '-f datafile', '-o outfile', '-A', '-e',
|
62
|
-
'-x exclude', '-m testmode', '-X', '-p', '-D'].each do |opt|
|
63
|
-
optparser.on(opt) { |val| options[opt[1].chr] = val }
|
64
|
-
end
|
65
|
-
begin
|
66
|
-
targets = optparser.parse!(ARGV)
|
67
|
-
rescue => ex
|
68
|
-
$stderr.puts "#{command}: #{ex.to_s}"
|
69
|
-
exit(1)
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
flag_help = options['h']
|
74
|
-
ntimes = (options['n'] || defaults[:ntimes]).to_i
|
75
|
-
$erubyfile = options['t'] || defaults[:erubyfile]
|
76
|
-
datafile = options['f'] || defaults[:datafile]
|
77
|
-
outfile = options['o'] || defaults[:outfile]
|
78
|
-
flag_all = options['A']
|
79
|
-
testmode = options['m'] || defaults[:testmode]
|
80
|
-
excludes = options['x']
|
81
|
-
$escape = options['e']
|
82
|
-
flag_expand = options['X'] ? true : false
|
83
|
-
flag_output = options['p'] ? true : false
|
84
|
-
$debug = options['D']
|
85
|
-
|
86
|
-
$ntimes = ntimes
|
87
|
-
|
88
|
-
$stderr.puts "** $ntimes=#{$ntimes.inspect}, flag_expand=#{flag_expand}, options=#{options.inspect}" if $debug
|
89
|
-
|
90
|
-
|
91
|
-
## help
|
92
|
-
if flag_help
|
93
|
-
puts usage(defaults)
|
94
|
-
exit()
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
## load data file
|
99
|
-
require 'yaml'
|
100
|
-
ydoc = YAML.load_file(datafile)
|
101
|
-
context = ydoc
|
102
|
-
list = context['list']
|
103
|
-
if $escape
|
104
|
-
list.each do |item|
|
105
|
-
if item['name'] =~ / /
|
106
|
-
item['name'] = "<#{item['name'].gsub(/ /, '&')}>"
|
107
|
-
else
|
108
|
-
item['name'] = "\"#{item['name']}\""
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
#list = []
|
113
|
-
#ydoc['list'].each do |hash|
|
114
|
-
# list << hash.inject({}) { |h, t| h[t[0].intern] = t[1]; h }
|
115
|
-
# #h = {}; hash.each { |k, v| h[k.intern] = v } ; data << h
|
116
|
-
#end
|
117
|
-
#require 'pp'; pp list
|
118
|
-
|
119
|
-
|
120
|
-
## test definitions
|
121
|
-
testdefs = YAML.load(DATA)
|
122
|
-
testdefs.each do |testdef|
|
123
|
-
c = testdef['class']
|
124
|
-
testdef['code'] ||= "print #{c}.new(File.read(erubyfile)).result(binding())\n"
|
125
|
-
testdef['compile'] ||= "#{c}.new(str).src\n"
|
126
|
-
#require 'pp'; pp testdef
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
## select test target
|
131
|
-
if flag_all
|
132
|
-
# nothing
|
133
|
-
elsif targets && !targets.empty?
|
134
|
-
testdefs = targets.collect { |t| testdefs.find { |h| h['name'] == t } }.compact
|
135
|
-
#testdefs.delete_if { |h| !targets.include?(h['name']) }
|
136
|
-
else
|
137
|
-
testdefs.delete_if { |h| h['skip'] }
|
138
|
-
end
|
139
|
-
|
140
|
-
## exclude target
|
141
|
-
if excludes
|
142
|
-
excludes = excluces.split(/,/)
|
143
|
-
testdefs.delete_if { |h| excludes.include?(h['name']) }
|
144
|
-
end
|
145
|
-
#require 'pp'; pp testdefs
|
146
|
-
|
147
|
-
|
148
|
-
## generate template
|
149
|
-
def erubyfilename(name)
|
150
|
-
case name
|
151
|
-
when /eruby/ ; s = '_eruby.'
|
152
|
-
when /ERB/ ; s = '_erb.'
|
153
|
-
when /PI/ ; s = '_pierubis.'
|
154
|
-
when /Tiny/ ; s = '_tiny.'
|
155
|
-
when /Erubis/ ; s = '_erubis.'
|
156
|
-
else
|
157
|
-
raise "#{name}: unknown name."
|
158
|
-
end
|
159
|
-
return $erubyfile.sub(/\./, s)
|
160
|
-
end
|
161
|
-
#
|
162
|
-
def File.write(filename, str)
|
163
|
-
File.open(filename, 'w') { |f| f.write(str) }
|
164
|
-
end
|
165
|
-
#
|
166
|
-
if $erubyfile == defaults[:erubyfile]
|
167
|
-
erubystr = File.read($erubyfile)
|
168
|
-
s = erubystr
|
169
|
-
erubystrs = {}
|
170
|
-
if $escape
|
171
|
-
erubystrs['eruby'] = s.gsub(/<%=(.*?)%>/, '<%= CGI.escapeHTML((\1).to_s) %>')
|
172
|
-
erubystrs['ERB'] = s.gsub(/<%=(.*?)%>/, '<%=h \1%>')
|
173
|
-
erubystrs['Erubis'] = s.gsub(/<%=(.*?)%>/, '<%==\1%>')
|
174
|
-
erubystrs['Tiny'] = s.gsub(/<%=(.*?)%>/, '<%=Erubis::XmlHelper.escape_xml((\1).to_s)%>')
|
175
|
-
erubystrs['PI'] = s.gsub(/<%=(.*?)%>/, '@{\1}@').gsub(/<%(.*?)%>/m, '<?rb\1?>')
|
176
|
-
else
|
177
|
-
erubystrs['eruby'] = s
|
178
|
-
erubystrs['ERB'] = s
|
179
|
-
erubystrs['Erubis'] = s
|
180
|
-
erubystrs['Tiny'] = s
|
181
|
-
erubystrs['PI'] = s.gsub(/<%=(.*?)%>/, '@!{\1}@').gsub(/<%(.*?)%>/m, '<?rb\1?>')
|
182
|
-
end
|
183
|
-
else
|
184
|
-
erubystr = File.read($erubyfile)
|
185
|
-
end
|
186
|
-
%w[eruby ERB PI Tiny Erubis].each do |name|
|
187
|
-
File.write(erubyfilename(name), erubystrs[name])
|
188
|
-
end
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
## define test functions for each classes
|
193
|
-
str = erubystr
|
194
|
-
testdefs.each do |h|
|
195
|
-
s = ''
|
196
|
-
s << "def test_execute_#{h['name']}(erubyfile, context)\n"
|
197
|
-
s << " list = context['list']\n"
|
198
|
-
if flag_expand
|
199
|
-
$ntimes.times do
|
200
|
-
s << " #{h['code']}\n"
|
201
|
-
end
|
202
|
-
else
|
203
|
-
s << " $ntimes.times do\n"
|
204
|
-
s << " #{h['code']}\n"
|
205
|
-
s << " end\n"
|
206
|
-
end
|
207
|
-
s << "end\n"
|
208
|
-
#puts s
|
209
|
-
eval s
|
210
|
-
end
|
211
|
-
|
212
|
-
|
213
|
-
## define view functions for each classes
|
214
|
-
str = erubystr
|
215
|
-
testdefs.each do |h|
|
216
|
-
if h['compile']
|
217
|
-
erubyfile = erubyfilename(h['name'])
|
218
|
-
code = eval h['compile']
|
219
|
-
s = <<-END
|
220
|
-
def view_#{h['name']}(context)
|
221
|
-
list = context['list']
|
222
|
-
#{code}
|
223
|
-
end
|
224
|
-
END
|
225
|
-
#puts s
|
226
|
-
eval s
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
## define tests for view functions
|
231
|
-
testdefs.each do |h|
|
232
|
-
pr = h['return'] ? 'print ' : ''
|
233
|
-
s = ''
|
234
|
-
s << "def test_func_#{h['name']}(context)\n"
|
235
|
-
s << " list = context['list']\n"
|
236
|
-
if flag_expand
|
237
|
-
$ntimes.times do
|
238
|
-
s << " #{pr}view_#{h['name']}(context)\n"
|
239
|
-
end
|
240
|
-
else
|
241
|
-
s << " $ntimes.times do\n"
|
242
|
-
s << " #{pr}view_#{h['name']}(context)\n"
|
243
|
-
s << " end\n"
|
244
|
-
end
|
245
|
-
s << "end\n"
|
246
|
-
#puts s
|
247
|
-
eval s
|
248
|
-
end
|
249
|
-
|
250
|
-
|
251
|
-
## define test for convertion
|
252
|
-
testdefs.each do |h|
|
253
|
-
if h['compile']
|
254
|
-
s = ''
|
255
|
-
s << "def test_convert_#{h['name']}(erubyfile)\n"
|
256
|
-
s << " str = File.read(erubyfile)\n"
|
257
|
-
if flag_expand
|
258
|
-
$ntimes.times do
|
259
|
-
s << " src = #{h['compile']}\n"
|
260
|
-
end
|
261
|
-
else
|
262
|
-
s << " $ntimes.times do \n"
|
263
|
-
s << " src = #{h['compile']}\n"
|
264
|
-
s << " end\n"
|
265
|
-
end
|
266
|
-
s << "end\n"
|
267
|
-
#puts s
|
268
|
-
eval s
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
|
273
|
-
## define tests for caching
|
274
|
-
str = erubystr
|
275
|
-
Dir.mkdir('src') unless test(?d, 'src')
|
276
|
-
testdefs.each do |h|
|
277
|
-
if h['compile']
|
278
|
-
# create file to read
|
279
|
-
erubyfile = erubyfilename(h['name'])
|
280
|
-
code = eval h['compile']
|
281
|
-
fname = "src/erubybench.#{h['name']}.rb"
|
282
|
-
File.open(fname, 'w') { |f| f.write(code) }
|
283
|
-
#at_exit do File.unlink fname if test(?f, fname) end
|
284
|
-
# define function
|
285
|
-
pr = h['return'] ? 'print' : ''
|
286
|
-
s = ''
|
287
|
-
s << "def test_cache_#{h['name']}(erubyfile, context)\n"
|
288
|
-
s << " list = context['list']\n"
|
289
|
-
if flag_expand
|
290
|
-
ntimes.times do
|
291
|
-
s << " #{pr} eval(File.read('#{fname}'))\n"
|
292
|
-
end
|
293
|
-
else
|
294
|
-
s << " $ntimes.times do\n"
|
295
|
-
s << " #{pr} eval(File.read('#{fname}'))\n"
|
296
|
-
s << " end\n"
|
297
|
-
end
|
298
|
-
s << "end\n"
|
299
|
-
#puts s
|
300
|
-
eval s
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
|
305
|
-
## output
|
306
|
-
if flag_output
|
307
|
-
testdefs.each do |h|
|
308
|
-
title = h['class']
|
309
|
-
func = 'test_basic_' + h['name']
|
310
|
-
puts "## #{h['class']}"
|
311
|
-
__send__(func, erubyfile, data)
|
312
|
-
puts
|
313
|
-
end
|
314
|
-
exit(0)
|
315
|
-
end
|
316
|
-
|
317
|
-
|
318
|
-
## rehearsal
|
319
|
-
$stdout = StringIO.new
|
320
|
-
testdefs.each do |h|
|
321
|
-
## execute test code
|
322
|
-
erubyfile = erubyfilename(h['name'])
|
323
|
-
eval h['code']
|
324
|
-
## execute view function
|
325
|
-
next unless h['compile']
|
326
|
-
v = __send__("view_#{h['name']}", context)
|
327
|
-
print v if h['return']
|
328
|
-
## execute caching function
|
329
|
-
fname = "src/erubybench.#{h['name']}.rb"
|
330
|
-
v = eval(File.read(fname))
|
331
|
-
print v if h['return']
|
332
|
-
end
|
333
|
-
$stdout = STDOUT
|
334
|
-
|
335
|
-
|
336
|
-
## open output file
|
337
|
-
$stdout = outfile == '-' ? STDOUT : File.open(outfile, 'w')
|
338
|
-
|
339
|
-
|
340
|
-
## change benchmark library to use $stderr instead of $stdout
|
341
|
-
require 'benchmark'
|
342
|
-
module Benchmark
|
343
|
-
class Report
|
344
|
-
def print(*args)
|
345
|
-
$stderr.print(*args)
|
346
|
-
end
|
347
|
-
end
|
348
|
-
module_function
|
349
|
-
def print(*args)
|
350
|
-
$stderr.print(*args)
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
|
355
|
-
## do benchmark
|
356
|
-
width = 30
|
357
|
-
begin
|
358
|
-
|
359
|
-
## evaluate
|
360
|
-
if !testmode || testmode == 'execute'
|
361
|
-
$stderr.puts "## execute"
|
362
|
-
Benchmark.bm(width) do |job|
|
363
|
-
testdefs.each do |h|
|
364
|
-
title = h['title'] || h['class']
|
365
|
-
func = 'test_execute_' + h['name']
|
366
|
-
GC.start
|
367
|
-
job.report(title) do
|
368
|
-
__send__(func, erubyfilename(h['name']), context)
|
369
|
-
end
|
370
|
-
end
|
371
|
-
end
|
372
|
-
$stderr.puts
|
373
|
-
end
|
374
|
-
|
375
|
-
## convert
|
376
|
-
if testmode == 'convert'
|
377
|
-
$stderr.puts "## convert"
|
378
|
-
Benchmark.bm(width) do |job|
|
379
|
-
testdefs.each do |h|
|
380
|
-
next unless h['compile']
|
381
|
-
title = h['title'] || h['class']
|
382
|
-
func = 'test_convert_' + h['name']
|
383
|
-
GC.start
|
384
|
-
job.report(title) do
|
385
|
-
__send__(func, erubyfilename(h['name']))
|
386
|
-
end
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
## caching
|
392
|
-
if testmode == 'cache'
|
393
|
-
$stderr.puts "## evaluate cache file"
|
394
|
-
Benchmark.bm(width) do |job|
|
395
|
-
testdefs.each do |h|
|
396
|
-
next unless h['compile']
|
397
|
-
#title = 'cache_' + h['name']
|
398
|
-
title = h['title'] || h['class']
|
399
|
-
func = 'test_cache_' + h['name']
|
400
|
-
GC.start
|
401
|
-
job.report(title) do
|
402
|
-
__send__(func, erubyfilename(h['name']), context)
|
403
|
-
end
|
404
|
-
end
|
405
|
-
end
|
406
|
-
$stderr.puts
|
407
|
-
end
|
408
|
-
|
409
|
-
## function
|
410
|
-
if testmode == 'func'
|
411
|
-
$stderr.puts "## evaluate function"
|
412
|
-
Benchmark.bm(width) do |job|
|
413
|
-
testdefs.each do |h|
|
414
|
-
next unless h['compile']
|
415
|
-
#title = 'func_' + h['name']
|
416
|
-
title = h['title'] || h['class']
|
417
|
-
func = 'test_func_' + h['name']
|
418
|
-
GC.start
|
419
|
-
job.report(title) do
|
420
|
-
__send__(func, context)
|
421
|
-
end
|
422
|
-
end
|
423
|
-
end
|
424
|
-
$stderr.puts
|
425
|
-
end
|
426
|
-
|
427
|
-
#Benchmark.bm(30) do |job|
|
428
|
-
# ## basic test
|
429
|
-
# testdefs.each do |h|
|
430
|
-
# title = h['class']
|
431
|
-
# func = 'test_basic_' + h['name']
|
432
|
-
# GC.start
|
433
|
-
# job.report(title) do
|
434
|
-
# __send__(func, erubyfile, context)
|
435
|
-
# end
|
436
|
-
# end if !testmode || testmode == 'basic'
|
437
|
-
#
|
438
|
-
# ## caching function
|
439
|
-
# testdefs.each do |h|
|
440
|
-
# next unless h['compile']
|
441
|
-
# title = 'cache_' + h['name']
|
442
|
-
# func = 'test_cache_' + h['name']
|
443
|
-
# GC.start
|
444
|
-
# job.report(title) do
|
445
|
-
# __send__(func, erubyfile, context)
|
446
|
-
# end
|
447
|
-
# end if !testmode || testmode == 'cache'
|
448
|
-
#
|
449
|
-
# ## view-function test
|
450
|
-
# testdefs.each do |h|
|
451
|
-
# next unless h['compile']
|
452
|
-
# title = 'func_' + h['name']
|
453
|
-
# func = 'test_func_' + h['name']
|
454
|
-
# GC.start
|
455
|
-
# job.report(title) do
|
456
|
-
# __send__(func, list)
|
457
|
-
# end
|
458
|
-
# end if !testmode || testmode == 'func'
|
459
|
-
#
|
460
|
-
#end
|
461
|
-
|
462
|
-
ensure
|
463
|
-
$stdout.close() unless outfile == '-'
|
464
|
-
end
|
465
|
-
|
466
|
-
__END__
|
467
|
-
|
468
|
-
## testdefs
|
469
|
-
|
470
|
-
- name: eruby
|
471
|
-
class: ERuby
|
472
|
-
title: eruby
|
473
|
-
code: |
|
474
|
-
ERuby.import(erubyfile)
|
475
|
-
compile: |
|
476
|
-
ERuby::Compiler.new.compile_string(str)
|
477
|
-
return: null
|
478
|
-
|
479
|
-
- name: ERB
|
480
|
-
class: ERB
|
481
|
-
code: |
|
482
|
-
print ERB.new(File.read(erubyfile)).result(binding())
|
483
|
-
# eruby = ERB.new(File.read(erubyfile))
|
484
|
-
# print eruby.result(binding())
|
485
|
-
compile: |
|
486
|
-
ERB.new(str).src
|
487
|
-
return: str
|
488
|
-
|
489
|
-
- name: ErubisEruby
|
490
|
-
class: Erubis::Eruby
|
491
|
-
return: str
|
492
|
-
|
493
|
-
- name: ErubisEruby2
|
494
|
-
desc: print _buf #, no binding()
|
495
|
-
class: Erubis::Eruby2
|
496
|
-
code: |
|
497
|
-
#Erubis::Eruby2.new(File.read(erubyfile)).result()
|
498
|
-
Erubis::Eruby2.new(File.read(erubyfile)).result(binding())
|
499
|
-
return: null
|
500
|
-
skip: yes
|
501
|
-
|
502
|
-
- name: ErubisEruby_cached
|
503
|
-
class: Erubis::Eruby
|
504
|
-
title: Erubis::Eruby(cached)
|
505
|
-
code: |
|
506
|
-
Erubis::Eruby.load_file(erubyfile).result(binding())
|
507
|
-
compile: |
|
508
|
-
Erubis::Eruby.load_file(erubyfile)
|
509
|
-
return: str
|
510
|
-
|
511
|
-
- name: ErubisExprStripped
|
512
|
-
desc: strip expr code
|
513
|
-
class: Erubis::ExprStrippedEruby
|
514
|
-
return: str
|
515
|
-
skip: yes
|
516
|
-
|
517
|
-
- name: ErubisOptimized
|
518
|
-
class: Erubis::OptimizedEruby
|
519
|
-
return: str
|
520
|
-
skip: yes
|
521
|
-
|
522
|
-
- name: ErubisOptimized2
|
523
|
-
class: Erubis::Optimized2Eruby
|
524
|
-
return: str
|
525
|
-
skip: yes
|
526
|
-
|
527
|
-
- name: ErubisArrayBuffer
|
528
|
-
class: Erubis::ArrayBufferEruby
|
529
|
-
# code: |
|
530
|
-
# Erubis::ArrayBufferEruby.new(File.read(erubyfile)).result(binding())
|
531
|
-
# compile: |
|
532
|
-
# Erubis::ArrayBufferEruby.new(str).src
|
533
|
-
return: str
|
534
|
-
skip: no
|
535
|
-
|
536
|
-
- name: ErubisStringBuffer
|
537
|
-
class: Erubis::StringBufferEruby
|
538
|
-
return: str
|
539
|
-
skip: yes
|
540
|
-
|
541
|
-
- name: ErubisStringIO
|
542
|
-
class: Erubis::StringIOEruby
|
543
|
-
return: str
|
544
|
-
skip: yes
|
545
|
-
|
546
|
-
- name: ErubisSimplified
|
547
|
-
class: Erubis::SimplifiedEruby
|
548
|
-
return: str
|
549
|
-
skip: no
|
550
|
-
|
551
|
-
- name: ErubisStdout
|
552
|
-
class: Erubis::StdoutEruby
|
553
|
-
return: null
|
554
|
-
skip: no
|
555
|
-
|
556
|
-
- name: ErubisStdoutSimplified
|
557
|
-
class: Erubis::StdoutSimplifiedEruby
|
558
|
-
return: str
|
559
|
-
skip: yes
|
560
|
-
|
561
|
-
- name: ErubisPrintOut
|
562
|
-
class: Erubis::PrintOutEruby
|
563
|
-
return: str
|
564
|
-
skip: no
|
565
|
-
|
566
|
-
- name: ErubisPrintOutSimplified
|
567
|
-
class: Erubis::PrintOutSimplifiedEruby
|
568
|
-
return: str
|
569
|
-
skip: yes
|
570
|
-
|
571
|
-
- name: ErubisTiny
|
572
|
-
class: Erubis::TinyEruby
|
573
|
-
return: yes
|
574
|
-
skip: no
|
575
|
-
|
576
|
-
- name: ErubisTinyStdout
|
577
|
-
class: Erubis::TinyStdoutEruby
|
578
|
-
return: null
|
579
|
-
skip: yes
|
580
|
-
|
581
|
-
- name: ErubisTinyPrint
|
582
|
-
class: Erubis::TinyPrintEruby
|
583
|
-
return: null
|
584
|
-
skip: yes
|
585
|
-
|
586
|
-
- name: ErubisPIEruby
|
587
|
-
class: Erubis::PI::Eruby
|
588
|
-
code: |
|
589
|
-
Erubis::PI::Eruby.new(File.read(erubyfile)).result(binding())
|
590
|
-
compile: |
|
591
|
-
Erubis::PI::Eruby.new(File.read(erubyfile)).src
|
592
|
-
return: str
|
593
|
-
|
594
|
-
#- name: load
|
595
|
-
# class: load
|
596
|
-
# code: |
|
597
|
-
# load($load_erubyfile)
|
598
|
-
# compile: null
|
599
|
-
# return: null
|
600
|
-
# skip: yes
|