Skip to content

Commit

Permalink
Seperate asset directories
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Mar 30, 2011
1 parent 651d371 commit 77d8f7a
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
4 changes: 3 additions & 1 deletion actionpack/lib/action_view/helpers/sprockets_helper.rb
Expand Up @@ -48,7 +48,9 @@ def compute_sprockets_path(source, dir, default_ext)
end

# Fingerprint url
source = assets.path(source, config.perform_caching)
if source =~ /^\/#{dir}\/(.+)/
source = assets.path($1, config.perform_caching, dir)
end

host = compute_asset_host(source)

Expand Down
33 changes: 18 additions & 15 deletions actionpack/test/template/sprockets_helper_test.rb
Expand Up @@ -20,20 +20,23 @@ def host_with_port() 'localhost' end
@controller.request = @request

@assets = Sprockets::Environment.new
@assets.paths << FIXTURES.join("sprockets/app/assets")
@assets.paths << FIXTURES.join("sprockets/app/javascripts")
@assets.paths << FIXTURES.join("sprockets/app/stylesheets")

config.perform_caching = true
end

def url_for(*args)
"http://www.example.com"
end

test "javascript path" do
assert_equal "/javascripts/application-d41d8cd98f00b204e9800998ecf8427e.js",
assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js",
sprockets_javascript_path(:application)

assert_equal "/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
assert_equal "/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
sprockets_javascript_path("xmlhr")
assert_equal "/javascripts/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
assert_equal "/assets/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
sprockets_javascript_path("dir/xmlhr.js")

assert_equal "/dir/xmlhr.js",
Expand All @@ -46,24 +49,24 @@ def url_for(*args)
end

test "javascript include tag" do
assert_equal '<script src="/javascripts/application-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
assert_equal '<script src="/assets/application-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
sprockets_javascript_include_tag(:application)

assert_equal '<script src="/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
sprockets_javascript_include_tag("xmlhr")
assert_equal '<script src="/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
sprockets_javascript_include_tag("xmlhr.js")
assert_equal '<script src="http://www.railsapplication.com/xmlhr" type="text/javascript"></script>',
sprockets_javascript_include_tag("http://www.railsapplication.com/xmlhr")
end

test "stylesheet path" do
assert_equal "/stylesheets/application-d41d8cd98f00b204e9800998ecf8427e.css",
assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css",
sprockets_stylesheet_path(:application)

assert_equal "/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css",
assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css",
sprockets_stylesheet_path("style")
assert_equal "/stylesheets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css",
assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css",
sprockets_stylesheet_path("dir/style.css")
assert_equal "/dir/style.css",
sprockets_stylesheet_path("/dir/style.css")
Expand All @@ -75,19 +78,19 @@ def url_for(*args)
end

test "stylesheet link tag" do
assert_equal '<link href="/stylesheets/application-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
assert_equal '<link href="/assets/application-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
sprockets_stylesheet_link_tag(:application)

assert_equal '<link href="/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
sprockets_stylesheet_link_tag("style")
assert_equal '<link href="/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
sprockets_stylesheet_link_tag("style.css")

assert_equal '<link href="http://www.railsapplication.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css")
assert_equal '<link href="/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />',
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />',
sprockets_stylesheet_link_tag("style", :media => "all")
assert_equal '<link href="/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />',
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />',
sprockets_stylesheet_link_tag("style", :media => "print")
end
end

0 comments on commit 77d8f7a

Please sign in to comment.