module RailsSassImages

Constants

VERSION

Public Class Methods

asset(path) click to toggle source

Return asset by file `path` from Sass parser

# File lib/rails-sass-images.rb, line 5
def self.asset(path)
  path  = path.value

  @load_from = @load_from.call() if @load_from.is_a? Proc

  if @load_from.is_a? Pathname
    asset = @load_from.join(path)
    raise "Can't find asset #{path} in #{@load_from}" unless asset.exist?
  elsif sprockets? @load_from
    asset = @load_from[path]
    raise "Can't find asset #{path}" unless asset
    asset = Pathname.new(asset.filename)
  else
    raise "Unknown type of RailsSassImages.load_from"
  end

  asset
end
install(sprockets) click to toggle source

Set Sprockets environment and add Rails Sass Images styles paths

# File lib/rails-sass-images.rb, line 25
def self.install(sprockets)
  sprockets.append_path(Pathname(__FILE__).dirname.join('assets/stylesheets'))
  @load_from = sprockets
end
load_from() click to toggle source

Get Sprockets environment or assets dir path

# File lib/rails-sass-images.rb, line 37
def self.load_from
  @load_from
end
load_from=(source) click to toggle source

Set Sprockets environment or assets dir path

# File lib/rails-sass-images.rb, line 31
def self.load_from=(source)
  source = Pathname(source) if source.is_a? String
  @load_from = source
end

Private Class Methods

sprockets?(var) click to toggle source

Safe detect is `var` is a Sprockets environment

# File lib/rails-sass-images.rb, line 44
def self.sprockets?(var)
  return false unless defined? Sprockets
  var.is_a? Sprockets::Environment or var.is_a? Sprockets::CachedEnvironment
end