Skip to content

Commit

Permalink
🔥 Rails asset id support
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Oct 15, 2012
1 parent 511382b commit 3db6990
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 246 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/abstract_controller/asset_paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module AssetPaths #:nodoc:
extend ActiveSupport::Concern

included do
config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir,
config_accessor :asset_host, :assets_dir, :javascripts_dir,
:stylesheets_dir, :default_asset_host_protocol, :relative_url_root
end
end
Expand Down
1 change: 0 additions & 1 deletion actionpack/lib/action_controller/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Railtie < Rails::Railtie #:nodoc:
options.stylesheets_dir ||= paths["public/stylesheets"].first

# Ensure readers methods get compiled
options.asset_path ||= app.config.asset_path
options.asset_host ||= app.config.asset_host
options.relative_url_root ||= app.config.relative_url_root

Expand Down
1 change: 0 additions & 1 deletion actionpack/lib/action_view/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Helpers #:nodoc:
extend ActiveSupport::Autoload

autoload :ActiveModelHelper
autoload :AssetIdHelper
autoload :AssetTagHelper
autoload :AssetUrlHelper
autoload :AtomFeedHelper
Expand Down
154 changes: 0 additions & 154 deletions actionpack/lib/action_view/helpers/asset_id_helper.rb

This file was deleted.

1 change: 0 additions & 1 deletion actionpack/lib/action_view/helpers/asset_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module AssetTagHelper
extend ActiveSupport::Concern

include AssetUrlHelper
include AssetIdHelper
include TagHelper

# Returns an HTML script tag for each of the +sources+ provided.
Expand Down
8 changes: 0 additions & 8 deletions actionpack/lib/action_view/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ class Railtie < Rails::Railtie
ActiveSupport.on_load(:action_view) { self.logger ||= Rails.logger }
end

initializer "action_view.cache_asset_ids" do |app|
unless app.config.cache_classes
ActiveSupport.on_load(:action_view) do
ActionView::Helpers::AssetIdHelper.cache_asset_ids = false
end
end
end

initializer "action_view.set_configs" do |app|
ActiveSupport.on_load(:action_view) do
app.config.action_view.each do |k,v|
Expand Down
81 changes: 1 addition & 80 deletions actionpack/test/template/asset_tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ def url_for(*args)
"http://www.example.com"
end

def teardown
ENV.delete('RAILS_ASSET_ID')
end

AssetPathToTag = {
%(asset_path("foo")) => %(/foo),
%(asset_path("style.css")) => %(/style.css),
Expand Down Expand Up @@ -291,7 +287,6 @@ def test_autodiscovery_link_tag_deprecated_types
end

def test_asset_path_tag
ENV["RAILS_ASSET_ID"] = ""
AssetPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end

Expand Down Expand Up @@ -323,8 +318,7 @@ def test_url_to_javascript_alias_for_javascript_url
UrlToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end

def test_javascript_include_tag_with_blank_asset_id
ENV["RAILS_ASSET_ID"] = ""
def test_javascript_include_tag
JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end

Expand All @@ -343,7 +337,6 @@ def test_javascript_include_tag_is_html_safe
end

def test_stylesheet_path
ENV["RAILS_ASSET_ID"] = ""
StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end

Expand All @@ -352,7 +345,6 @@ def test_path_to_stylesheet_alias_for_stylesheet_path
end

def test_stylesheet_url
ENV["RAILS_ASSET_ID"] = ""
StyleUrlToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end

Expand All @@ -361,7 +353,6 @@ def test_url_to_stylesheet_alias_for_stylesheet_url
end

def test_stylesheet_link_tag
ENV["RAILS_ASSET_ID"] = ""
StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end

Expand All @@ -376,7 +367,6 @@ def test_stylesheet_link_tag_with_missing_source
end

def test_stylesheet_link_tag_is_html_safe
ENV["RAILS_ASSET_ID"] = ""
assert stylesheet_link_tag('dir/file').html_safe?
assert stylesheet_link_tag('dir/other/file', 'dir/file2').html_safe?
end
Expand All @@ -386,7 +376,6 @@ def test_stylesheet_link_tag_escapes_options
end

def test_stylesheet_link_tag_should_not_output_the_same_asset_twice
ENV["RAILS_ASSET_ID"] = ""
assert_dom_equal %(<link href="/stylesheets/wellington.css" media="screen" rel="stylesheet" />\n<link href="/stylesheets/amsterdam.css" media="screen" rel="stylesheet" />), stylesheet_link_tag('wellington', 'wellington', 'amsterdam')
end

Expand Down Expand Up @@ -428,21 +417,6 @@ def test_favicon_link_tag
FaviconLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end

def test_image_tag_windows_behaviour
old_asset_id, ENV["RAILS_ASSET_ID"] = ENV["RAILS_ASSET_ID"], "1"
# This simulates the behavior of File#exist? on windows when testing a file ending in "."
# If the file "rails.png" exists, windows will return true when asked if "rails.png." exists (notice trailing ".")
# OS X, linux etc will return false in this case.
File.stubs(:exist?).with('template/../fixtures/public/images/rails.png.').returns(true)
assert_equal '<img alt="Rails" src="/images/rails.png?1" />', image_tag('rails.png')
ensure
if old_asset_id
ENV["RAILS_ASSET_ID"] = old_asset_id
else
ENV.delete("RAILS_ASSET_ID")
end
end

def test_video_path
VideoPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
Expand Down Expand Up @@ -491,27 +465,6 @@ def test_video_audio_tag_does_not_modify_options
assert_equal({:autoplay => true}, options)
end

def test_timebased_asset_id
expected_time = File.mtime(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).to_i.to_s
assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
end

def test_string_asset_id
@controller.config.asset_path = "/assets.v12345%s"

expected_path = "/assets.v12345/images/rails.png"
assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
end

def test_proc_asset_id
@controller.config.asset_path = Proc.new do |asset_path|
"/assets.v12345#{asset_path}"
end

expected_path = "/assets.v12345/images/rails.png"
assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
end

def test_image_tag_interpreting_email_cid_correctly
# An inline image has no need for an alt tag to be automatically generated from the cid:
assert_equal '<img src="cid:thi%25%25sis@acontentid" />', image_tag("cid:thi%25%25sis@acontentid")
Expand All @@ -521,37 +474,6 @@ def test_image_tag_interpreting_email_adding_optional_alt_tag
assert_equal '<img alt="Image" src="cid:thi%25%25sis@acontentid" />', image_tag("cid:thi%25%25sis@acontentid", :alt => "Image")
end

def test_timebased_asset_id_with_relative_url_root
@controller.config.relative_url_root = "/collaboration/hieraki"
expected_time = File.mtime(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).to_i.to_s
assert_equal %(<img alt="Rails" src="#{@controller.config.relative_url_root}/images/rails.png?#{expected_time}" />), image_tag("rails.png")
end

# Same as above, but with script_name
def test_timebased_asset_id_with_script_name
@request.script_name = "/collaboration/hieraki"
expected_time = File.mtime(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).to_i.to_s
assert_equal %(<img alt="Rails" src="#{@request.script_name}/images/rails.png?#{expected_time}" />), image_tag("rails.png")
end

def test_should_skip_asset_id_on_complete_url
assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png")
end

def test_should_skip_asset_id_on_scheme_relative_url
assert_equal %(<img alt="Rails" src="//www.example.com/rails.png" />), image_tag("//www.example.com/rails.png")
end

def test_should_use_preset_asset_id
ENV["RAILS_ASSET_ID"] = "4500"
assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png")
end

def test_preset_empty_asset_id
ENV["RAILS_ASSET_ID"] = ""
assert_equal %(<img alt="Rails" src="/images/rails.png" />), image_tag("rails.png")
end

def test_should_not_modify_source_string
source = '/images/rails.png'
copy = source.dup
Expand All @@ -560,7 +482,6 @@ def test_should_not_modify_source_string
end

def test_caching_image_path_with_caching_and_proc_asset_host_using_request
ENV['RAILS_ASSET_ID'] = ''
@controller.config.asset_host = Proc.new do |source, request|
if request.ssl?
"#{request.protocol}#{request.host_with_port}"
Expand Down

0 comments on commit 3db6990

Please sign in to comment.