1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman/features/relative_assets.rb

38 lines
1 KiB
Ruby
Raw Normal View History

module Middleman::Features::RelativeAssets
class << self
def registered(app)
2011-07-26 16:40:37 -04:00
app.compass_config do |config|
config.relative_assets = true
end
2011-07-06 13:40:17 -04:00
app.register_asset_handler :relative_assets do |path, prefix, request|
begin
2011-07-06 13:40:17 -04:00
prefix = app.images_dir if prefix == app.http_images_path
rescue
end
if path.include?("://")
2011-07-06 13:40:17 -04:00
app.before_asset_handler(:relative_assets, path, prefix, request)
elsif path[0,1] == "/"
path
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{/$})
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
end
end
end
alias :included :registered
end
end