From 89237fe07e9c6d35687b3a473f09f4608a3625d8 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Sat, 12 Apr 2008 18:43:38 -0500 Subject: [PATCH] Scripts and styles with multiple dots in the filename should cache --- .../lib/action_view/helpers/asset_tag_helper.rb | 6 +++--- .../fixtures/public/javascripts/version.1.0.js | 1 + .../fixtures/public/stylesheets/version.1.0.css | 1 + .../test/template/asset_tag_helper_test.rb | 16 ++++++++-------- 4 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 actionpack/test/fixtures/public/javascripts/version.1.0.js create mode 100644 actionpack/test/fixtures/public/stylesheets/version.1.0.css diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index d57d1e0903e9a..472bd1ae3e387 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -474,7 +474,7 @@ def compute_public_path(source, dir, ext = nil, include_host = true) ActionView::Base.computed_public_paths[cache_key] ||= begin - source += ".#{ext}" if File.extname(source).blank? && ext + source += ".#{ext}" if ext && File.extname(source).blank? || File.exist?(File.join(ASSETS_DIR, dir, "#{source}.#{ext}")) if source =~ %r{^[-a-z]+://} source @@ -566,7 +566,7 @@ def compute_stylesheet_paths(sources) def expand_javascript_sources(sources) if sources.include?(:all) - all_javascript_files = Dir[File.join(JAVASCRIPTS_DIR, '*.js')].collect { |file| File.basename(file).split(".", 0).first }.sort + all_javascript_files = Dir[File.join(JAVASCRIPTS_DIR, '*.js')].collect { |file| File.basename(file).gsub(/\.\w+$/, '') }.sort @@all_javascript_sources ||= ((determine_source(:defaults, @@javascript_expansions).dup & all_javascript_files) + all_javascript_files).uniq else expanded_sources = sources.collect do |source| @@ -579,7 +579,7 @@ def expand_javascript_sources(sources) def expand_stylesheet_sources(sources) if sources.first == :all - @@all_stylesheet_sources ||= Dir[File.join(STYLESHEETS_DIR, '*.css')].collect { |file| File.basename(file).split(".", 0).first }.sort + @@all_stylesheet_sources ||= Dir[File.join(STYLESHEETS_DIR, '*.css')].collect { |file| File.basename(file).gsub(/\.\w+$/, '') }.sort else sources.collect do |source| determine_source(source, @@stylesheet_expansions) diff --git a/actionpack/test/fixtures/public/javascripts/version.1.0.js b/actionpack/test/fixtures/public/javascripts/version.1.0.js new file mode 100644 index 0000000000000..cfd5fce70e02d --- /dev/null +++ b/actionpack/test/fixtures/public/javascripts/version.1.0.js @@ -0,0 +1 @@ +// version.1.0 js \ No newline at end of file diff --git a/actionpack/test/fixtures/public/stylesheets/version.1.0.css b/actionpack/test/fixtures/public/stylesheets/version.1.0.css new file mode 100644 index 0000000000000..30f5f9ba6ee9a --- /dev/null +++ b/actionpack/test/fixtures/public/stylesheets/version.1.0.css @@ -0,0 +1 @@ +/* version.1.0.css */ \ No newline at end of file diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index be605329fc9c1..ffb8856a5947c 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -84,7 +84,7 @@ def teardown %(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(), %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(\n), %(javascript_include_tag(:defaults)) => %(\n\n\n\n), - %(javascript_include_tag(:all)) => %(\n\n\n\n\n\n), + %(javascript_include_tag(:all)) => %(\n\n\n\n\n\n\n), %(javascript_include_tag(:defaults, "test")) => %(\n\n\n\n\n), %(javascript_include_tag("test", :defaults)) => %(\n\n\n\n\n) } @@ -109,8 +109,8 @@ def teardown %(stylesheet_link_tag("/dir/file")) => %(), %(stylesheet_link_tag("dir/file")) => %(), %(stylesheet_link_tag("style", :media => "all")) => %(), - %(stylesheet_link_tag(:all)) => %(\n), - %(stylesheet_link_tag(:all, :media => "all")) => %(\n), + %(stylesheet_link_tag(:all)) => %(\n\n), + %(stylesheet_link_tag(:all, :media => "all")) => %(\n\n), %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(\n), %(stylesheet_link_tag("http://www.example.com/styles/style")) => %() } @@ -358,7 +358,7 @@ def test_caching_javascript_include_tag_with_all_puts_defaults_at_the_start_of_t assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js')) assert_equal( - %(// prototype js\n\n// effects js\n\n// dragdrop js\n\n// controls js\n\n// application js\n\n// bank js\n\n// robber js), + %(// prototype js\n\n// effects js\n\n// dragdrop js\n\n// controls js\n\n// application js\n\n// bank js\n\n// robber js\n\n// version.1.0 js), IO.read(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js')) ) @@ -371,14 +371,14 @@ def test_caching_javascript_include_tag_when_caching_off ActionController::Base.perform_caching = false assert_dom_equal( - %(\n\n\n\n\n\n), + %(\n\n\n\n\n\n\n), javascript_include_tag(:all, :cache => true) ) assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) assert_dom_equal( - %(\n\n\n\n\n\n), + %(\n\n\n\n\n\n\n), javascript_include_tag(:all, :cache => "money") ) @@ -430,14 +430,14 @@ def test_caching_stylesheet_include_tag_when_caching_off ActionController::Base.perform_caching = false assert_dom_equal( - %(\n), + %(\n\n), stylesheet_link_tag(:all, :cache => true) ) assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) assert_dom_equal( - %(\n), + %(\n\n), stylesheet_link_tag(:all, :cache => "money") )