1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Jeremy Kemper 2006-11-20 09:04:26 +00:00
parent 19c99acfbc
commit d41f380a2c
3 changed files with 48 additions and 5 deletions

View file

@ -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 file

@ -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)

View file

@ -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)