2013-04-20 23:33:18 +02:00
|
|
|
# Relative Assets extension
|
|
|
|
class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
|
|
|
def initialize(app, options_hash={}, &block)
|
|
|
|
super
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2013-04-20 23:33:18 +02:00
|
|
|
# After compass is setup, make it use the registered cache buster
|
|
|
|
app.compass_config do |config|
|
|
|
|
config.relative_assets = true
|
2013-05-08 20:37:55 +02:00
|
|
|
end if app.respond_to?(:compass_config)
|
2013-04-20 23:33:18 +02:00
|
|
|
end
|
2011-11-21 09:23:16 +01:00
|
|
|
|
2013-04-20 23:33:18 +02:00
|
|
|
helpers do
|
|
|
|
# asset_url override for relative assets
|
|
|
|
# @param [String] path
|
|
|
|
# @param [String] prefix
|
|
|
|
# @return [String]
|
2013-12-28 01:26:31 +01:00
|
|
|
def asset_url(path, prefix='')
|
2013-04-20 23:33:18 +02:00
|
|
|
path = super(path, prefix)
|
|
|
|
|
2013-06-16 01:22:14 +02:00
|
|
|
if path.include?('//') || path.start_with?('data:') || !current_resource
|
2013-04-20 23:33:18 +02:00
|
|
|
path
|
|
|
|
else
|
|
|
|
current_dir = Pathname('/' + current_resource.destination_path)
|
|
|
|
Pathname(path).relative_path_from(current_dir.dirname).to_s
|
2011-11-21 09:23:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-05-01 06:50:31 +02:00
|
|
|
end
|