erubis-bmp 2.7.0.bmp

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.txt +828 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.txt +10 -0
  5. data/benchmark/bench.rb +313 -0
  6. data/benchmark/bench_context.yaml +141 -0
  7. data/benchmark/mybench2.rb +266 -0
  8. data/benchmark/pibench.rb +163 -0
  9. data/benchmark/templates/_footer.html +4 -0
  10. data/benchmark/templates/_header.html +52 -0
  11. data/benchmark/templates/bench_erb.rhtml +29 -0
  12. data/benchmark/templates/bench_erubis.rhtml +29 -0
  13. data/benchmark/templates/bench_eruby.rhtml +29 -0
  14. data/bin/erubis +10 -0
  15. data/contrib/erubis-run.rb +132 -0
  16. data/doc/Rookbook.yaml +106 -0
  17. data/doc/docstyle.css +209 -0
  18. data/doc/users-guide.html +3551 -0
  19. data/doc/users-guide.txt +3631 -0
  20. data/examples/basic/Makefile +58 -0
  21. data/examples/basic/example.ec +42 -0
  22. data/examples/basic/example.ecpp +33 -0
  23. data/examples/basic/example.ejava +45 -0
  24. data/examples/basic/example.ejs +16 -0
  25. data/examples/basic/example.eperl +16 -0
  26. data/examples/basic/example.ephp +17 -0
  27. data/examples/basic/example.eruby +15 -0
  28. data/examples/basic/example.escheme +26 -0
  29. data/examples/pi-xhtml/ExamplePage.xhtml +80 -0
  30. data/examples/pi-xhtml/Makefile +17 -0
  31. data/examples/pi-xhtml/my/User.java +19 -0
  32. data/examples/pi-xhtml/my/Util.java +54 -0
  33. data/examples/pi/Makefile +54 -0
  34. data/examples/pi/example.ec +42 -0
  35. data/examples/pi/example.ejava +45 -0
  36. data/examples/pi/example.ejs +16 -0
  37. data/examples/pi/example.eperl +16 -0
  38. data/examples/pi/example.ephp +17 -0
  39. data/examples/pi/example.eruby +15 -0
  40. data/examples/pi/example.escheme +26 -0
  41. data/lib/erubis.rb +73 -0
  42. data/lib/erubis/context.rb +83 -0
  43. data/lib/erubis/converter.rb +357 -0
  44. data/lib/erubis/engine.rb +120 -0
  45. data/lib/erubis/engine/ec.rb +117 -0
  46. data/lib/erubis/engine/ecpp.rb +113 -0
  47. data/lib/erubis/engine/ejava.rb +110 -0
  48. data/lib/erubis/engine/ejavascript.rb +119 -0
  49. data/lib/erubis/engine/enhanced.rb +126 -0
  50. data/lib/erubis/engine/eperl.rb +95 -0
  51. data/lib/erubis/engine/ephp.rb +99 -0
  52. data/lib/erubis/engine/eruby.rb +125 -0
  53. data/lib/erubis/engine/escheme.rb +114 -0
  54. data/lib/erubis/engine/optimized.rb +127 -0
  55. data/lib/erubis/enhancer.rb +723 -0
  56. data/lib/erubis/error.rb +23 -0
  57. data/lib/erubis/evaluator.rb +88 -0
  58. data/lib/erubis/generator.rb +85 -0
  59. data/lib/erubis/helper.rb +47 -0
  60. data/lib/erubis/helpers/rails_form_helper.rb +197 -0
  61. data/lib/erubis/helpers/rails_helper.rb +353 -0
  62. data/lib/erubis/local-setting.rb +9 -0
  63. data/lib/erubis/main.rb +516 -0
  64. data/lib/erubis/preprocessing.rb +58 -0
  65. data/lib/erubis/tiny.rb +144 -0
  66. data/lib/erubis/util.rb +22 -0
  67. data/setup.rb +1331 -0
  68. data/test/Rookbook.yaml +42 -0
  69. data/test/assert-text-equal.rb +44 -0
  70. data/test/test-engines.rb +425 -0
  71. data/test/test-enhancers.rb +646 -0
  72. data/test/test-erubis.rb +887 -0
  73. data/test/test-index-cgi.rb +191 -0
  74. data/test/test-main.rb +752 -0
  75. data/test/test-users-guide.rb +73 -0
  76. data/test/test.rb +45 -0
  77. data/test/testutil.rb +111 -0
  78. metadata +121 -0
@@ -0,0 +1,20 @@
1
+ $Copyright$
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+ This is a fork of [erubis](http://www.kuwata-lab.com/erubis/) used by
2
+ [Brakeman Pro](https://brakemanpro.com/).
3
+
4
+ == License
5
+
6
+ MIT License
7
+
8
+ == Original Author
9
+
10
+ makoto kuwata <kwa(at)kuwata-lab.com>
@@ -0,0 +1,313 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###
4
+ ### $Release:$
5
+ ### $Copyright$
6
+ ###
7
+
8
+ require 'erb'
9
+ require 'erubis'
10
+ require 'erubis/tiny'
11
+ require 'erubis/engine/enhanced'
12
+ require 'yaml'
13
+ require 'cgi'
14
+ include ERB::Util
15
+
16
+ begin
17
+ require 'eruby'
18
+ rescue LoadError
19
+ ERuby = nil
20
+ end
21
+
22
+ def File.write(filename, content)
23
+ File.open(filename, 'w') { |f| f.write(content) }
24
+ end
25
+
26
+
27
+ ## change benchmark library to use $stderr instead of $stdout
28
+ require 'benchmark'
29
+ module Benchmark
30
+ class Report
31
+ def print(*args)
32
+ $stderr.print(*args)
33
+ end
34
+ end
35
+ module_function
36
+ def print(*args)
37
+ $stderr.print(*args)
38
+ end
39
+ end
40
+
41
+
42
+ class BenchmarkApplication
43
+
44
+ TARGETS = %w[eruby
45
+ ERB ERB(cached)
46
+ Erubis::Eruby Erubis::Eruby(cached)
47
+ Erubis::FastEruby Erubis::FastEruby(cached)
48
+ Erubis::TinyEruby
49
+ Erubis::ArrayBufferEruby
50
+ Erubis::PrintOutEruby
51
+ Erubis::StdoutEruby
52
+ ]
53
+
54
+ def initialize(ntimes, context, targets=nil, params={})
55
+ @ntimes = ntimes
56
+ @context = context
57
+ @targets = targets && !targets.empty? ? targets : TARGETS.dup
58
+ @testmode = params[:testmode] || 'execute'
59
+ @erubyfile = params[:erubyfile] || 'erubybench.rhtml'
60
+ @printout = params[:printout] || false
61
+ end
62
+
63
+ attr_accessor :ntimes, :targets
64
+ attr_accessor :testmode, :erubyfile, :contextfile, :printout
65
+
66
+ def context2code(context, varname='context')
67
+ s = ''
68
+ context.each { |k, | s << "#{k} = #{varname}[#{k.inspect}]; " }
69
+ return s
70
+ end
71
+
72
+ def perform_benchmark
73
+ width = 30
74
+ $stderr.puts "*** ntimes=#{@ntimes}, testmode=#{@testmode}"
75
+ Benchmark.bm(width) do |job|
76
+ for target in @targets do
77
+ method = "#{@testmode}_#{target.gsub(/::|-|\(/, '_').gsub(/\)/, '').downcase}"
78
+ #$stderr.puts "*** debug: method=#{method.inspect}"
79
+ next unless self.respond_to?(method)
80
+ filename = "bench_#{(target =~ /^(\w+)/) && $1.downcase}.rhtml"
81
+ title = target
82
+ output = nil
83
+ job.report(title) do
84
+ output = self.__send__(method, filename, @context)
85
+ end
86
+ File.write("output.#{target.gsub(/[^\w]/,'')}", output) if @printout && output && !output.empty?
87
+ end
88
+ end
89
+ end
90
+
91
+ ##
92
+
93
+ def execute_eruby(filename, context)
94
+ return unless ERuby
95
+ #eval context2code(context)
96
+ list = context['list']
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
+ list = context['list']
106
+ output = nil
107
+ @ntimes.times do
108
+ eruby = ERB.new(File.read(filename))
109
+ output = eruby.result(binding())
110
+ print output
111
+ end
112
+ return output
113
+ end
114
+
115
+ def execute_erb_cached(filename, context)
116
+ #eval context2code(context)
117
+ list = context['list']
118
+ output = nil
119
+ cachefile = filename + '.cache'
120
+ File.unlink(cachefile) if test(?f, cachefile)
121
+ @ntimes.times do
122
+ if !test(?f, cachefile) || File.mtime(filename) > File.mtime(cachefile)
123
+ eruby = ERB.new(File.read(filename))
124
+ File.write(cachefile, eruby.src)
125
+ else
126
+ eruby = ERB.new('')
127
+ #eruby.src = File.read(cachefile)
128
+ eruby.instance_variable_set("@src", File.read(cachefile))
129
+ end
130
+ output = eruby.result(binding())
131
+ print output
132
+ end
133
+ return output
134
+ end
135
+
136
+ ## no cached
137
+ for klass in %w[Eruby FastEruby TinyEruby ArrayBufferEruby PrintOutEruby StdoutEruby] do
138
+ s = <<-END
139
+ def execute_erubis_#{klass.downcase}(filename, context)
140
+ #eval context2code(context)
141
+ list = context['list']
142
+ output = nil
143
+ @ntimes.times do
144
+ eruby = Erubis::#{klass}.new(File.read(filename))
145
+ output = eruby.result(binding())
146
+ print output
147
+ end
148
+ return output
149
+ end
150
+ END
151
+ eval s
152
+ end
153
+
154
+ ## cached
155
+ for klass in %w[Eruby FastEruby] do
156
+ s = <<-END
157
+ def execute_erubis_#{klass.downcase}_cached(filename, context)
158
+ #eval context2code(context)
159
+ list = context['list']
160
+ cachefile = filename + '.cache'
161
+ File.unlink(cachefile) if test(?f, cachefile)
162
+ output = nil
163
+ @ntimes.times do
164
+ eruby = Erubis::#{klass}.load_file(filename)
165
+ output = eruby.result(binding())
166
+ print output
167
+ end
168
+ savefile = cachefile.sub(/\\.cache$/, '.#{klass.downcase}.cache')
169
+ File.rename(cachefile, savefile)
170
+ return output
171
+ end
172
+ END
173
+ eval s
174
+ end
175
+
176
+ ##
177
+
178
+ def convert_eruby(filename, context)
179
+ return unless ERuby
180
+ #eval context2code(context)
181
+ list = context['list']
182
+ output = nil
183
+ @ntimes.times do
184
+ output = ERuby::Compiler.new.compile_string(File.read(filename))
185
+ end
186
+ return output
187
+ end
188
+
189
+ def convert_erb(filename, context)
190
+ #eval context2code(context)
191
+ list = context['list']
192
+ output = nil
193
+ @ntimes.times do
194
+ eruby = ERB.new(File.read(filename))
195
+ output = eruby.src
196
+ end
197
+ return output
198
+ end
199
+
200
+ for klass in %w[Eruby FastEruby TinyEruby]
201
+ s = <<-END
202
+ def convert_erubis_#{klass.downcase}(filename, context)
203
+ #eval context2code(context)
204
+ list = context['list']
205
+ output = nil
206
+ @ntimes.times do
207
+ eruby = Erubis::#{klass}.new(File.read(filename))
208
+ output = eruby.src
209
+ end
210
+ return output
211
+ end
212
+ END
213
+ eval s
214
+ end
215
+
216
+ end
217
+
218
+
219
+ require 'optparse'
220
+
221
+ class MainApplication
222
+
223
+ def parse_argv(argv=ARGV)
224
+ optparser = OptionParser.new
225
+ options = {}
226
+ ['-h', '-n N', '-t erubyfile', '-f contextfile', '-A', '-e',
227
+ '-x exclude', '-m testmode', '-X', '-p', '-D'].each do |opt|
228
+ optparser.on(opt) { |val| options[opt[1].chr] = val }
229
+ end
230
+ begin
231
+ targets = optparser.parse!(argv)
232
+ rescue => ex
233
+ $stderr.puts "#{@script}: #{ex.to_s}"
234
+ exit(1)
235
+ end
236
+ return options, targets
237
+ end
238
+
239
+ def execute
240
+ @script = File.basename($0)
241
+ ntimes = 1000
242
+ targets = BenchmarkApplication::TARGETS.dup
243
+ testmode = 'execute'
244
+ contextfile = 'bench_context.yaml'
245
+ #
246
+ options, args = parse_argv(ARGV)
247
+ ntimes = options['n'].to_i if options['n']
248
+ targets = args if args && !args.empty?
249
+ targets = targets - options['x'].split(/,/) if options['x']
250
+ testmode = options['m'] if options['m']
251
+ contextfile = options['f'] if options['f']
252
+ erubyfile = options['t'] if options['t']
253
+ #
254
+ if options['h']
255
+ $stderr.puts "Usage: ruby #{@script} [..options..] [..targets..]"
256
+ $stderr.puts " -h : help"
257
+ $stderr.puts " -n N : loop N times"
258
+ $stderr.puts " -f datafile : context data filename (*.yaml)"
259
+ $stderr.puts " -x exclude : exclude target name"
260
+ $stdout.puts " -m testmode : 'execute' or 'convert' (default 'execute')"
261
+ $stderr.puts " -p : print output to file (filename: 'output.TARGETNAME')"
262
+ return
263
+ end
264
+ #
265
+ #if ! options['t']
266
+ for item in %w[eruby erb erubis]
267
+ fname = "bench_#{item}.rhtml"
268
+ header = File.read("templates/_header.html")
269
+ #body = File.read("templates/#{erubyfile}")
270
+ body = File.read("templates/#{fname}")
271
+ footer = File.read("templates/_footer.html")
272
+ content = header + body + footer
273
+ File.write(fname, content)
274
+ end
275
+ #
276
+ if options['e'] # escape
277
+ tuples = [
278
+ [ 'bench_eruby.rhtml', '<%= CGI.escapeHTML((\1).to_s) %>' ],
279
+ [ 'bench_erb.rhtml', '<%=h \1 %>' ],
280
+ [ 'bench_erubis.rhtml', '<%== \1 %>' ],
281
+ ]
282
+ for fname, replace in tuples
283
+ content = File.read(fname).gsub(/<%= ?(.*?) ?%>/, replace)
284
+ File.write(fname, content)
285
+ end
286
+ targets.delete('Erubis::TinyEruby') ## because TinyEruby doesn't support '<%== =>'
287
+ end
288
+ #
289
+ context = YAML.load_file(contextfile)
290
+ #
291
+ params = {
292
+ :printout=>options['p'],
293
+ :testmode=>testmode,
294
+ }
295
+ app = BenchmarkApplication.new(ntimes, context, targets, params)
296
+ app.perform_benchmark()
297
+ end
298
+
299
+ end
300
+
301
+
302
+ if __FILE__ == $0
303
+
304
+ ## open /dev/null
305
+ $stdout = File.open('/dev/null', 'w')
306
+ at_exit do
307
+ $stdout.close()
308
+ end
309
+
310
+ ## start benchmark
311
+ MainApplication.new().execute()
312
+
313
+ end
@@ -0,0 +1,141 @@
1
+ list:
2
+ - name: Adobe Systems
3
+ name2: Adobe Systems Inc.
4
+ url: http://www.adobe.com
5
+ symbol: ADBE
6
+ price: 39.26
7
+ change: 0.13
8
+ ratio: 0.33
9
+ - name: Advanced Micro Devices
10
+ name2: Advanced Micro Devices Inc.
11
+ url: http://www.amd.com
12
+ symbol: AMD
13
+ price: 16.22
14
+ change: 0.17
15
+ ratio: 1.06
16
+ - name: Amazon.com
17
+ name2: Amazon.com Inc
18
+ url: http://www.amazon.com
19
+ symbol: AMZN
20
+ price: 36.85
21
+ change: -0.23
22
+ ratio: -0.62
23
+ - name: Apple
24
+ name2: Apple Inc.
25
+ url: http://www.apple.com
26
+ symbol: AAPL
27
+ price: 85.38
28
+ change: -0.87
29
+ ratio: -1.01
30
+ - name: BEA Systems
31
+ name2: BEA Systems Inc.
32
+ url: http://www.bea.com
33
+ symbol: BEAS
34
+ price: 12.46
35
+ change: 0.09
36
+ ratio: 0.73
37
+ - name: CA
38
+ name2: CA, Inc.
39
+ url: http://www.ca.com
40
+ symbol: CA
41
+ price: 24.66
42
+ change: 0.38
43
+ ratio: 1.57
44
+ - name: Cisco Systems
45
+ name2: Cisco Systems Inc.
46
+ url: http://www.cisco.com
47
+ symbol: CSCO
48
+ price: 26.35
49
+ change: 0.13
50
+ ratio: 0.5
51
+ - name: Dell
52
+ name2: Dell Corp.
53
+ url: http://www.dell.com/
54
+ symbol: DELL
55
+ price: 23.73
56
+ change: -0.42
57
+ ratio: -1.74
58
+ - name: eBay
59
+ name2: eBay Inc.
60
+ url: http://www.ebay.com
61
+ symbol: EBAY
62
+ price: 31.65
63
+ change: -0.8
64
+ ratio: -2.47
65
+ - name: Google
66
+ name2: Google Inc.
67
+ url: http://www.google.com
68
+ symbol: GOOG
69
+ price: 495.84
70
+ change: 7.75
71
+ ratio: 1.59
72
+ - name: Hewlett-Packard
73
+ name2: Hewlett-Packard Co.
74
+ url: http://www.hp.com
75
+ symbol: HPQ
76
+ price: 41.69
77
+ change: -0.02
78
+ ratio: -0.05
79
+ - name: IBM
80
+ name2: International Business Machines Corp.
81
+ url: http://www.ibm.com
82
+ symbol: IBM
83
+ price: 97.45
84
+ change: -0.06
85
+ ratio: -0.06
86
+ - name: Intel
87
+ name2: Intel Corp.
88
+ url: http://www.intel.com
89
+ symbol: INTC
90
+ price: 20.53
91
+ change: -0.07
92
+ ratio: -0.34
93
+ - name: Juniper Networks
94
+ name2: Juniper Networks, Inc
95
+ url: http://www.juniper.net/
96
+ symbol: JNPR
97
+ price: 18.96
98
+ change: 0.5
99
+ ratio: 2.71
100
+ - name: Microsoft
101
+ name2: Microsoft Corp
102
+ url: http://www.microsoft.com
103
+ symbol: MSFT
104
+ price: 30.6
105
+ change: 0.15
106
+ ratio: 0.49
107
+ - name: Oracle
108
+ name2: Oracle Corp.
109
+ url: http://www.oracle.com
110
+ symbol: ORCL
111
+ price: 17.15
112
+ change: 0.17
113
+ ratio: 1.0
114
+ - name: SAP
115
+ name2: SAP AG
116
+ url: http://www.sap.com
117
+ symbol: SAP
118
+ price: 46.2
119
+ change: -0.16
120
+ ratio: -0.35
121
+ - name: Seagate Technology
122
+ name2: Seagate Technology
123
+ url: http://www.seagate.com/
124
+ symbol: STX
125
+ price: 27.35
126
+ change: -0.36
127
+ ratio: -1.3
128
+ - name: Sun Microsystems
129
+ name2: Sun Microsystems Inc.
130
+ url: http://www.sun.com
131
+ symbol: SUNW
132
+ price: 6.33
133
+ change: -0.01
134
+ ratio: -0.16
135
+ - name: Yahoo
136
+ name2: Yahoo! Inc.
137
+ url: http://www.yahoo.com
138
+ symbol: YHOO
139
+ price: 28.04
140
+ change: -0.17
141
+ ratio: -0.6