Sha256: 216de2fb9f147383436a7c9152394894a8d44a0be15257b42c2edc44dbb20090

Contents?: true

Size: 1.03 KB

Versions: 55

Compression:

Stored size: 1.03 KB

Contents

module Middleman::Features::RelativeAssets
  class << self
    def registered(app)
      app.compass_config do |config|
        config.relative_assets = true
      end

      app.register_asset_handler :relative_assets do |path, prefix, request|
        begin
          prefix = app.images_dir if prefix == app.http_images_path
        rescue
        end

        if path.include?("://")
          app.before_asset_handler(:relative_assets, path, prefix, request)
        elsif path[0,1] == "/"
          path
        else
          path = File.join(prefix, path) if prefix.length > 0
          request_path = request.path_info.dup
          request_path << app.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
    alias :included :registered
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
middleman-2.0.15.2-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.15.2 lib/middleman/features/relative_assets.rb
middleman-2.0.15.1-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.15.1 lib/middleman/features/relative_assets.rb
middleman-2.0.15-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.15 lib/middleman/features/relative_assets.rb
middleman-2.0.14-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.14 lib/middleman/features/relative_assets.rb
middleman-2.0.14.pre2-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.14.pre2 lib/middleman/features/relative_assets.rb
middleman-2.0.13.2-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.14.pre-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.14.pre lib/middleman/features/relative_assets.rb
middleman-2.0.13.1-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.13.1 lib/middleman/features/relative_assets.rb
middleman-2.0.13-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.13 lib/middleman/features/relative_assets.rb
middleman-2.0.12-x86-mingw32 lib/middleman/features/relative_assets.rb
middleman-2.0.12 lib/middleman/features/relative_assets.rb
middleman-2.0.12.pre-x86-mingw32 lib/middleman/features/relative_assets.rb