Update Vendored Erubis to 2.6.6
This commit is contained in:
parent
c18c2f988d
commit
39c2138f88
300 changed files with 207 additions and 171 deletions
6
vendor/plugins/erubis/benchmark/Makefile
vendored
Normal file
6
vendor/plugins/erubis/benchmark/Makefile
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
bench:
|
||||
ruby bench.rb -n 10000
|
||||
|
||||
clean:
|
||||
rm -rf bench_*.rhtml*
|
313
vendor/plugins/erubis/benchmark/bench.rb
vendored
Normal file
313
vendor/plugins/erubis/benchmark/bench.rb
vendored
Normal file
|
@ -0,0 +1,313 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
###
|
||||
### $Release: 2.6.6 $
|
||||
### copyright(c) 2006-2010 kuwata-lab.com all rights reserved.
|
||||
###
|
||||
|
||||
require 'erb'
|
||||
require 'erubis'
|
||||
require 'erubis/tiny'
|
||||
require 'erubis/engine/enhanced'
|
||||
require 'yaml'
|
||||
require 'cgi'
|
||||
include ERB::Util
|
||||
|
||||
begin
|
||||
require 'eruby'
|
||||
rescue LoadError
|
||||
ERuby = nil
|
||||
end
|
||||
|
||||
def File.write(filename, content)
|
||||
File.open(filename, 'w') { |f| f.write(content) }
|
||||
end
|
||||
|
||||
|
||||
## change benchmark library to use $stderr instead of $stdout
|
||||
require 'benchmark'
|
||||
module Benchmark
|
||||
class Report
|
||||
def print(*args)
|
||||
$stderr.print(*args)
|
||||
end
|
||||
end
|
||||
module_function
|
||||
def print(*args)
|
||||
$stderr.print(*args)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class BenchmarkApplication
|
||||
|
||||
TARGETS = %w[eruby
|
||||
ERB ERB(cached)
|
||||
Erubis::Eruby Erubis::Eruby(cached)
|
||||
Erubis::FastEruby Erubis::FastEruby(cached)
|
||||
Erubis::TinyEruby
|
||||
Erubis::ArrayBufferEruby
|
||||
Erubis::PrintOutEruby
|
||||
Erubis::StdoutEruby
|
||||
]
|
||||
|
||||
def initialize(ntimes, context, targets=nil, params={})
|
||||
@ntimes = ntimes
|
||||
@context = context
|
||||
@targets = targets && !targets.empty? ? targets : TARGETS.dup
|
||||
@testmode = params[:testmode] || 'execute'
|
||||
@erubyfile = params[:erubyfile] || 'erubybench.rhtml'
|
||||
@printout = params[:printout] || false
|
||||
end
|
||||
|
||||
attr_accessor :ntimes, :targets
|
||||
attr_accessor :testmode, :erubyfile, :contextfile, :printout
|
||||
|
||||
def context2code(context, varname='context')
|
||||
s = ''
|
||||
context.each { |k, | s << "#{k} = #{varname}[#{k.inspect}]; " }
|
||||
return s
|
||||
end
|
||||
|
||||
def perform_benchmark
|
||||
width = 30
|
||||
$stderr.puts "*** ntimes=#{@ntimes}, testmode=#{@testmode}"
|
||||
Benchmark.bm(width) do |job|
|
||||
for target in @targets do
|
||||
method = "#{@testmode}_#{target.gsub(/::|-|\(/, '_').gsub(/\)/, '').downcase}"
|
||||
#$stderr.puts "*** debug: method=#{method.inspect}"
|
||||
next unless self.respond_to?(method)
|
||||
filename = "bench_#{(target =~ /^(\w+)/) && $1.downcase}.rhtml"
|
||||
title = target
|
||||
output = nil
|
||||
job.report(title) do
|
||||
output = self.__send__(method, filename, @context)
|
||||
end
|
||||
File.write("output.#{target.gsub(/[^\w]/,'')}", output) if @printout && output && !output.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
|
||||
def execute_eruby(filename, context)
|
||||
return unless ERuby
|
||||
#eval context2code(context)
|
||||
list = context['list']
|
||||
@ntimes.times do
|
||||
ERuby.import(filename)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def execute_erb(filename, context)
|
||||
#eval context2code(context)
|
||||
list = context['list']
|
||||
output = nil
|
||||
@ntimes.times do
|
||||
eruby = ERB.new(File.read(filename))
|
||||
output = eruby.result(binding())
|
||||
print output
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
def execute_erb_cached(filename, context)
|
||||
#eval context2code(context)
|
||||
list = context['list']
|
||||
output = nil
|
||||
cachefile = filename + '.cache'
|
||||
File.unlink(cachefile) if test(?f, cachefile)
|
||||
@ntimes.times do
|
||||
if !test(?f, cachefile) || File.mtime(filename) > File.mtime(cachefile)
|
||||
eruby = ERB.new(File.read(filename))
|
||||
File.write(cachefile, eruby.src)
|
||||
else
|
||||
eruby = ERB.new('')
|
||||
#eruby.src = File.read(cachefile)
|
||||
eruby.instance_variable_set("@src", File.read(cachefile))
|
||||
end
|
||||
output = eruby.result(binding())
|
||||
print output
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
## no cached
|
||||
for klass in %w[Eruby FastEruby TinyEruby ArrayBufferEruby PrintOutEruby StdoutEruby] do
|
||||
s = <<-END
|
||||
def execute_erubis_#{klass.downcase}(filename, context)
|
||||
#eval context2code(context)
|
||||
list = context['list']
|
||||
output = nil
|
||||
@ntimes.times do
|
||||
eruby = Erubis::#{klass}.new(File.read(filename))
|
||||
output = eruby.result(binding())
|
||||
print output
|
||||
end
|
||||
return output
|
||||
end
|
||||
END
|
||||
eval s
|
||||
end
|
||||
|
||||
## cached
|
||||
for klass in %w[Eruby FastEruby] do
|
||||
s = <<-END
|
||||
def execute_erubis_#{klass.downcase}_cached(filename, context)
|
||||
#eval context2code(context)
|
||||
list = context['list']
|
||||
cachefile = filename + '.cache'
|
||||
File.unlink(cachefile) if test(?f, cachefile)
|
||||
output = nil
|
||||
@ntimes.times do
|
||||
eruby = Erubis::#{klass}.load_file(filename)
|
||||
output = eruby.result(binding())
|
||||
print output
|
||||
end
|
||||
savefile = cachefile.sub(/\\.cache$/, '.#{klass.downcase}.cache')
|
||||
File.rename(cachefile, savefile)
|
||||
return output
|
||||
end
|
||||
END
|
||||
eval s
|
||||
end
|
||||
|
||||
##
|
||||
|
||||
def convert_eruby(filename, context)
|
||||
return unless ERuby
|
||||
#eval context2code(context)
|
||||
list = context['list']
|
||||
output = nil
|
||||
@ntimes.times do
|
||||
output = ERuby::Compiler.new.compile_string(File.read(filename))
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
def convert_erb(filename, context)
|
||||
#eval context2code(context)
|
||||
list = context['list']
|
||||
output = nil
|
||||
@ntimes.times do
|
||||
eruby = ERB.new(File.read(filename))
|
||||
output = eruby.src
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
for klass in %w[Eruby FastEruby TinyEruby]
|
||||
s = <<-END
|
||||
def convert_erubis_#{klass.downcase}(filename, context)
|
||||
#eval context2code(context)
|
||||
list = context['list']
|
||||
output = nil
|
||||
@ntimes.times do
|
||||
eruby = Erubis::#{klass}.new(File.read(filename))
|
||||
output = eruby.src
|
||||
end
|
||||
return output
|
||||
end
|
||||
END
|
||||
eval s
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
require 'optparse'
|
||||
|
||||
class MainApplication
|
||||
|
||||
def parse_argv(argv=ARGV)
|
||||
optparser = OptionParser.new
|
||||
options = {}
|
||||
['-h', '-n N', '-t erubyfile', '-f contextfile', '-A', '-e',
|
||||
'-x exclude', '-m testmode', '-X', '-p', '-D'].each do |opt|
|
||||
optparser.on(opt) { |val| options[opt[1].chr] = val }
|
||||
end
|
||||
begin
|
||||
targets = optparser.parse!(argv)
|
||||
rescue => ex
|
||||
$stderr.puts "#{@script}: #{ex.to_s}"
|
||||
exit(1)
|
||||
end
|
||||
return options, targets
|
||||
end
|
||||
|
||||
def execute
|
||||
@script = File.basename($0)
|
||||
ntimes = 1000
|
||||
targets = BenchmarkApplication::TARGETS.dup
|
||||
testmode = 'execute'
|
||||
contextfile = 'bench_context.yaml'
|
||||
#
|
||||
options, args = parse_argv(ARGV)
|
||||
ntimes = options['n'].to_i if options['n']
|
||||
targets = args if args && !args.empty?
|
||||
targets = targets - options['x'].split(/,/) if options['x']
|
||||
testmode = options['m'] if options['m']
|
||||
contextfile = options['f'] if options['f']
|
||||
erubyfile = options['t'] if options['t']
|
||||
#
|
||||
if options['h']
|
||||
$stderr.puts "Usage: ruby #{@script} [..options..] [..targets..]"
|
||||
$stderr.puts " -h : help"
|
||||
$stderr.puts " -n N : loop N times"
|
||||
$stderr.puts " -f datafile : context data filename (*.yaml)"
|
||||
$stderr.puts " -x exclude : exclude target name"
|
||||
$stdout.puts " -m testmode : 'execute' or 'convert' (default 'execute')"
|
||||
$stderr.puts " -p : print output to file (filename: 'output.TARGETNAME')"
|
||||
return
|
||||
end
|
||||
#
|
||||
#if ! options['t']
|
||||
for item in %w[eruby erb erubis]
|
||||
fname = "bench_#{item}.rhtml"
|
||||
header = File.read("templates/_header.html")
|
||||
#body = File.read("templates/#{erubyfile}")
|
||||
body = File.read("templates/#{fname}")
|
||||
footer = File.read("templates/_footer.html")
|
||||
content = header + body + footer
|
||||
File.write(fname, content)
|
||||
end
|
||||
#
|
||||
if options['e'] # escape
|
||||
tuples = [
|
||||
[ 'bench_eruby.rhtml', '<%= CGI.escapeHTML((\1).to_s) %>' ],
|
||||
[ 'bench_erb.rhtml', '<%=h \1 %>' ],
|
||||
[ 'bench_erubis.rhtml', '<%== \1 %>' ],
|
||||
]
|
||||
for fname, replace in tuples
|
||||
content = File.read(fname).gsub(/<%= ?(.*?) ?%>/, replace)
|
||||
File.write(fname, content)
|
||||
end
|
||||
targets.delete('Erubis::TinyEruby') ## because TinyEruby doesn't support '<%== =>'
|
||||
end
|
||||
#
|
||||
context = YAML.load_file(contextfile)
|
||||
#
|
||||
params = {
|
||||
:printout=>options['p'],
|
||||
:testmode=>testmode,
|
||||
}
|
||||
app = BenchmarkApplication.new(ntimes, context, targets, params)
|
||||
app.perform_benchmark()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
if __FILE__ == $0
|
||||
|
||||
## open /dev/null
|
||||
$stdout = File.open('/dev/null', 'w')
|
||||
at_exit do
|
||||
$stdout.close()
|
||||
end
|
||||
|
||||
## start benchmark
|
||||
MainApplication.new().execute()
|
||||
|
||||
end
|
141
vendor/plugins/erubis/benchmark/bench_context.yaml
vendored
Normal file
141
vendor/plugins/erubis/benchmark/bench_context.yaml
vendored
Normal file
|
@ -0,0 +1,141 @@
|
|||
list:
|
||||
- name: Adobe Systems
|
||||
name2: Adobe Systems Inc.
|
||||
url: http://www.adobe.com
|
||||
symbol: ADBE
|
||||
price: 39.26
|
||||
change: 0.13
|
||||
ratio: 0.33
|
||||
- name: Advanced Micro Devices
|
||||
name2: Advanced Micro Devices Inc.
|
||||
url: http://www.amd.com
|
||||
symbol: AMD
|
||||
price: 16.22
|
||||
change: 0.17
|
||||
ratio: 1.06
|
||||
- name: Amazon.com
|
||||
name2: Amazon.com Inc
|
||||
url: http://www.amazon.com
|
||||
symbol: AMZN
|
||||
price: 36.85
|
||||
change: -0.23
|
||||
ratio: -0.62
|
||||
- name: Apple
|
||||
name2: Apple Inc.
|
||||
url: http://www.apple.com
|
||||
symbol: AAPL
|
||||
price: 85.38
|
||||
change: -0.87
|
||||
ratio: -1.01
|
||||
- name: BEA Systems
|
||||
name2: BEA Systems Inc.
|
||||
url: http://www.bea.com
|
||||
symbol: BEAS
|
||||
price: 12.46
|
||||
change: 0.09
|
||||
ratio: 0.73
|
||||
- name: CA
|
||||
name2: CA, Inc.
|
||||
url: http://www.ca.com
|
||||
symbol: CA
|
||||
price: 24.66
|
||||
change: 0.38
|
||||
ratio: 1.57
|
||||
- name: Cisco Systems
|
||||
name2: Cisco Systems Inc.
|
||||
url: http://www.cisco.com
|
||||
symbol: CSCO
|
||||
price: 26.35
|
||||
change: 0.13
|
||||
ratio: 0.5
|
||||
- name: Dell
|
||||
name2: Dell Corp.
|
||||
url: http://www.dell.com/
|
||||
symbol: DELL
|
||||
price: 23.73
|
||||
change: -0.42
|
||||
ratio: -1.74
|
||||
- name: eBay
|
||||
name2: eBay Inc.
|
||||
url: http://www.ebay.com
|
||||
symbol: EBAY
|
||||
price: 31.65
|
||||
change: -0.8
|
||||
ratio: -2.47
|
||||
- name: Google
|
||||
name2: Google Inc.
|
||||
url: http://www.google.com
|
||||
symbol: GOOG
|
||||
price: 495.84
|
||||
change: 7.75
|
||||
ratio: 1.59
|
||||
- name: Hewlett-Packard
|
||||
name2: Hewlett-Packard Co.
|
||||
url: http://www.hp.com
|
||||
symbol: HPQ
|
||||
price: 41.69
|
||||
change: -0.02
|
||||
ratio: -0.05
|
||||
- name: IBM
|
||||
name2: International Business Machines Corp.
|
||||
url: http://www.ibm.com
|
||||
symbol: IBM
|
||||
price: 97.45
|
||||
change: -0.06
|
||||
ratio: -0.06
|
||||
- name: Intel
|
||||
name2: Intel Corp.
|
||||
url: http://www.intel.com
|
||||
symbol: INTC
|
||||
price: 20.53
|
||||
change: -0.07
|
||||
ratio: -0.34
|
||||
- name: Juniper Networks
|
||||
name2: Juniper Networks, Inc
|
||||
url: http://www.juniper.net/
|
||||
symbol: JNPR
|
||||
price: 18.96
|
||||
change: 0.5
|
||||
ratio: 2.71
|
||||
- name: Microsoft
|
||||
name2: Microsoft Corp
|
||||
url: http://www.microsoft.com
|
||||
symbol: MSFT
|
||||
price: 30.6
|
||||
change: 0.15
|
||||
ratio: 0.49
|
||||
- name: Oracle
|
||||
name2: Oracle Corp.
|
||||
url: http://www.oracle.com
|
||||
symbol: ORCL
|
||||
price: 17.15
|
||||
change: 0.17
|
||||
ratio: 1.0
|
||||
- name: SAP
|
||||
name2: SAP AG
|
||||
url: http://www.sap.com
|
||||
symbol: SAP
|
||||
price: 46.2
|
||||
change: -0.16
|
||||
ratio: -0.35
|
||||
- name: Seagate Technology
|
||||
name2: Seagate Technology
|
||||
url: http://www.seagate.com/
|
||||
symbol: STX
|
||||
price: 27.35
|
||||
change: -0.36
|
||||
ratio: -1.3
|
||||
- name: Sun Microsystems
|
||||
name2: Sun Microsystems Inc.
|
||||
url: http://www.sun.com
|
||||
symbol: SUNW
|
||||
price: 6.33
|
||||
change: -0.01
|
||||
ratio: -0.16
|
||||
- name: Yahoo
|
||||
name2: Yahoo! Inc.
|
||||
url: http://www.yahoo.com
|
||||
symbol: YHOO
|
||||
price: 28.04
|
||||
change: -0.17
|
||||
ratio: -0.6
|
4
vendor/plugins/erubis/benchmark/templates/_footer.html
vendored
Normal file
4
vendor/plugins/erubis/benchmark/templates/_footer.html
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
52
vendor/plugins/erubis/benchmark/templates/_header.html
vendored
Normal file
52
vendor/plugins/erubis/benchmark/templates/_header.html
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Stock Prices</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
||||
<link rel="shortcut icon" href="/images/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="/css/style.css" media="all" />
|
||||
<script type="text/javascript" src="/js/util.js"></script>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
|
||||
body {
|
||||
color: #333333;
|
||||
line-height: 150%;
|
||||
}
|
||||
|
||||
thead {
|
||||
font-weight: bold;
|
||||
background-color: #CCCCCC;
|
||||
}
|
||||
|
||||
.odd {
|
||||
background-color: #FFCCCC;
|
||||
}
|
||||
|
||||
.even {
|
||||
background-color: #CCCCFF;
|
||||
}
|
||||
|
||||
.minus {
|
||||
color: #FF0000;
|
||||
}
|
||||
|
||||
/*]]>*/
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Stock Prices</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th><th>symbol</th><th>name</th><th>price</th><th>change</th><th>ratio</th>
|
||||
</tr>
|
||||
</thead>
|
29
vendor/plugins/erubis/benchmark/templates/bench_erb.rhtml
vendored
Normal file
29
vendor/plugins/erubis/benchmark/templates/bench_erb.rhtml
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
<tbody>
|
||||
<%
|
||||
n = 0
|
||||
for item in list
|
||||
n += 1
|
||||
%>
|
||||
<tr class="<%= n % 2 == 0 ? 'even' : 'odd' %>">
|
||||
<td style="text-align: center"><%= n %></td>
|
||||
<td>
|
||||
<a href="/stocks/<%= item['symbol'] %>"><%= item['symbol'] %></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<%= item['url'] %>"><%= item['name'] %></a>
|
||||
</td>
|
||||
<td>
|
||||
<strong><%= item['price'] %></strong>
|
||||
</td>
|
||||
<% if item['change'] < 0.0 %>
|
||||
<td class="minus"><%= item['change'] %></td>
|
||||
<td class="minus"><%= item['ratio'] %></td>
|
||||
<% else %>
|
||||
<td><%= item['change'] %></td>
|
||||
<td><%= item['ratio'] %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<%
|
||||
end
|
||||
%>
|
||||
</tbody>
|
29
vendor/plugins/erubis/benchmark/templates/bench_erubis.rhtml
vendored
Normal file
29
vendor/plugins/erubis/benchmark/templates/bench_erubis.rhtml
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
<tbody>
|
||||
<%
|
||||
n = 0
|
||||
for item in list
|
||||
n += 1
|
||||
%>
|
||||
<tr class="<%= n % 2 == 0 ? 'even' : 'odd' %>">
|
||||
<td style="text-align: center"><%= n %></td>
|
||||
<td>
|
||||
<a href="/stocks/<%= item['symbol'] %>"><%= item['symbol'] %></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<%= item['url'] %>"><%= item['name'] %></a>
|
||||
</td>
|
||||
<td>
|
||||
<strong><%= item['price'] %></strong>
|
||||
</td>
|
||||
<% if item['change'] < 0.0 %>
|
||||
<td class="minus"><%= item['change'] %></td>
|
||||
<td class="minus"><%= item['ratio'] %></td>
|
||||
<% else %>
|
||||
<td><%= item['change'] %></td>
|
||||
<td><%= item['ratio'] %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<%
|
||||
end
|
||||
%>
|
||||
</tbody>
|
29
vendor/plugins/erubis/benchmark/templates/bench_eruby.rhtml
vendored
Normal file
29
vendor/plugins/erubis/benchmark/templates/bench_eruby.rhtml
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
<tbody>
|
||||
<%
|
||||
n = 0
|
||||
for item in list
|
||||
n += 1
|
||||
%>
|
||||
<tr class="<%= n % 2 == 0 ? 'even' : 'odd' %>">
|
||||
<td style="text-align: center"><%= n %></td>
|
||||
<td>
|
||||
<a href="/stocks/<%= item['symbol'] %>"><%= item['symbol'] %></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<%= item['url'] %>"><%= item['name'] %></a>
|
||||
</td>
|
||||
<td>
|
||||
<strong><%= item['price'] %></strong>
|
||||
</td>
|
||||
<% if item['change'] < 0.0 %>
|
||||
<td class="minus"><%= item['change'] %></td>
|
||||
<td class="minus"><%= item['ratio'] %></td>
|
||||
<% else %>
|
||||
<td><%= item['change'] %></td>
|
||||
<td><%= item['ratio'] %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<%
|
||||
end
|
||||
%>
|
||||
</tbody>
|
Loading…
Add table
Add a link
Reference in a new issue