aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/template.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-10-10 13:43:32 +0200
committerJosé Valim <jose.valim@gmail.com>2010-10-10 13:43:32 +0200
commit11aa5157355d06ddbc9cad8fd0aa43a75ac8431e (patch)
treee40196b0a9aad3113d5e248a171636576a98ec14 /actionpack/lib/action_view/template.rb
parentffa32714bd339ae32355a6827750e1af81454a1b (diff)
downloadrails-11aa5157355d06ddbc9cad8fd0aa43a75ac8431e.tar.gz
rails-11aa5157355d06ddbc9cad8fd0aa43a75ac8431e.tar.bz2
rails-11aa5157355d06ddbc9cad8fd0aa43a75ac8431e.zip
Add expire! and rerender to the template API. This will be used by SASS template handler.
Diffstat (limited to 'actionpack/lib/action_view/template.rb')
-rw-r--r--actionpack/lib/action_view/template.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index 074daa5d28..5c3e0e899b 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -154,13 +154,30 @@ module ActionView
# Notice this method raises an error if the template to be refreshed does not have a
# virtual path set (true just for inline templates).
def refresh(view)
- raise "A template need to have a virtual path in order to be refreshed" unless @virtual_path
+ raise "A template needs to have a virtual path in order to be refreshed" unless @virtual_path
lookup = view.lookup_context
pieces = @virtual_path.split("/")
name = pieces.pop
- partial = name.sub!(/^_/, "")
+ partial = !!name.sub!(/^_/, "")
lookup.disable_cache do
- lookup.find_template(name, pieces.join, partial || false, @locals)
+ lookup.find_template(name, pieces.join, partial, @locals)
+ end
+ end
+
+ # Expires this template by setting his updated_at date to Jan 1st, 1970.
+ def expire!
+ @updated_at = Time.utc(1970)
+ end
+
+ # Receives a view context and renders a template exactly like self by using
+ # the @virtual_path. It raises an error if no @virtual_path was given.
+ def rerender(view)
+ raise "A template needs to have a virtual path in order to be rerendered" unless @virtual_path
+ name = @virtual_path.dup
+ if name.sub!(/(^|\/)_([^\/]*)$/, '\1\2')
+ view.render :partial => name
+ else
+ view.render :template => @virtual_path
end
end