class Object

Public Instance Methods

cachebust_generated_images(path) click to toggle source
# File lib/compass-rails/patches.rb, line 11
def cachebust_generated_images(path)
  generated_images_dir = Compass.configuration.generated_images_dir
  generated_images_dir = Rails.root.join(generated_images_dir)

  sprockets_env     = options[:sprockets][:environment]
  sprockets_entries = sprockets_env.instance_variable_get(:@entries) || {}
  sprockets_stats   = sprockets_env.instance_variable_get(:@stats) || {}

  if sprockets_entries.key?(generated_images_dir.to_s)
    path = path.value
    dir  = File.dirname(path)

    # Delete the entries (directories) which cache the files/dirs in a directory
    entry = generated_images_dir.join(dir).to_s
    sprockets_entries.delete(entry)

    # Delete the stats (file/dir info) which cache the what kind of file/dir each image is
    stat = generated_images_dir.join(path).to_s
    sprockets_stats.delete(stat)
  end
end
evaluate(context, locals, &block) click to toggle source
# File lib/compass-rails/patches/sass_importer.rb, line 8
def evaluate(context, locals, &block)
  # Use custom importer that knows about Sprockets Caching
  cache_store =  Sprockets::SassProcessor::CacheStore.new(sprockets_cache_store, context.environment)

  paths  = context.environment.paths.map { |path| CompassRails::SpriteImporter.new(path) }
  paths += context.environment.paths.map { |path| sass_importer(context, path) }
  paths += ::Rails.application.config.sass.load_paths

  options = CompassRails.sass_config.merge( {
    :filename => eval_file,
    :line => line,
    :syntax => syntax,
    :cache_store => cache_store,
    :importer => sass_importer(context, context.pathname),
    :load_paths => paths,
    :sprockets => {
      :context => context,
      :environment => context.environment
    }
  })

  engine = ::Sass::Engine.new(data, options)

  engine.dependencies.map do |dependency|
    filename = dependency.options[:filename]
    if filename.include?('*') # Handle sprite globs
      image_path = Rails.root.join(Compass.configuration.images_dir).to_s
      Dir[File.join(image_path, filename)].each do |f|
        context.depend_on(f)
      end
    else
      context.depend_on(filename)
    end
  end

  engine.render
rescue ::Sass::SyntaxError => e
  # Annotates exception message with parse line number
  context.__LINE__ = e.sass_backtrace.first[:line]
  raise e
end
generated_image_url(path, cache_buster = Sass::Script::Bool.new(false)) click to toggle source
# File lib/compass-rails/patches.rb, line 6
def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false))
  cachebust_generated_images(path)
  asset_url(path)
end
image_path_for_size(image_file) click to toggle source
Calls superclass method
# File lib/compass-rails/patches/compass.rb, line 4
def image_path_for_size(image_file)
  begin
    file = ::Rails.application.assets.find_asset(image_file)
    return file.filename
  rescue ::Sprockets::FileOutsidePaths
    return super(image_file)
  end
end
sass_importer(context, path) click to toggle source
# File lib/compass-rails/patches/sass_importer.rb, line 56
def sass_importer(context, path)
  case sass_importer_artiy.abs
  when 1
    sass_importer_class.new(path)
  else
    sass_importer_class.new(context, path)
  end
end
sass_importer_artiy() click to toggle source
# File lib/compass-rails/patches/sass_importer.rb, line 52
def sass_importer_artiy
  @sass_importer_artiy ||= sass_importer_class.instance_method(:initialize).arity
end
sass_importer_class() click to toggle source

if using haml-rails, self.class.parent = Haml::Filters (which doesn’t have an implementation)

# File lib/compass-rails/patches/sass_importer.rb, line 66
def sass_importer_class
  @sass_importer_class ||= if defined?(self.class.parent::SassImporter)
                             self.class.parent::SassImporter
                           elsif defined?(Sass::Rails::SassTemplate)
                             Sass::Rails::SassImporter
                           else
                             Sprockets::SassImporter
                           end
end
sprockets_cache_store() click to toggle source
# File lib/compass-rails/patches/sass_importer.rb, line 76
def sprockets_cache_store
  cache = case Rails.application.config.assets.cache_store
  when :null_store
    Sprockets::Cache::NullStore.new
  when :memory_store, :mem_cache_store
    Sprockets::Cache::MemoryStore.new
  else
    tmpd = Rails.root.join("tmp/compass").to_s
    FileUtils.mkdir(tmpd) unless File.directory?(tmpd)
    Sprockets::Cache::FileStore.new(tmpd)
  end

  Sprockets::Cache.new(cache, Rails.logger)
end