summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2006-08-09 22:27:24 +0000
committermakoto kuwata <kwa@kuwata-lab.com>2006-08-09 22:27:24 +0000
commiteb9d45f66f892d5f28433f981e77338914340ebc (patch)
tree14361f7e057c8692e469ef21e79fe93b05a133d9
parent21583f7fb5de74c33ea5acf0481bc44fd7a481e6 (diff)
downloaderubis-eb9d45f66f892d5f28433f981e77338914340ebc.tar.gz
- [change] 'rails/action_view_support.rb' is renamed to 'helper/rails.rb'
- [update] users-guide updated
-rw-r--r--ChangeLog.txt4
-rw-r--r--README.txt13
-rw-r--r--doc/users-guide.html29
-rw-r--r--doc/users-guide.txt13
-rw-r--r--lib/erubis.rb13
-rw-r--r--lib/erubis/helper/rails.rb (renamed from lib/erubis/rails/action_view_support.rb)44
6 files changed, 77 insertions, 39 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 622fb8e..a84f555 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -2,6 +2,10 @@
.?lastupdate: $Date$
.?version: $Rev$
+.: Rev.36 (2006-08-10)
+ .- [change] 'rails/action_view_support.rb' is renamed to 'helper/rails.rb'
+ .- [update] users-guide updated
+
.: Rev.35 (2006-08-05)
.- [enhance] add PI::Converter#parse_stmt2()
diff --git a/README.txt b/README.txt
index 61c6dbd..1258e3c 100644
--- a/README.txt
+++ b/README.txt
@@ -8,13 +8,16 @@ copyright:: $Copyright$
== About Erubis
Erubis is an implementation of eRuby. It has the following features.
-* Very fast (about three times faster than ERB and almost as fast as eruby)
+* Very fast, almost three times faster than ERB and even faster than eruby (implemented in C)
+* Auto escaping support
* Auto trimming spaces around '<% %>'
-* Auto escape (sanitizing)
-* Changeable embedded pattern (default '<% %>')
-* Context object available
-* Easy to expand and customize in subclass
+* Embedded pattern changeable (default '<% %>')
+* Enable to handle Processing Instructions (PI) as embedded pattern (ex. '<?rb ... ?>')
* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
+* Context object available and easy to combine eRuby template with YAML datafile
+* Print statement available
+* Easy to expand and customize in subclass
+* Ruby on Rails support
Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
diff --git a/doc/users-guide.html b/doc/users-guide.html
index 499ba90..925cc08 100644
--- a/doc/users-guide.html
+++ b/doc/users-guide.html
@@ -33,13 +33,15 @@ It has the following features.
</li>
<li>Enable to handle Processing Instructions (PI) as embedded pattern (ex. '&lt;?rb ... ?&gt;')
</li>
-<li>Support multi-language (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
+<li>Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
</li>
<li>Context object available and easy to combine eRuby template with YAML datafile
</li>
<li>Print statement available
</li>
-<li>Easy to extend in subclass
+<li>Easy to expand and customize in subclass
+</li>
+<li>Ruby on Rails support
</li>
</ul>
<p>Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
@@ -212,6 +214,12 @@ puts <strong>eruby.src</strong> # print script source
puts "---------- result ----------"
list = ['aaa', 'bbb', 'ccc']
puts <strong>eruby.result(binding())</strong> # get result
+
+## # or
+## eruby = Erubis::Eruby.new
+## input = File.read('example1.eruby')
+## src = eruby.convert(input)
+## eval src
</pre>
<div class="terminal_caption">
output</div>
@@ -413,7 +421,7 @@ $ cat stderr.log
*** debug: item="b&amp;b"
*** debug: item="\"ccc\""
</pre>
-<p>The command-line option '-e'<sup>(<a href="#fnref:2" name="fnlink:2">*2</a>)</sup> will do the same action as Erubis::EscapedEruby.
+<p>The command-line option '-e' will do the same action as Erubis::EscapedEruby.
This option is available for any language.
</p>
<pre class="terminal">$ erubis -l ruby <strong>-e</strong> example3.eruby
@@ -446,8 +454,6 @@ end
<dl compact>
<dt>(<a name="fnref:1" href="#fnlink:1">*1</a>)</dt>
<dd>Erubis::EscapedEruby class includes Erubis::EscapeEnhancer which swtches the action of '&lt;%= %&gt;' and '&lt;%== %&gt;'.</dd>
- <dt>(<a name="fnref:2" href="#fnlink:2">*2</a>)</dt>
- <dd>Command-line option '-e' is equivarent to '-E Escape'.</dd>
</dl>
</div>
<br>
@@ -1882,12 +1888,13 @@ Add the following code to your 'app/controllers/application.rb'.
</p>
<div class="program_caption">
app/controllers/application.rb</div>
-<pre class="program">require 'erubis/rails/action_view_support'
+<pre class="program">require 'erubis/helper/rails'
suffix = 'erubis'
-ActionView::Base.register_template_handler("erubis", Erubis::Rails::ViewTemplate)
-Erubis::Rails::ViewTemplate.engine_class = Erubis::EscapedEruby ## or Erubis::PI::Eruby
+ActionView::Base.register_template_handler("erubis", Erubis::Helper::RailsTemplate)
+#Erubis::Helper::RailsTemplate.engine_class = Erubis::EscapedEruby ## or Erubis::PI::Eruby
+#Erubis::Helper::RailsTemplate.default_properties = { :escape=&gt;true, :escapefunc=&gt;'h' }
</pre>
-<p>If you specify Erubis::Rails::CachedViewTemplate class instead of Erubis::Rails::ViewTemplate class, template string is cached in memory (but template is not reloaded when it is modified).
+<p>If you specify Erubis::Helper::CachedRailsTemplate class instead of Erubis::Helper::RailsTemplate class, template string is cached in memory (but template is not reloaded when it is modified).
</p>
<br>
@@ -1983,7 +1990,7 @@ example of using NoCodeEnhancer with PHP file</div>
Here is an example result of benchmark.
</p>
<div class="output_caption">
-Env: Linux FedoraCore4, Celeron 667MHz, Mem512MB, Ruby1.8.4</div>
+Env: Linux FedoraCore4, Celeron 667MHz, Mem512MB, Ruby1.8.4, eruby1.0.5</div>
<pre class="output"> user system total real
ERuby 131.990000 1.900000 133.890000 (135.061456)
ERB 385.040000 3.180000 388.220000 (391.570653)
@@ -1994,7 +2001,7 @@ Erubis::TinyEruby 118.720000 2.250000 120.970000 (122.022996)
Erubis::TinyStdoutEruby 87.130000 2.030000 89.160000 ( 89.879538)
</pre>
<div class="output_caption">
-Env: MacOS X 10.4, PowerPC 1.42GHz, Mem1.5GB, Ruby1.8.4</div>
+Env: MacOS X 10.4, PowerPC 1.42GHz, Mem1.5GB, Ruby1.8.4, eruby1.0.5</div>
<pre class="output"> user system total real
ERuby 55.040000 2.120000 57.160000 ( 89.311397)
ERB 103.960000 3.480000 107.440000 (159.231792)
diff --git a/doc/users-guide.txt b/doc/users-guide.txt
index fdee5d8..c866f8b 100644
--- a/doc/users-guide.txt
+++ b/doc/users-guide.txt
@@ -14,10 +14,10 @@ It has the following features.
.* Auto trimming spaces around '<% %>'
.* Embedded pattern changeable (default '<% %>')
.* Enable to handle Processing Instructions (PI) as embedded pattern (ex. '<?rb ... ?>')
-.* Support multi-language (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
+.* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
.* Context object available and easy to combine eRuby template with YAML datafile
.* Print statement available
-.* Easy to extend in subclass
+.* Easy to expand and customize in subclass
.* Ruby on Rails support
Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
@@ -1489,13 +1489,14 @@ Add the following code to your 'app/controllers/application.rb'.
.? app/controllers/application.rb
.--------------------
-require 'erubis/rails/action_view_support'
+require 'erubis/helper/rails'
suffix = 'erubis'
-ActionView::Base.register_template_handler("erubis", Erubis::Rails::ViewTemplate)
-Erubis::Rails::ViewTemplate.engine_class = Erubis::EscapedEruby ## or Erubis::PI::Eruby
+ActionView::Base.register_template_handler("erubis", Erubis::Helper::RailsTemplate)
+#Erubis::Helper::RailsTemplate.engine_class = Erubis::EscapedEruby ## or Erubis::PI::Eruby
+#Erubis::Helper::RailsTemplate.default_properties = { :escape=>true, :escapefunc=>'h' }
.--------------------
-If you specify Erubis::Rails::CachedViewTemplate class instead of Erubis::Rails::ViewTemplate class, template string is cached in memory (but template is not reloaded when it is modified).
+If you specify Erubis::Helper::CachedRailsTemplate class instead of Erubis::Helper::RailsTemplate class, template string is cached in memory (but template is not reloaded when it is modified).
diff --git a/lib/erubis.rb b/lib/erubis.rb
index 3937935..213a5c3 100644
--- a/lib/erubis.rb
+++ b/lib/erubis.rb
@@ -24,12 +24,15 @@
## </ul>
## END
## list = ['<aaa>', 'b&b', '"ccc"']
-## eruby = Erubis::Eruby.new(input)
-## puts "--- source ---"
-## puts eruby.src
+## eruby = Erubis::Eruby.new()
+## code = eruby.convert(input)
+## puts "--- code ---"
+## puts code
## puts "--- result ---"
-## puts eruby.evaluate(:list=>list)
-## # or puts eruby.result(binding())
+## context = Object.new
+## context.instance_variable_set("@list", list)
+## puts context.instance_eval(code)
+## # or @list = list; puts eval(code, binding())
##
## result:
## --- source ---
diff --git a/lib/erubis/rails/action_view_support.rb b/lib/erubis/helper/rails.rb
index 66fa04b..bba65d9 100644
--- a/lib/erubis/rails/action_view_support.rb
+++ b/lib/erubis/helper/rails.rb
@@ -7,10 +7,11 @@
###
### 1. add the folliwng code in your 'app/controllers/application.rb'.
### --------------------
-### require 'erubis/rails/action_view_support'
+### require 'erubis/helper/rails'
### suffix = 'erubis'
-### ActionView::Base.register_template_handler(suffix, Erubis::Rails::ViewTemplate)
-### Erubis::Rails::ViewTemplate.engine_class = Erubis::EscapedEruby ## if you want
+### ActionView::Base.register_template_handler(suffix, Erubis::Helper::RailsTemplate)
+### #Erubis::Helper::RailsTemplate.engine_class = Erubis::EscapedEruby ## if you want
+### #Erubis::Helper::RailsTemplate.default_class = { :escape=>true, :escapefunc='h' }
### --------------------
### 2. restart web server.
### 3. change view template filename from 'file.rhtml' to 'file.erubis'.
@@ -24,18 +25,12 @@ require 'erubis'
module Erubis
- module Rails
+ module Helper
- class ViewTemplate
-
-
- def initialize(view)
- @view = view
- end
+ class RailsTemplate
@@engine_class = Erubis::Eruby
- @@engine_instance = @@engine_class.new
def self.engine_class
@@engine_class
@@ -49,6 +44,25 @@ module Erubis
#cattr_accessor :engine_class
+ @@default_properties = { }
+
+ def self.default_properties
+ return @@default_properties
+ end
+
+ def self.default_properties=(properties)
+ @@default_properties = properties
+ end
+
+ #cattr_accessor :default_properties
+
+
+ def initialize(view)
+ @view = view
+ @@engine_instance = @@engine_class.new(nil, @@default_properties)
+ end
+
+
def convert(template)
code = @@engine_instance.convert(template)
return code
@@ -73,6 +87,9 @@ module Erubis
end
+ protected
+
+
def _localvar_code(_localvars)
list = _localvars.collect { |_name| "#{_name} = _localvars[#{_name.inspect}]\n" }
code = list.join()
@@ -90,7 +107,7 @@ module Erubis
- class CachedViewTemplate < ViewTemplate
+ class CachedRailsTemplate < RailsTemplate
@@cache_table = {}
@@ -124,6 +141,9 @@ module Erubis
end
+ protected
+
+
def _evaluate_proc(_proc_obj, _context, _localvars)
eval(_localvar_code(_localvars))
_context.instance_eval(&_proc_obj)