Add options hash to asset methods to allow special options to be passed through from extensions
This commit is contained in:
parent
1c37cc6a34
commit
6d2f8cd50c
2
Gemfile
2
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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue