ActionView class was refactoring on Edge Rails, see Ticket #10437 for more details. The template engines are integrated into new ActionView::Template class, but we have to modify some scripts in order to run Erubis on Edge Rails.
0. Install Erubis and Edge Rails
% sudo gem install erubis
% cd /path/to/rails_app/ && rake rails::freeze:edge
1. Create a template handler for Erubis.
Copy and paste below code at #{RAILS_ROOT}/lib/erubis_rails_helper.rb.require 'erubis'
require 'erubis/preprocessing'
module Erubis
class Eruby
include ErboutEnhancer
end
class FastEruby
include ErboutEnhancer
end
end
module ActionView
module TemplateHandlers
class Erubis < TemplateHandler
include Compilable
# Erubis engine class
cattr_accessor :engine_class
@@engine_class = ::Erubis::Eruby
# Properties
cattr_accessor :init_properties
@@init_properties = {}
# Enable preprocessing if true
cattr_accessor :preprocessing
@@preprocessing = false
def compile(template)
if preprocessing
preprocessor = ::Erubis::PreprocessingEruby.new(template, init_properties)
template = preprocessor.evaluate(@view)
end
engine_class.new(template, init_properties).src
end
end
end
end
ActionView::Template.register_default_template_handler :erb, ActionView::TemplateHandlers::Erubis
ActionView::Template.register_template_handler :rhtml, ActionView::TemplateHandlers::Erubis
2. Configure settings of Erubis in enviroment.rb.
Append below scripts in config/enviroment.rbrequire 'erubis_rails_helper'Restart the web server.
ActionView::TemplateHandlers::Erubis.engine_class = Erubis::FastEruby
ActionView::TemplateHandlers::Erubis.preprocessing = true
5 comments:
I'm a little confused why someone would want to use Erubis with Rails. I suppose it's somewhat more customizable than ERB, but unless you really need those customizations it seems like more hassle than it's worth.
Rendering speed is often pointed to as a reason, but Erubis is only faster than ERB at compiling the template. Since Rails will cache compiled templates, you don't get any speed boost.
Rails caching mechanism is powerful and useful, so Erubis is not needed with Rails.
What kind of problem will occur when use Erubis with Rails?
On Rails 2.0.2, I got it to work by getting rid of "include Compilable", and changing "ActionView::Template" to "ActionView::Base"
nevermind my previous comment, looks like erubis 2.6.0 supports rails already 2.0.2
Services usually buy my games. But every time I go http://www.ygscn.net Because every time they did not disappoint me, for me to provide excellent service. Therefore, I hope that everyone can go take a look at their Warhammer Online Power Leveling and Warhammer Online Gold. They have many excellent Game Games gold and technology. At the same time, the form of the face of the economic benefits they introduce more and more every player fit for wow power leveling and wow gold service. also Service there is more to choose from: AOC Gold, SilkRoad Online gold, SWG credits, WAR Power leveling, EQ2 gold.
Post a Comment