From 4a49388d642e50ef753de189a4e52b67b57ae92a Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 26 Apr 2012 15:59:28 -0700 Subject: [PATCH] Minor relative_assets cleanup --- .../extensions/relative_assets.rb | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/middleman-more/lib/middleman-more/extensions/relative_assets.rb b/middleman-more/lib/middleman-more/extensions/relative_assets.rb index 1f694eee..5aaf59b8 100755 --- a/middleman-more/lib/middleman-more/extensions/relative_assets.rb +++ b/middleman-more/lib/middleman-more/extensions/relative_assets.rb @@ -1,63 +1,63 @@ # Extension namespace -module Middleman::Extensions +module Middleman + module Extensions - # Relative Assets extension - module RelativeAssets + # Relative Assets extension + module RelativeAssets - # Setup extension - class << self + # Setup extension + class << self - # Once registered - def registered(app) - # Tell compass to use relative assets - app.compass_config do |config| - config.relative_assets = true + # Once registered + def registered(app) + # Tell compass to use relative assets + app.compass_config do |config| + config.relative_assets = true + end + + # Include instance methods + app.send :include, InstanceMethods end - # Include instance methods - app.send :include, InstanceMethods + alias :included :registered end - - alias :included :registered - end - # Relative Assets instance method - module InstanceMethods + # 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="") - begin - prefix = images_dir if prefix == http_images_path - rescue - end + # asset_url override for relative assets + # @param [String] path + # @param [String] prefix + # @return [String] + def asset_url(path, prefix="") + begin + prefix = images_dir if prefix == http_images_path + rescue + end - if path.include?("://") - super(path, prefix) - elsif path[0,1] == "/" - path - else - path = File.join(prefix, path) if prefix.length > 0 - request_path = @request_path.dup - request_path << index_file if path.match(%r{/$}) - request_path.gsub!(%r{^/}, '') - parts = request_path.split('/') - - if parts.length > 1 - arry = [] - (parts.length - 1).times { arry << ".." } - arry << path - File.join(*arry) - else + if path.include?("://") + super(path, prefix) + elsif path[0,1] == "/" path + else + path = File.join(prefix, path) if prefix.length > 0 + + request_path = @request_path.dup + request_path << index_file if path.match(%r{/$}) + + parts = request_path.gsub(%r{^/}, '').split('/') + + if parts.length > 1 + arry = [] + (parts.length - 1).times { arry << ".." } + arry << path + File.join(*arry) + else + path + end end end end end end - - # Register extension - # register :relative_assets, RelativeAssets end \ No newline at end of file