2009-11-22 18:37:11 -05:00
|
|
|
class Middleman::Base
|
|
|
|
after_feature_init do
|
|
|
|
::Compass.configuration do |config|
|
|
|
|
config.relative_assets = Proc.new do
|
2010-01-20 18:22:40 -05:00
|
|
|
Middleman::Base.enabled?(:relative_assets)
|
2009-11-22 18:37:11 -05:00
|
|
|
end
|
|
|
|
end
|
2010-01-20 18:22:40 -05:00
|
|
|
|
2009-11-22 18:37:11 -05:00
|
|
|
::Compass.configure_sass_plugin!
|
|
|
|
end
|
2009-10-22 20:25:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class << Middleman::Base
|
|
|
|
alias_method :pre_relative_asset_url, :asset_url
|
|
|
|
def asset_url(path, prefix="", request=nil)
|
2010-01-20 18:22:40 -05:00
|
|
|
if !self.enabled?(:relative_assets)
|
2009-11-22 18:37:11 -05:00
|
|
|
return pre_relative_asset_url(path, prefix, request)
|
|
|
|
end
|
|
|
|
|
2009-10-22 20:25:15 -04:00
|
|
|
begin
|
|
|
|
prefix = self.images_dir if prefix == self.http_images_path
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
|
|
|
|
if path.include?("://")
|
2009-11-06 19:23:33 -05:00
|
|
|
pre_relative_asset_url(path, prefix, request)
|
|
|
|
elsif path[0,1] == "/"
|
2009-10-22 20:25:15 -04:00
|
|
|
path
|
|
|
|
else
|
2009-11-06 19:23:33 -05:00
|
|
|
path = File.join(prefix, path) if prefix.length > 0
|
2009-10-22 20:25:15 -04:00
|
|
|
request_path = request.path_info.dup
|
2009-11-06 19:23:33 -05:00
|
|
|
request_path << self.index_file if path.match(%r{/$})
|
2009-10-22 20:25:15 -04:00
|
|
|
request_path.gsub!(%r{^/}, '')
|
|
|
|
parts = request_path.split('/')
|
2009-11-06 19:23:33 -05:00
|
|
|
|
2009-10-22 20:25:15 -04:00
|
|
|
if parts.length > 1
|
2009-11-06 19:23:33 -05:00
|
|
|
arry = []
|
|
|
|
(parts.length - 1).times { arry << ".." }
|
|
|
|
arry << path
|
|
|
|
File.join(*arry)
|
2009-10-22 20:25:15 -04:00
|
|
|
else
|
|
|
|
path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|