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 module Middleman::Features::AssetHost
class << self class << self
def registered(app) def registered(app)
app.set :asset_host, nil
app.compass_config do |config| app.compass_config do |config|
if app.asset_host.is_a?(Proc) if self.asset_host.is_a?(Proc)
config.asset_host(&app.asset_host) config.asset_host(&self.asset_host)
end end
end end
app.register_asset_handler :asset_host do |path, prefix| app.send :include, InstanceMethods
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
end end
alias :included :registered alias :included :registered
end 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 end