diff --git a/lib/middleman/features/asset_host.rb b/lib/middleman/features/asset_host.rb index 6bba40a0..6a728cc8 100644 --- a/lib/middleman/features/asset_host.rb +++ b/lib/middleman/features/asset_host.rb @@ -1,22 +1,32 @@ module Middleman::Features::AssetHost class << self def registered(app) + app.set :asset_host, nil + app.compass_config do |config| - if app.asset_host.is_a?(Proc) - config.asset_host(&app.asset_host) + if self.asset_host.is_a?(Proc) + config.asset_host(&self.asset_host) end end - - app.register_asset_handler :asset_host do |path, prefix| - original_output = self.before_asset_handler(:asset_host, path, prefix) - - valid_extensions = %w(.png .gif .jpg .jpeg .js .css) - - asset_prefix = self.asset_host.call(original_output) - - File.join(asset_prefix, original_output) - end + + app.send :include, InstanceMethods end alias :included :registered end + + module InstanceMethods + def asset_url(path, prefix="") + original_output = super + + valid_extensions = %w(.png .gif .jpg .jpeg .js .css) + + asset_prefix = if self.asset_host.is_a?(Proc) + self.asset_host.call(original_output) + elsif self.asset_host.is_a?(String) + self.asset_host + end + + File.join(asset_prefix, original_output) + end + end end \ No newline at end of file