aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG13
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb21
-rw-r--r--actionpack/test/fixtures/public/images/rails.pngbin0 -> 1787 bytes
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb16
4 files changed, 45 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 82294a9299..7b3b44f7cb 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,3 +1,16 @@
+*SVN*
+
+* Added automated timestamping to AssetTagHelper methods for stylesheets, javascripts, and images when Action Controller is run under Rails [DHH]. Example:
+
+ image_tag("rails.png") # => '<img alt="Rails" src="/images/rails.png?1143664135" />'
+
+ ...to avoid frequent stats (not a problem for most people), you can set RAILS_ASSET_ID in the ENV to avoid stats:
+
+ ENV["RAILS_ASSET_ID"] = "2345"
+ image_tag("rails.png") # => '<img alt="Rails" src="/images/rails.png?2345" />'
+
+ This can be used by deployment managers to set the asset id by application revision
+
*1.12.0* (March 27th, 2005)
* Add documentation for respond_to. [Jamis Buck]
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index f05d9a096b..de44ef6531 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -59,11 +59,16 @@ module ActionView
# <tt>controllers/application.rb</tt> and <tt>helpers/application_helper.rb</tt>.
def javascript_include_tag(*sources)
options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
+
if sources.include?(:defaults)
- sources = sources[0..(sources.index(:defaults))] + @@javascript_default_sources.dup + sources[(sources.index(:defaults) + 1)..sources.length]
+ sources = sources[0..(sources.index(:defaults))] +
+ @@javascript_default_sources.dup +
+ sources[(sources.index(:defaults) + 1)..sources.length]
+
sources.delete(:defaults)
- sources << "application" if defined?(RAILS_ROOT) and File.exists?("#{RAILS_ROOT}/public/javascripts/application.js")
+ sources << "application" if defined?(RAILS_ROOT) && File.exists?("#{RAILS_ROOT}/public/javascripts/application.js")
end
+
sources.collect { |source|
source = javascript_path(source)
content_tag("script", "", { "type" => "text/javascript", "src" => source }.merge(options))
@@ -145,12 +150,18 @@ module ActionView
private
def compute_public_path(source, dir, ext)
- source = "/#{dir}/#{source}" unless source.first == "/" || source.include?(":")
- source = "#{source}.#{ext}" unless source.split("/").last.include?(".")
- source = "#{@controller.request.relative_url_root}#{source}" unless %r{^[-a-z]+://} =~ source
+ source = "/#{dir}/#{source}" unless source.first == "/" || source.include?(":")
+ source << ".#{ext}" unless source.split("/").last.include?(".")
+ source << '?' + rails_asset_id(source) if defined?(RAILS_ROOT)
+ source = "#{@controller.request.relative_url_root}#{source}" unless %r{^[-a-z]+://} =~ source
source = ActionController::Base.asset_host + source unless source.include?(":")
source
end
+
+ def rails_asset_id(source)
+ ENV["RAILS_ASSET_ID"] ||
+ File.stat(RAILS_ROOT + "/public/#{source}").mtime.to_i.to_s
+ end
end
end
end
diff --git a/actionpack/test/fixtures/public/images/rails.png b/actionpack/test/fixtures/public/images/rails.png
new file mode 100644
index 0000000000..b8441f182e
--- /dev/null
+++ b/actionpack/test/fixtures/public/images/rails.png
Binary files differ
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index bc7e3e0f7a..b3e062f4c8 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -27,6 +27,11 @@ class AssetTagHelperTest < Test::Unit::TestCase
ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
end
+ def teardown
+ Object.send(:remove_const, :RAILS_ROOT) if defined?(RAILS_ROOT)
+ ENV["RAILS_ASSET_ID"] = nil
+ end
+
AutoDiscoveryToTag = {
%(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
@@ -115,6 +120,17 @@ class AssetTagHelperTest < Test::Unit::TestCase
ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
+ def test_timebased_asset_id
+ Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
+ expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s
+ assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
+ end
+
+ def test_preset_asset_id
+ Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
+ ENV["RAILS_ASSET_ID"] = "4500"
+ assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png")
+ end
end
class AssetTagHelperNonVhostTest < Test::Unit::TestCase