2010-09-04 23:26:48 -04:00
|
|
|
class Middleman::Features::RelativeAssets
|
2010-09-05 22:28:38 -04:00
|
|
|
def initialize(app, config)
|
2010-09-04 23:26:48 -04:00
|
|
|
::Compass.configuration.relative_assets = true
|
|
|
|
|
|
|
|
Middleman::Assets.register :relative_assets do |path, prefix, request|
|
|
|
|
begin
|
2010-09-05 22:28:38 -04:00
|
|
|
prefix = Middleman::Server.images_dir if prefix == Middleman::Server.http_images_path
|
2010-09-04 23:26:48 -04:00
|
|
|
rescue
|
2009-11-22 18:37:11 -05:00
|
|
|
end
|
2009-10-22 20:25:15 -04:00
|
|
|
|
2010-09-04 23:26:48 -04:00
|
|
|
if path.include?("://")
|
|
|
|
Middleman::Assets.before(:relative_assets, path, prefix, request)
|
|
|
|
elsif path[0,1] == "/"
|
2009-10-22 20:25:15 -04:00
|
|
|
path
|
2010-09-04 23:26:48 -04:00
|
|
|
else
|
|
|
|
path = File.join(prefix, path) if prefix.length > 0
|
|
|
|
request_path = request.path_info.dup
|
2010-09-05 22:28:38 -04:00
|
|
|
request_path << Middleman::Server.index_file if path.match(%r{/$})
|
2010-09-04 23:26:48 -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
|
2009-10-22 20:25:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-09-04 23:26:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Middleman::Features.register :relative_assets, Middleman::Features::RelativeAssets
|