2010-09-06 21:48:25 -04:00
|
|
|
module Middleman::Features::RelativeAssets
|
|
|
|
class << self
|
|
|
|
def registered(app)
|
|
|
|
::Compass.configuration.relative_assets = true
|
2010-09-04 23:26:48 -04:00
|
|
|
|
2011-07-06 13:40:17 -04:00
|
|
|
app.register_asset_handler :relative_assets do |path, prefix, request|
|
2010-09-06 21:48:25 -04:00
|
|
|
begin
|
2011-07-06 13:40:17 -04:00
|
|
|
prefix = app.images_dir if prefix == app.http_images_path
|
2010-09-06 21:48:25 -04:00
|
|
|
rescue
|
|
|
|
end
|
|
|
|
|
|
|
|
if path.include?("://")
|
2011-07-06 13:40:17 -04:00
|
|
|
app.before_asset_handler(:relative_assets, path, prefix, request)
|
2010-09-06 21:48:25 -04:00
|
|
|
elsif path[0,1] == "/"
|
2010-09-04 23:26:48 -04:00
|
|
|
path
|
2010-09-06 21:48:25 -04:00
|
|
|
else
|
|
|
|
path = File.join(prefix, path) if prefix.length > 0
|
|
|
|
request_path = request.path_info.dup
|
2011-07-06 13:40:17 -04:00
|
|
|
request_path << app.index_file if path.match(%r{/$})
|
2010-09-06 21:48:25 -04:00
|
|
|
request_path.gsub!(%r{^/}, '')
|
|
|
|
parts = request_path.split('/')
|
|
|
|
|
|
|
|
if parts.length > 1
|
|
|
|
arry = []
|
|
|
|
(parts.length - 1).times { arry << ".." }
|
|
|
|
arry << path
|
|
|
|
File.join(*arry)
|
|
|
|
else
|
|
|
|
path
|
|
|
|
end
|
2010-09-04 23:26:48 -04:00
|
|
|
end
|
2009-10-22 20:25:15 -04:00
|
|
|
end
|
|
|
|
end
|
2010-09-06 21:48:25 -04:00
|
|
|
alias :included :registered
|
2009-10-22 20:25:15 -04:00
|
|
|
end
|
2010-09-06 21:48:25 -04:00
|
|
|
end
|