diff --git a/Gemfile b/Gemfile index e930dc7c..27c59bf3 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gem 'yard', '~> 0.8.0', require: false # Test tools gem 'cucumber', '~> 1.3.1' -gem 'fivemat' +gem 'fivemat', '~> 1.2.1' gem 'aruba', '~> 0.5.1' gem 'rspec', '~> 2.12' gem 'simplecov' diff --git a/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb index 1e76674f..14466f25 100644 --- a/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb @@ -167,8 +167,9 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension # # @param [Symbol] kind The type of file # @param [String] source The path to the file + # @param [Hash] options Data to pass through. # @return [String] - def asset_path(kind, source) + def asset_path(kind, source, options={}) return source if source.to_s.include?('//') || source.to_s.start_with?('data:') asset_folder = case kind when :css then config[:css_dir] @@ -182,15 +183,16 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension source << ".#{kind}" unless ignore_extension || source.end_with?(".#{kind}") asset_folder = '' if source.start_with?('/') # absolute path - asset_url(source, asset_folder) + asset_url(source, asset_folder, options) end # Get the URL of an asset given a type/prefix # # @param [String] path The path (such as "photo.jpg") # @param [String] prefix The type prefix (such as "images") + # @param [Hash] options Data to pass through. # @return [String] The fully qualified asset url - def asset_url(path, prefix='') + def asset_url(path, prefix='', options={}) # Don't touch assets which already have a full path if path.include?('//') or path.start_with?('data:') path diff --git a/middleman-core/lib/middleman-core/extensions/asset_host.rb b/middleman-core/lib/middleman-core/extensions/asset_host.rb index 89cc49d6..b73f74bc 100644 --- a/middleman-core/lib/middleman-core/extensions/asset_host.rb +++ b/middleman-core/lib/middleman-core/extensions/asset_host.rb @@ -31,8 +31,9 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension # # @param [String] path # @param [String] prefix + # @param [Hash] options Data to pass through. # @return [String] - def asset_url(path, prefix='') + def asset_url(path, prefix='', options={}) controller = extensions[:asset_host] original_output = super diff --git a/middleman-core/lib/middleman-core/extensions/cache_buster.rb b/middleman-core/lib/middleman-core/extensions/cache_buster.rb index 8d1788ce..44652888 100644 --- a/middleman-core/lib/middleman-core/extensions/cache_buster.rb +++ b/middleman-core/lib/middleman-core/extensions/cache_buster.rb @@ -22,7 +22,8 @@ class Middleman::Extensions::CacheBuster < ::Middleman::Extension # asset_url override if we're using cache busting # @param [String] path # @param [String] prefix - def asset_url(path, prefix='') + # @param [Hash] options Data to pass through. + def asset_url(path, prefix='', options={}) http_path = super if http_path.include?('://') || !%w(.css .png .jpg .jpeg .svg .svgz .js .gif).include?(File.extname(http_path)) diff --git a/middleman-core/lib/middleman-core/extensions/relative_assets.rb b/middleman-core/lib/middleman-core/extensions/relative_assets.rb index 3e67d59d..61e54881 100644 --- a/middleman-core/lib/middleman-core/extensions/relative_assets.rb +++ b/middleman-core/lib/middleman-core/extensions/relative_assets.rb @@ -14,14 +14,17 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension # asset_url override for relative assets # @param [String] path # @param [String] prefix + # @param [Hash] options Data to pass through. # @return [String] - def asset_url(path, prefix='') - path = super(path, prefix) + def asset_url(path, prefix='', options={}) + path = super - if path.include?('//') || path.start_with?('data:') || !current_resource + requested_resource = options[:current_resource] || current_resource + + if path.include?('//') || path.start_with?('data:') || !requested_resource path else - current_dir = Pathname('/' + current_resource.destination_path) + current_dir = Pathname('/' + requested_resource.destination_path) Pathname(path).relative_path_from(current_dir.dirname).to_s end end