class Middleman::Extensions::RelativeAssets

Relative Assets extension

Public Class Methods

new(app, options_hash={}, &block) click to toggle source
Calls superclass method Middleman::Extension::new
# File lib/middleman-more/extensions/relative_assets.rb, line 3
def initialize(app, options_hash={}, &block)
  super

  # After compass is setup, make it use the registered cache buster
  app.compass_config do |config|
    config.relative_assets = true
  end if app.respond_to?(:compass_config)
end

Public Instance Methods

asset_url(path, prefix='') click to toggle source

asset_url override for relative assets @param [String] path @param [String] prefix @return [String]

Calls superclass method
# File lib/middleman-more/extensions/relative_assets.rb, line 17
def asset_url(path, prefix='')
  path = super(path, prefix)

  if path.include?('//') || path.start_with?('data:') || !current_resource
    path
  else
    current_dir = Pathname('/' + current_resource.destination_path)
    Pathname(path).relative_path_from(current_dir.dirname).to_s
  end
end