class Sprockets::SassProcessor
def self.cache_key
def self.cache_key instance.cache_key end
def self.call(input)
def self.call(input) instance.call(input) end
def self.instance
Public: Return singleton instance with default options.
def self.instance @instance ||= new end
def self.syntax
Internal: Defines default sass syntax to use. Exposed so the ScssProcessor
def self.syntax :sass end
def build_cache_store(input, version)
Override this method if you need to use a different cache than the
version - the cache version.
input - the input hash.
Public: Build the cache store to be used by the Sass engine.
def build_cache_store(input, version) CacheStore.new(input[:cache], version) end
def call(input)
def call(input) context = input[:environment].context_class.new(input) engine_options = merge_options({ filename: input[:filename], syntax: self.class.syntax, cache_store: build_cache_store(input, @cache_version), load_paths: context.environment.paths.map { |p| @importer_class.new(p.to_s) }, importer: @importer_class.new(Pathname.new(context.filename).to_s), sprockets: { context: context, environment: input[:environment], dependencies: context.metadata[:dependencies] } }) engine = Autoload::Sass::Engine.new(input[:data], engine_options) css, map = Utils.module_include(Autoload::Sass::Script::Functions, @functions) do engine.render_with_sourcemap('') end css = css.sub("\n/*# sourceMappingURL= */\n", '') map = SourceMapUtils.format_source_map(JSON.parse(map.to_json(css_uri: '')), input) map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map) # Track all imported files sass_dependencies = Set.new([input[:filename]]) engine.dependencies.map do |dependency| sass_dependencies << dependency.options[:filename] context.metadata[:dependencies] << URIUtils.build_file_digest_uri(dependency.options[:filename]) end context.metadata.merge(data: css, sass_dependencies: sass_dependencies, map: map) end
def initialize(options = {}, &block)
change after code changes are made to Sass Functions.
cache_version - String custom cache version. Used to force a cache
options - Hash
Public: Initialize template with custom options.
def initialize(options = {}, &block) @cache_version = options[:cache_version] @cache_key = "#{self.class.name}:#{VERSION}:#{Autoload::Sass::VERSION}:#{@cache_version}".freeze @importer_class = options[:importer] || Sass::Importers::Filesystem @sass_config = options[:sass_config] || {} @functions = Module.new do include Functions include options[:functions] if options[:functions] class_eval(&block) if block_given? end end
def merge_options(options)
def merge_options(options) defaults = @sass_config.dup if load_paths = defaults.delete(:load_paths) options[:load_paths] += load_paths end options.merge!(defaults) options end