Creates a hook that allows you to make changes to a template once after it's rendered.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



You can use this plugin to post-process Rails templates (originally 
worked for 1.2.6; it's now updated for Rails 2 and only tested with Rails 
2.1.1) have been rendered. This has not been thoroughly tested ... it 
works well enough for me at the moment.

You can use AfterRender in two ways. Either you can write your own code
that you want to apply after rendering, or you can use the default. If
you want the default (which adds comments to generated HTML showing which
template you're in, as well as showing locals), then set
AFTER_RENDER=true in the proper environment file (e.g. at the bottom of
development.rb). Otherwise, you can set AFTER_RENDER equal to a proc or a
lambda, like so:

AFTER_RENDER = lambda { | h |  
   "<!-- code generated by: #{h[:template_path]} -->\n" + 
   rendered_template +
   "<!-- end of code generated by: #{h[:template_path} -->\n"

Here's the full list of values in the Hash that's passed to AFTER_RENDER:

:template_path        => The path to the template being rendered.
:locals               => The locals passed to the template, including the
                         the one passed as :object.
:rendered_template    => The HTML generated after rendering the template.
:parent_template_path => The path to the template that this one is nested 
                         in, if applicable.

:parent_template_path is a guess based on the call stack. It just looks 
for the first thing in app/views that was called before the current 
template being rendered.

Tested on Rails 2.1.1 only.