2011-12-31 23:28:17 +01:00
|
|
|
# Extension namespace
|
2012-04-27 00:59:28 +02:00
|
|
|
module Middleman
|
|
|
|
module Extensions
|
2011-12-31 23:28:17 +01:00
|
|
|
|
2012-04-27 00:59:28 +02:00
|
|
|
# Relative Assets extension
|
|
|
|
module RelativeAssets
|
2011-12-31 23:28:17 +01:00
|
|
|
|
2012-04-27 00:59:28 +02:00
|
|
|
# Setup extension
|
|
|
|
class << self
|
2011-12-31 23:28:17 +01:00
|
|
|
|
2012-04-27 00:59:28 +02:00
|
|
|
# Once registered
|
|
|
|
def registered(app)
|
|
|
|
# Tell compass to use relative assets
|
|
|
|
app.compass_config do |config|
|
|
|
|
config.relative_assets = true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Include instance methods
|
|
|
|
app.send :include, InstanceMethods
|
2011-11-21 09:23:16 +01:00
|
|
|
end
|
|
|
|
|
2012-04-27 00:59:28 +02:00
|
|
|
alias :included :registered
|
2011-11-21 09:23:16 +01:00
|
|
|
end
|
|
|
|
|
2012-04-27 00:59:28 +02:00
|
|
|
# Relative Assets instance method
|
|
|
|
module InstanceMethods
|
2011-12-31 23:28:17 +01:00
|
|
|
|
2012-04-27 00:59:28 +02:00
|
|
|
# asset_url override for relative assets
|
|
|
|
# @param [String] path
|
|
|
|
# @param [String] prefix
|
|
|
|
# @return [String]
|
|
|
|
def asset_url(path, prefix="")
|
2012-07-01 07:02:23 +02:00
|
|
|
path = super(path, prefix)
|
2011-11-21 09:23:16 +01:00
|
|
|
|
2012-07-01 07:02:23 +02:00
|
|
|
if path.include?("//")
|
2011-11-21 09:23:16 +01:00
|
|
|
path
|
2012-04-27 00:59:28 +02:00
|
|
|
else
|
2012-07-01 07:02:23 +02:00
|
|
|
current_dir = Pathname('/' + current_resource.destination_path).dirname
|
|
|
|
Pathname(path).relative_path_from(current_dir)
|
2011-11-21 09:23:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-05-01 06:50:31 +02:00
|
|
|
end
|