fix basic asset host

This commit is contained in:
Thomas Reynolds 2011-11-18 16:22:15 -08:00
parent a5e0dd49a9
commit 186651c5b5

View file

@ -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