2010-09-04 23:26:48 -04:00
|
|
|
module Middleman
|
|
|
|
module Assets
|
|
|
|
@@asset_handler_map = []
|
|
|
|
@@asset_handler_stack = []
|
|
|
|
|
|
|
|
def self.register(handler_name, &block)
|
|
|
|
if block_given?
|
|
|
|
@@asset_handler_stack << block
|
|
|
|
@@asset_handler_map << handler_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get_url(path, prefix="", request=nil)
|
|
|
|
@@asset_handler_stack.last.call(path, prefix, request)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.before(position, *args)
|
|
|
|
current_index = @@asset_handler_map.index(position)
|
|
|
|
return nil unless current_index
|
|
|
|
|
|
|
|
previous = current_index - 1
|
|
|
|
if (previous >= 0) && (previous < @@asset_handler_map.length)
|
|
|
|
@@asset_handler_stack[previous].call(*args)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Middleman::Assets.register :base do |path, prefix, request|
|
2010-09-05 22:28:38 -04:00
|
|
|
path.include?("://") ? path : File.join(Middleman::Server.http_prefix || "/", prefix, path)
|
2010-09-04 23:26:48 -04:00
|
|
|
end
|