Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract template_changed_since? from compile_template? so plugins may…

… override its behavior for non-file-based templates. Closes #6651.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5587 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit d41f380a2c7c7926ce89ee2bcef8093d1fd59036 1 parent 19c99ac
@jeremy jeremy authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Extract template_changed_since? from compile_template? so plugins may override its behavior for non-file-based templates. #6651 [Jeff Barczewski]
+
* Update to Prototype and script.aculo.us [5579]. [Thomas Fuchs]
* simple_format helper doesn't choke on nil. #6644 [jerry426]
View
14 actionpack/lib/action_view/base.rb
@@ -432,21 +432,27 @@ def supports_local_assigns?(render_symbol, local_assigns)
# Check whether compilation is necessary.
# Compile if the inline template or file has not been compiled yet.
# Or if local_assigns has a new key, which isn't supported by the compiled code yet.
- # Or if the file has changed on disk and checking file mods hasn't been disabled.
+ # Or if the file has changed on disk and checking file mods hasn't been disabled.
def compile_template?(template, file_name, local_assigns)
method_key = file_name || template
render_symbol = @@method_names[method_key]
if @@compile_time[render_symbol] && supports_local_assigns?(render_symbol, local_assigns)
- if file_name && !@@cache_template_loading
- @@compile_time[render_symbol] < File.mtime(file_name) ||
- (File.symlink?(file_name) && (@@compile_time[render_symbol] < File.lstat(file_name).mtime))
+ if file_name && !@@cache_template_loading
+ template_changed_since?(file_name, @@compile_time[render_symbol])
end
else
true
end
end
+ # handles checking if template changed since last compile, isolated so that templates
+ # not stored on the file system can hook and extend appropriately
+ def template_changed_since?(file_name, compile_time)
+ compile_time < File.mtime(file_name) ||
+ (File.symlink?(file_name) && (compile_time < File.lstat(file_name).mtime))
+ end
+
# Create source code for given template
def create_template_source(extension, template, render_symbol, locals)
if template_requires_setup?(extension)
View
37 actionpack/test/template/compiled_templates_test.rb
@@ -71,14 +71,24 @@ def test_mtime
end
def test_compile_time
+ t = Time.now
+ sleep 1
`echo '#{@a}' > #{@a}; echo '#{@b}' > #{@b}; ln -s #{@a} #{@s}`
v = ActionView::Base.new
v.base_path = '.'
v.cache_template_loading = false;
+ # private methods template_changed_since? and compile_template?
+ # should report true for all since they have not been compiled
+ assert v.send(:template_changed_since?, @a, t)
+ assert v.send(:template_changed_since?, @b, t)
+ assert v.send(:template_changed_since?, @s, t)
+ assert v.send(:compile_template?, nil, @a, {})
+ assert v.send(:compile_template?, nil, @b, {})
+ assert v.send(:compile_template?, nil, @s, {})
+
sleep 1
- t = Time.now
v.compile_and_render_template(:rhtml, '', @a)
v.compile_and_render_template(:rhtml, '', @b)
v.compile_and_render_template(:rhtml, '', @s)
@@ -92,6 +102,14 @@ def test_compile_time
sleep 1
t = Time.now
+ # private methods template_changed_since? and compile_template?
+ # should report false for all since none have changed since compile
+ assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
+ assert !v.send(:template_changed_since?, @b, v.compile_time[b_n])
+ assert !v.send(:template_changed_since?, @s, v.compile_time[s_n])
+ assert !v.send(:compile_template?, nil, @a, {})
+ assert !v.send(:compile_template?, nil, @b, {})
+ assert !v.send(:compile_template?, nil, @s, {})
v.compile_and_render_template(:rhtml, '', @a)
v.compile_and_render_template(:rhtml, '', @b)
v.compile_and_render_template(:rhtml, '', @s)
@@ -101,6 +119,14 @@ def test_compile_time
assert v.compile_time[s_n] < t
`rm #{@s}; ln -s #{@b} #{@s}`
+ # private methods template_changed_since? and compile_template?
+ # should report true for symlink since it has changed since compile
+ assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
+ assert !v.send(:template_changed_since?, @b, v.compile_time[b_n])
+ assert v.send(:template_changed_since?, @s, v.compile_time[s_n])
+ assert !v.send(:compile_template?, nil, @a, {})
+ assert !v.send(:compile_template?, nil, @b, {})
+ assert v.send(:compile_template?, nil, @s, {})
v.compile_and_render_template(:rhtml, '', @a)
v.compile_and_render_template(:rhtml, '', @b)
v.compile_and_render_template(:rhtml, '', @s)
@@ -111,6 +137,15 @@ def test_compile_time
sleep 1
`touch #{@b}`
+ # private methods template_changed_since? and compile_template?
+ # should report true for symlink and file at end of symlink
+ # since it has changed since last compile
+ assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
+ assert v.send(:template_changed_since?, @b, v.compile_time[b_n])
+ assert v.send(:template_changed_since?, @s, v.compile_time[s_n])
+ assert !v.send(:compile_template?, nil, @a, {})
+ assert v.send(:compile_template?, nil, @b, {})
+ assert v.send(:compile_template?, nil, @s, {})
t = Time.now
v.compile_and_render_template(:rhtml, '', @a)
v.compile_and_render_template(:rhtml, '', @b)
Please sign in to comment.
Something went wrong with that request. Please try again.