Minor relative_assets cleanup

This commit is contained in:
Thomas Reynolds 2012-04-26 15:59:28 -07:00
parent 8bf0124241
commit 4a49388d64

View file

@ -1,63 +1,63 @@
# Extension namespace # Extension namespace
module Middleman::Extensions module Middleman
module Extensions
# Relative Assets extension # Relative Assets extension
module RelativeAssets module RelativeAssets
# Setup extension # Setup extension
class << self class << self
# Once registered # Once registered
def registered(app) def registered(app)
# Tell compass to use relative assets # Tell compass to use relative assets
app.compass_config do |config| app.compass_config do |config|
config.relative_assets = true config.relative_assets = true
end
# Include instance methods
app.send :include, InstanceMethods
end end
# Include instance methods alias :included :registered
app.send :include, InstanceMethods
end end
alias :included :registered # Relative Assets instance method
end module InstanceMethods
# Relative Assets instance method # asset_url override for relative assets
module InstanceMethods # @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 if path.include?("://")
# @param [String] path super(path, prefix)
# @param [String] prefix elsif path[0,1] == "/"
# @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
path 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 end
end end
end end
# Register extension
# register :relative_assets, RelativeAssets
end end