-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
36 lines (29 loc) · 1.52 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
AfterRender
===========
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.