Sha256: 2d073b8b7daf5a79111d3d348390effc948f3f4dc73f1128a49068bf7d9c89a5

Contents?: true

Size: 1000 Bytes

Versions: 1

Compression:

Stored size: 1000 Bytes

Contents

module Middleman::Features::RelativeAssets
  class << self
    def registered(app)
      app.compass_config do |config|
        config.relative_assets = true
      end
      
      app.send :include, InstanceMethods
    end
    alias :included :registered
  end
  
  module InstanceMethods
    def asset_url(path, prefix="")
      begin
        prefix = self.images_dir if prefix == self.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 << self.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
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-3.0.0.alpha.2 lib/middleman/features/relative_assets.rb