').html_safe
end
end
@@ -115,14 +115,14 @@ require 'stringsupport'
def truncate(text, *args)
options = args.extract_options!
options.reverse_merge!(:length => 30, :omission => "...")
- return text if text.num_chars <= options[:length]
+ return text.html_safe if text.num_chars <= options[:length]
len = options[:length] - options[:omission].as_utf8.num_chars
t = ''
text.split.collect do |word|
if t.num_chars + word.num_chars <= len
t << word + ' '
else
- return t.chop + options[:omission]
+ return (t.chop + options[:omission]).html_safe
end
end
end
diff --git a/app/models/page.rb b/app/models/page.rb
index c799792a..9b291dfb 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -90,7 +90,7 @@ class Page < ActiveRecord::Base
# Returns the original wiki-word name as separate words, so "MyPage" becomes "My Page".
def plain_name
- web.brackets_only? ? name.escapeHTML : WikiWords.separate(name).escapeHTML
+ web.brackets_only? ? name.escapeHTML.html_safe : WikiWords.separate(name).escapeHTML.html_safe
end
LOCKING_PERIOD = 30.minutes
diff --git a/app/views/admin/edit_web.rhtml b/app/views/admin/edit_web.rhtml
index 75782bf3..e42df362 100644
--- a/app/views/admin/edit_web.rhtml
+++ b/app/views/admin/edit_web.rhtml
@@ -46,18 +46,18 @@
}, @web.color) %>
- />
+ />
- />
+ />
- />
+ />
- />
+ />
Allow uploads of no more than
@@ -100,7 +100,7 @@
The published version is accessible through URLs like /<%= @web.address %>/published/HomePage.
+
+ - |
+ '<%= -%>' removes tail spaces and newlines.
+ This is for compatibiliy with ERB when trim mode is '-'.
+ '<%= =%>' also removes tail spaces and newlines, and this is
+ Erubis-original enhancement (cooler than '<%= -%>', isn't it?).
+
+ ex2.rhtml:
+
+
+ - |
+ Erubis::Eruby.load_file() now allows you to change cache filename.
+
+ ex.
+ eruby = Erubis::Eruby.load_file("ex3.rhtml",
+ :cachename=>'ex3.rhtml.cache')
+
+
+- release: 2.5.0
+ date: 2008-01-30
+ enhancements:
+
+ - |
+ Ruby on Rails 2.0 support.
+ If you are using preprocessing, notice that _?('foo.id') will be NG
+ because it contains period ('.') character.
+
+ --------------------
+
+ [%= link_to 'Edit', edit_user_path(_?('@user.id')) %]
+ [%= link_to 'Show', @user %]
+ [%= link_to 'Delete', @user, :confirm=>'OK?', :method=>:delete %]
+
+
+ <%= user_id = @user.id %>
+ [%= link_to 'Edit', edit_user_path(_?('user_id')) %]
+ [%= link_to 'Show', :action=>'show', :id=>_?('user_id') %]
+ [%= link_to 'Delete', {:action=>'destroy', :id=>_?('user_id')},
+ {:confirm=>'OK?', :method=>:delete} %]
+ --------------------
+
+ - |
+ (experimental)
+ Rails form helper methods for preprocessing are added.
+ These helper methos are available with preprocessing.
+
+ ex. _form.rhtml
+ --------------------
+ Name: <%= text_field :user, :name %>
+ Name: [%= pp_text_field :user, :name %]
+ --------------------
+
+ preprocessed:
+ --------------------
+ Name: <%= text_field :user, :name %>
+ Name:
+ --------------------
+
+ Ruby code:
+ --------------------
+ _buf << '
+ Name: '; _buf << ( text_field :stock, :name ).to_s; _buf << '
+ Name:
+ ';
+ --------------------
+
+ This shows that text_filed() is called every time when rendering,
+ but pp_text_filed() is called only once when loading template,
+ so pp_text_field() with prepocessing is much faster than text_field().
+
+ See User's guide for details.
+ http://www.kuwata-lab.com/erubis/users-guide.05.html#rails-formhelpers
+
+#
+- release: 2.4.1
+ date: 2007-09-25
+ enhancements:
+
+ - |
+ Add new section 'evaluate(context) v.s. result(binding)' to user's guide.
+ This section describes why Erubis::Eruby#evaluate(context) is recommended
+ rather than Erubis::Eruby#result(binding).
+ User's Guide > Other Topics > evaluate(context) v.s. result(binding)
+ http://www.kuwata-lab.com/erubis/users-guide.06.html#topics-context-vs-binding
+
+ - |
+ Add new command-line property '--docwrite={true|false}' to
+ Erubis::Ejavascript.
+ If this property is true then 'document.write(_buf.join(""));' is used
+ as postamble and if it is false then '_buf.join("")' is used.
+ Default is true for compatibility reason but it will be false in the
+ future release.
+ (This feature was proposed by D.Dribin. Thank you.)
+
+ bugfix:
+
+ - |
+ When using Erubis::Eruby#evaluate(), changing local variables in
+ templates have affected to variables accessible with TOPLEVEL_BINDING.
+ It means that if you change variables in templates, it is possible to
+ change variables in main program.
+ This was a bug and is now fixed not to affect to variables in main
+ program.
+
+ ex. template.rhtml
+ --------------------
+ <% for x in @items %>
+ item = <%= x %>
+ <% end %>
+ --------------------
+
+ ex. main-program.rb
+ --------------------
+ require 'erubis'
+ x = 10
+ items = ['foo', 'bar', 'baz']
+ eruby = Erubis::Eruby.new(File.read('template.rhtml'))
+ s = eruby.evaluate(:items=>items)
+ print s
+ $stderr.puts "*** debug: x=#{x.inspect}" #=> x="baz" (2.4.0)
+ #=> x=10 (2.4.1)
+ --------------------
+
+ - |
+ PercentLineEnhancer was very slow. Now performance problem is solved.
+
+
+#
+- release: 2.4.0
+ date: 2007-07-19
+ enhancements:
+
+ - |
+ Preprocessing is supported by Ruby on Rails helper.
+ Preprocessing makes Ruby on Rails application about 20-40 percent faster.
+
+ For example,
+
+ [%= link_to 'Show', :action=>'show', :id=>_?('@user.id') %]
+
+ is evaluate by preprocessor and expanded into the following
+ when template file is loaded.
+
+ Show
+
+ It means that link_to() is not called when template is rendered
+ and rendering speed will be much faster in the result.
+
+ See User's Guide for details.
+
+ - |
+ Erubis::Eruby#evaluate() (or Erubis::RubyEvaluator#evaluate()) now
+ creates Proc object from @src and eval it.
+
+ def evaluate(context=Context.new)
+ context = Context.new(context) if context.is_a?(Hash)
+ @_proc ||= eval("proc { #{@src} }", TOPLEVEL_BINDING, @filename || '(erubis)')
+ return context.instance_eval(&@_proc)
+ end
+
+ This makes evaluate() much faster when eruby object is reused.
+
+ - |
+ Erubis::Eruby#def_method() is supported.
+ This method defines ruby code as instance method or singleton metod.
+
+ require 'erubis'
+ s = "hello <%= name %>"
+ eruby = Erubis::Eruby.new(s)
+ filename = 'hello.rhtml'
+
+ ## define instance method to Dummy class (or module)
+ class Dummy; end
+ eruby.def_method(Dummy, 'render(name)', filename) # filename is optional
+ p Dummy.new.render('world') #=> "hello world"
+
+ ## define singleton method to an object
+ obj = Object.new
+ eruby.def_method(obj, 'render(name)', filename) # filename is optional
+ p obj.render('world') #=> "hello world"
+
+ This is equivarent to ERB#def_method().
+
+ - |
+ Erubis::XmlHelper.url_escape() and u() which is alias of url_escape()
+ are added.
+ This is equivarent to ERB#Util.url_escape().
+
+
+ bugfix:
+ - Help message was not shown when '-h' is specified. Fixed.
+ - 'def method()' was not availabe in template file. Fixed.
+
+
+#
+- release: 2.3.1
+ date: 2007-05-26
+ bugfix:
+ - A serious bug in 'helpers/rails_helper.rb' is fixed.
+ You must be update if you are using Erubis with Ruby on Rails.
+
+
+#
+- release: 2.3.0
+ date: 2007-05-23
+ enhancements:
+ - |
+ New class 'Erubis::FastEruby' is added.
+ It is a subclass of Erubis::Eruby and includes InterpolationEnhancer.
+ Erubis::FastEruby is compatible with and faster than Erubis::Eruby.
+
+ - |
+ New enhancer 'InterpolationEnhancer' is added.
+ This enhancer uses expression interpolation to eliminate method call
+ of String#<<. In the result, this enhancer makes Eruby a little faster.
+
+ --------------------
+ ## Assume that input is '<%=name%>'.
+ ## Eruby convert input into the following code. String#<< is called 5 times.
+ _buf << ''; _buf << (name).to_s; _buf << '';
+
+ ## When InterpolationEnhancer is used, String#<< is called only once.
+ _buf << %Q`#{name}`;
+ --------------------
+
+ - |
+ New enhancer 'ErboutEnhancer' is added.
+ ErboutEnhancer set '_erbout' as well as '_buf' to be compatible with ERB.
+
+ ex.
+ ====================
+ $ cat ex.rhtml
+
+ ';
+ _buf.to_s
+ ====================
+
+ - |
+ [experimental]
+ New enhancer 'DeleteIndentEnhancer' is added.
+ This enhancer deletes indentation of HTML file.
+
+ ex.
+ ====================
+ $ cat ex.rhtml
+
+
+ <% for item in ['AAA', 'BBB', 'CCC'] %>
+
<%= item %>
+ <% end %>
+
+
+ $ erubis ex.rhtml
+
+
+
AAA
+
BBB
+
CCC
+
+
+ $ erubis -E DeleteIndent ex.rhtml
+
+
+
AAA
+
BBB
+
CCC
+
+
+ ====================
+
+ - |
+ Mod_ruby is supported (very thanks to Andrew R Jackson!).
+ See users-guide and 'contrib/erubis-run.rb' for details.
+
+ - |
+ New command-line option '-X', '-N', '-U', and '-C' are added.
+ These are intended to be a replacement of 'notext' command.
+ '-X' shows only ruby statements and expressions.
+ '-N' adds line numbers.
+ '-U' compress empty lines into a line.
+ '-C' removes empty lines.
+
+
+ changes:
+
+ - |
+ 'helpers/rails_helper.rb' is changed to use ErboutEnhancer.
+ The following is an examle to use Erubis with Ruby on Rails.
+
+ File 'config/environment.rb':
+ ----------------------------------------
+ require 'erubis/helpers/rails_helper'
+ #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
+ #Erubis::Helpers::RailsHelper.init_properties = {}
+ #Erubis::Helpers::RailsHelper.show_src = false # set true for debugging
+ ----------------------------------------
+
+ - |
+ Command 'notext' has been removed. Use '-X', '-N', '-U', and '-C'
+ instead.
+
+ - |
+ Tab characters in YAML file are expaneded automatically.
+ If you want not to expand tab characters, add command-line optio '-T'.
+
+ - |
+ Benchmark scripts (benchmark/bench.*) are rewrited.
+
+ - |
+ Users-guide (doc/users-guide.html) is updated.
+
+
+
+#
+- release: 2.2.0
+ date: 2007-02-11
+ enhancements:
+ - |
+ Performance tuned up. Release 2.2.0 works about 8 percent faster
+ than 2.1.0.
+ As a result, Erubis works more than 10 percent faster than eruby.
+ (eruby is the extension module of eRuby written in C.)
+
+ - |
+ Support of Ruby on Rails improved.
+ If you want to use Erubis with Ruby on Rails, add the following code
+ into your 'config/environment.rb' and restart web server.
+ This will set Erubis as eRuby compiler in Ruby on Rails instead of ERB.
+
+ --------------------
+ require 'erubis/helpers/rails_helper'
+ #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby
+ #Erubis::Helpers::RailsHelper.init_properties = {}
+ #Erubis::Helpers::RailsHelper.show_src = true
+ --------------------
+
+ Methods 'capture()' and 'content_for()' of ActionView::Helpers::CaptureHelper
+ are available. Methd ActionView::Helpers::TextHelper#concat() is also available.
+
+ If Erubis::Helpers::RailsHelper.show_src is ture, Erubis prints converted
+ Ruby code into log file (such as 'log/development.log').
+
+ - |
+ Erubis::Engine.load_file(filename) creates cache file (filename +
+ '.cache') automatically if cache file is old or not exist.
+ Caching makes Erubis about 40-50 percent faster.
+
+ ex.
+ --------------------
+ require 'erubis'
+ eruby = Erubis::Eruby.load_file('example.rhtml')
+ ## cache file 'example.rhtml.cache' is created automatically
+ --------------------
+
+ - |
+ Command-line option '-f datafile' can take Ruby script ('*.rb')
+ as well as YAML file ('*.yaml' or '*.yml').
+
+ ex.
+ ====================
+ $ cat context.rb
+ @title = 'Example'
+ @list = %w[AAA BBB CCC]
+ $ cat example.rhtml
+
<%= @title %>
+
+ <% for item in @list %>
+
<%= item %>
+ <% end %>
+
+ $ erubis -f context.rb example.rhtml
+
Example
+
+
AAA
+
BBB
+
CCC
+
+ ====================
+
+ - |
+ New command-line option '-c context' support. It takes context string
+ in YAML inline style or Ruby code style.
+
+ ex. YAML inline style
+ ====================
+ $ erubis -c '{title: Example, list: [AAA, BBB, CCC]}' example.rhtml
+ ====================
+
+ ex. Ruby style
+ ====================
+ $ erubis -c '@title="Example"; @list=%w[AAA BBB CCC]' example.rhtml
+ ====================
+
+ - |
+ New command-line option '-z' (syntax checking) support. It is similar
+ to 'erubis -x file.rhtml | ruby -wc', but it can take several filenames.
+
+ ex.
+ ====================
+ $ erubis -z app/views/*/*.rhtml
+ Syntax OK
+ ====================
+
+ - |
+ New constant Erubis::VERSION added.
+
+
+ changes:
+ - |
+ Class Erubis::Eruby changed to include Erubis::StringBufferEnhancer
+ instead of Erubis::ArrayBufferEnhancer.
+ This is for Ruby on Rails support.
+
+ ex.
+ ====================
+ $ cat example.rhtml
+
+ '; @list.each_with_index do |item, i|
+ klass = i % 2 == 0 ? 'odd' : 'even'
+ _buf << '
+
'; _buf << (item).to_s; _buf << '
+
+ '; end
+ _buf << '
+ ';
+ _buf.join
+ ====================
+
+ - |
+ Add new command 'notext' which remove text part from eRuby
+ script and leaves only Ruby code.
+ This is very useful for debug of eRuby script.
+
+ example2.rhtml
+ --------------------
+
+
+
+ <% @list.each_with_index do |item, i| %>
+ <% klass = i % 2 == 0 ? 'odd' : 'even' %>
+
+
<%== item %>
+
+ <% end %>
+
+
+
+ --------------------
+
+ command line example:
+ ====================
+ $ notext example2.rhtml
+ _buf = [];
+
+
+ @list.each_with_index do |item, i| ;
+ klass = i % 2 == 0 ? 'odd' : 'even' ;
+ _buf << ( klass ).to_s;
+ _buf << Erubis::XmlHelper.escape_xml( item );
+
+ end ;
+
+
+
+ _buf.join
+ $ notext -nc example2.rhtml
+ 1: _buf = [];
+ 4: @list.each_with_index do |item, i| ;
+ 5: klass = i % 2 == 0 ? 'odd' : 'even' ;
+ 6: _buf << ( klass ).to_s;
+ 7: _buf << Erubis::XmlHelper.escape_xml( item );
+ 9: end ;
+ 13: _buf.join
+ ====================
+
+ - |
+ Add new enhance 'NoCode' which removes ruby code from
+ eRuby script and leaves only HTML text part.
+ It is very useful to validate HTML of eRuby script.
+
+ command-line example:
+ ====================
+ $ erubis -x -E NoCode example2.rhtml
+
+
+
+
+
+
+
+
+
+
+
+
+ ====================
+
+ changes:
+ - License is changed to LGPL.
+ - Command-line property '--escape=name' is renamed to
+ '--escapefunc=name'.
+ - When command-line option '-l perl' is specified, function
+ 'encode_entities()' is used ad escaping function which is
+ available wth HTML::Entities module.
+
+ bugfix:
+ - There is a certain pattern which makes Engine#convert()
+ too slow. Now Engne#convert() is fixed not to be slown.
+ - Command name is now displayed when '-h' is specified.
+
+
+#
+- release: 2.0.1
+ date: 2006-06-21
+ bugfix:
+ - some minor bugs are fixed
+
+
+#
+- release: 2.0.0
+ date: 2006-05-20
+ changes:
+ - module 'PrintEnhancer' is renamed to 'PrintEnabledEnahncer'
+ - module 'FastEnhancer' and class 'FastEruby' is obsolete because they are integrated into Eruby class
+ - Eruby#evaluate() calls instance_eval() instead of eval()
+ - XmlEruby.escape_xml() is moved to XmlHelper.escape_xml()
+ enhancements:
+ - multi programming language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
+ - class Eruby runs very fast because FastEnhancer module is integrated into Eruby by default
+ - TinyEruby class (tiny.rb) is added
+ - module ArrayBufferEnhancer added
+ - module ArrayEnhancer added
+ - module BiPatternEnhancer added
+ - module EscapeEnhancer added
+ - module HeaderFooterEnhancer added
+ - module NoTextEnhancer added
+ - module PercentLineEnhancer added
+ - module PrintEnabledEnhancer added
+ - module PrintOutEnhancer added
+ - module SimplifyEnhancer added
+ - module StringBufferEnhancer added
+ - module StringIOEnhancer added
+ - command-line option '-b' (body only) added
+ - command-line option '-e' (escape) added
+ - command-line option '-l' (lang) added
+ - command-line option '-E' (enhancer) added
+ - command-line option '-I' (require path) added
+ - command-line option '-K' (kanji code) added
+ - command-line option '-S' (string to symbol) added
+ - command-line option '-B' (call result(binding())) added
+
+
+#
+- release: 1.1.0
+ date: 2006-03-05
+ enhancements:
+ - '<%# ... %>' is supported
+ - PrintEnhancer, PrintEruby, and PrintXmlEruby added
+
+- release: 1.0.1
+ date: 2006-02-01
+ bugfixes:
+ - bin/erubis is available with RubyGems
+
+
+#
+- release: 1.0.0
+ date: 2006-02-01
+ bugfixes:
+ - first release
+
diff --git a/vendor/plugins/erubis-2.6.5/MIT-LICENSE b/vendor/plugins/erubis-2.6.5/MIT-LICENSE
new file mode 100644
index 00000000..99fbcfd3
--- /dev/null
+++ b/vendor/plugins/erubis-2.6.5/MIT-LICENSE
@@ -0,0 +1,20 @@
+copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/plugins/erubis-2.6.5/README.txt b/vendor/plugins/erubis-2.6.5/README.txt
new file mode 100644
index 00000000..0f07e3ee
--- /dev/null
+++ b/vendor/plugins/erubis-2.6.5/README.txt
@@ -0,0 +1,102 @@
+= README
+
+release:: 2.6.5
+copyright:: copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
+
+
+
+== About Erubis
+
+Erubis is an implementation of eRuby. It has the following features.
+* Very fast, almost three times faster than ERB and even 10% faster than eruby
+* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
+* Auto escaping support
+* Auto trimming spaces around '<% %>'
+* Embedded pattern changeable (default '<% %>')
+* Enable to handle Processing Instructions (PI) as embedded pattern (ex. '')
+* Context object available and easy to combine eRuby template with YAML datafile
+* Print statement available
+* Easy to extend and customize in subclass
+* Ruby on Rails support
+
+Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
+Erubis now supports Ruby 1.9.
+
+See doc/users-guide.html for details.
+
+
+
+== Installation
+
+* If you have installed RubyGems, just type gem install erubis.
+
+ $ sudo gem install erubis
+
+* Else install abstract[http://rubyforge.org/projects/abstract/] at first,
+ and download erubis_X.X.X.tar.bz2 and install it by setup.rb.
+
+ $ tar xjf abstract_X.X.X.tar.bz2
+ $ cd abstract_X.X.X/
+ $ sudo ruby setup.rb
+ $ cd ..
+ $ tar xjf erubis_X.X.X.tar.bz2
+ $ cd erubis_X.X.X/
+ $ sudo ruby setup.rb
+
+* (Optional) It is able to merge 'lib/**/*.rb' into 'bin/erubis' by
+ 'contrib/inline-require' script.
+
+ $ tar xjf erubis_X.X.X.tar.bz2
+ $ cd erubis_X.X.X/
+ $ cp /tmp/abstract_X.X.X/lib/abstract.rb lib
+ $ unset RUBYLIB
+ $ contrib/inline-require -I lib bin/erubis > contrib/erubis
+
+
+
+== Ruby on Rails Support
+
+Erubis supports Ruby on Rails.
+All you have to do is to add the following code into your 'config/environment.rb'
+and restart web server.
+
+ require 'erubis/helpers/rails_helper'
+ #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby
+ #Erubis::Helpers::RailsHelper.init_properties = {}
+ #Erubis::Helpers::RailsHelper.show_src = nil
+
+If Erubis::Helpers::RailsHelper.show_src is ture, Erubis prints converted Ruby code
+into log file ('log/development.log' or so). It is useful for debug.
+
+
+
+== Exploring Guide
+
+If you are exploring Eruby, see the following class at first.
+* Erubis::TinyEruby (erubis/tiny.rb) --
+ the most simple eRuby implementation.
+* Erubis::Engine (erubis/engine.rb) --
+ base class of Eruby, Ephp, Ejava, and so on.
+* Erubis::Eruby (erubis/engine/eruby.rb) --
+ engine class for eRuby.
+* Erubis::Converter (erubis/converter.rb) --
+ convert eRuby script into Ruby code.
+
+
+
+== Benchmark
+
+'benchmark/erubybenchmark.rb' is a benchmark script of Erubis.
+Try 'ruby erubybenchmark.rb' in benchmark directory.
+
+
+
+== License
+
+MIT License
+
+
+
+== Author
+
+makoto kuwata
diff --git a/vendor/plugins/erubis-2.6.5/benchmark/Makefile b/vendor/plugins/erubis-2.6.5/benchmark/Makefile
new file mode 100644
index 00000000..fa740feb
--- /dev/null
+++ b/vendor/plugins/erubis-2.6.5/benchmark/Makefile
@@ -0,0 +1,6 @@
+
+bench:
+ ruby bench.rb -n 10000
+
+clean:
+ rm -rf bench_*.rhtml*
diff --git a/vendor/plugins/erubis-2.6.5/benchmark/bench.rb b/vendor/plugins/erubis-2.6.5/benchmark/bench.rb
new file mode 100644
index 00000000..e541dde7
--- /dev/null
+++ b/vendor/plugins/erubis-2.6.5/benchmark/bench.rb
@@ -0,0 +1,313 @@
+#!/usr/bin/env ruby
+
+###
+### $Release: 2.6.5 $
+### copyright(c) 2006-2009 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
diff --git a/vendor/plugins/erubis-2.6.5/benchmark/bench_context.yaml b/vendor/plugins/erubis-2.6.5/benchmark/bench_context.yaml
new file mode 100644
index 00000000..e0ab4e85
--- /dev/null
+++ b/vendor/plugins/erubis-2.6.5/benchmark/bench_context.yaml
@@ -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
diff --git a/vendor/plugins/erubis-2.6.5/benchmark/templates/_footer.html b/vendor/plugins/erubis-2.6.5/benchmark/templates/_footer.html
new file mode 100644
index 00000000..3ae6d4d0
--- /dev/null
+++ b/vendor/plugins/erubis-2.6.5/benchmark/templates/_footer.html
@@ -0,0 +1,4 @@
+
+
+