From 15d6210df85560cca00df520811de25f9b79392a Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sun, 20 Jul 2014 13:53:05 -0700 Subject: [PATCH] Use the resource instead of the request path for auto asset helpers. Fixes #1326 --- .../features/helpers_auto_javascript_include_tag.feature | 5 +++++ .../fixtures/auto-js-directory-index-app/config.rb | 1 + .../auto-js-directory-index-app/source/auto-js.html.erb | 1 + .../source/javascripts/auto-js.js | 1 + .../lib/middleman-more/core_extensions/default_helpers.rb | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 middleman-core/fixtures/auto-js-directory-index-app/config.rb create mode 100755 middleman-core/fixtures/auto-js-directory-index-app/source/auto-js.html.erb create mode 100644 middleman-core/fixtures/auto-js-directory-index-app/source/javascripts/auto-js.js diff --git a/middleman-core/features/helpers_auto_javascript_include_tag.feature b/middleman-core/features/helpers_auto_javascript_include_tag.feature index 4407ea72..ffcf7df5 100644 --- a/middleman-core/features/helpers_auto_javascript_include_tag.feature +++ b/middleman-core/features/helpers_auto_javascript_include_tag.feature @@ -6,6 +6,11 @@ Feature: Built-in auto_javascript_include_tag view helper When I go to "/auto-js.html" Then I should see "javascripts/auto-js.js" + Scenario: Viewing the root path (directory index) + Given the Server is running at "auto-js-directory-index-app" + When I go to "/auto-js/index.html" + Then I should see "javascripts/auto-js.js" + Scenario: Viewing the root path (build mode) Given a successfully built app at "auto-js-app" When I cd to "build" diff --git a/middleman-core/fixtures/auto-js-directory-index-app/config.rb b/middleman-core/fixtures/auto-js-directory-index-app/config.rb new file mode 100644 index 00000000..f343b291 --- /dev/null +++ b/middleman-core/fixtures/auto-js-directory-index-app/config.rb @@ -0,0 +1 @@ +activate :directory_indexes \ No newline at end of file diff --git a/middleman-core/fixtures/auto-js-directory-index-app/source/auto-js.html.erb b/middleman-core/fixtures/auto-js-directory-index-app/source/auto-js.html.erb new file mode 100755 index 00000000..7af247d9 --- /dev/null +++ b/middleman-core/fixtures/auto-js-directory-index-app/source/auto-js.html.erb @@ -0,0 +1 @@ +<%= auto_javascript_include_tag %> \ No newline at end of file diff --git a/middleman-core/fixtures/auto-js-directory-index-app/source/javascripts/auto-js.js b/middleman-core/fixtures/auto-js-directory-index-app/source/javascripts/auto-js.js new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/middleman-core/fixtures/auto-js-directory-index-app/source/javascripts/auto-js.js @@ -0,0 +1 @@ + diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index 4b60bb65..91ade628 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -118,7 +118,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension # If the basename of the request as no extension, assume we are serving a # directory and join index_file to the path. - path = File.join(asset_dir, current_path) + path = File.join(asset_dir, current_resource.path) path = path.sub(/#{Regexp.escape(File.extname(path))}$/, ".#{asset_ext}") yield path if sitemap.find_resource_by_path(path)