diff --git a/middleman-more/lib/middleman-more.rb b/middleman-more/lib/middleman-more.rb index 4e3b99a2..ce9580dc 100644 --- a/middleman-more/lib/middleman-more.rb +++ b/middleman-more/lib/middleman-more.rb @@ -64,10 +64,8 @@ module Middleman # RelativeAssets allow any asset path in dynamic templates to be either # relative to the root of the project or use an absolute URL. - Middleman::Extensions.register(:relative_assets) do - require "middleman-more/extensions/relative_assets" - Middleman::Extensions::RelativeAssets - end + require "middleman-more/extensions/relative_assets" + Middleman::Extensions::RelativeAssets.register # GZIP assets and pages during build require "middleman-more/extensions/gzip" diff --git a/middleman-more/lib/middleman-more/extensions/relative_assets.rb b/middleman-more/lib/middleman-more/extensions/relative_assets.rb index c848f672..20583d03 100644 --- a/middleman-more/lib/middleman-more/extensions/relative_assets.rb +++ b/middleman-more/lib/middleman-more/extensions/relative_assets.rb @@ -1,44 +1,28 @@ -# Extension namespace -module Middleman - module Extensions +# Relative Assets extension +class Middleman::Extensions::RelativeAssets < ::Middleman::Extension - # Relative Assets extension - module RelativeAssets + def initialize(app, options_hash={}, &block) + super - # Setup extension - class << self + # After compass is setup, make it use the registered cache buster + app.compass_config do |config| + config.relative_assets = true + end + end - # Once registered - def registered(app) - # Tell compass to use relative assets - app.compass_config do |config| - config.relative_assets = true - end + helpers do + # asset_url override for relative assets + # @param [String] path + # @param [String] prefix + # @return [String] + def asset_url(path, prefix="") + path = super(path, prefix) - # Include instance methods - app.send :include, InstanceMethods - end - - alias :included :registered - end - - # Relative Assets instance method - module InstanceMethods - - # asset_url override for relative assets - # @param [String] path - # @param [String] prefix - # @return [String] - def asset_url(path, prefix="") - path = super(path, prefix) - - if path.include?("//") || !current_resource - path - else - current_dir = Pathname('/' + current_resource.destination_path) - Pathname(path).relative_path_from(current_dir.dirname).to_s - end - end + if path.include?("//") || !current_resource + path + else + current_dir = Pathname('/' + current_resource.destination_path) + Pathname(path).relative_path_from(current_dir.dirname).to_s end end end