aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-11-20 09:04:26 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-11-20 09:04:26 +0000
commitd41f380a2c7c7926ce89ee2bcef8093d1fd59036 (patch)
treec5fdfc4ef646b81e7b9a840edf9b11451b4e425f
parent19c99acfbc26c5fad02d968f37a958b1cbfa617b (diff)
downloadrails-d41f380a2c7c7926ce89ee2bcef8093d1fd59036.tar.gz
rails-d41f380a2c7c7926ce89ee2bcef8093d1fd59036.tar.bz2
rails-d41f380a2c7c7926ce89ee2bcef8093d1fd59036.zip
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
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/base.rb14
-rw-r--r--actionpack/test/template/compiled_templates_test.rb37
3 files changed, 48 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 1d270e39e6..506ad30822 100644
--- a/actionpack/CHANGELOG
+++ b/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]
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index efd2824236..dfe421c312 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -432,21 +432,27 @@ module ActionView #:nodoc:
# 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)
diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb
index e46543d645..a64ae95743 100644
--- a/actionpack/test/template/compiled_templates_test.rb
+++ b/actionpack/test/template/compiled_templates_test.rb
@@ -71,14 +71,24 @@ class CompiledTemplateTests < Test::Unit::TestCase
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 @@ class CompiledTemplateTests < Test::Unit::TestCase
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 @@ class CompiledTemplateTests < Test::Unit::TestCase
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 @@ class CompiledTemplateTests < Test::Unit::TestCase
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)