class Sprockets::SasscProcessor
Processor engine class for the SASS/SCSS compiler. Depends on the ‘sassc` gem.
For more information see:
https://github.com/sass/sassc-ruby https://github.com/sass/sassc-rails
Attributes
cache_key[R]
Public Class Methods
cache_key()
click to toggle source
# File lib/sprockets/sassc_processor.rb, line 34 def self.cache_key instance.cache_key end
call(input)
click to toggle source
# File lib/sprockets/sassc_processor.rb, line 30 def self.call(input) instance.call(input) end
instance()
click to toggle source
Public: Return singleton instance with default options.
Returns SasscProcessor
object.
# File lib/sprockets/sassc_processor.rb, line 26 def self.instance @instance ||= new end
new(options = {}, &block)
click to toggle source
# File lib/sprockets/sassc_processor.rb, line 40 def initialize(options = {}, &block) @cache_version = options[:cache_version] @cache_key = "#{self.class.name}:#{VERSION}:#{Autoload::SassC::VERSION}:#{@cache_version}".freeze @importer_class = options[:importer] @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
syntax()
click to toggle source
Internal: Defines default sass syntax to use. Exposed so the ScsscProcessor
may override it.
# File lib/sprockets/sassc_processor.rb, line 19 def self.syntax :sass end
Public Instance Methods
call(input)
click to toggle source
# File lib/sprockets/sassc_processor.rb, line 52 def call(input) context = input[:environment].context_class.new(input) options = engine_options(input, context) engine = Autoload::SassC::Engine.new(input[:data], options) css = Utils.module_include(Autoload::SassC::Script::Functions, @functions) do engine.render.sub(/^\n^\/\*# sourceMappingURL=.*\*\/$/m, '') end begin map = SourceMapUtils.format_source_map(JSON.parse(engine.source_map), input) map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map) engine.dependencies.each do |dependency| context.metadata[:dependencies] << URIUtils.build_file_digest_uri(dependency.filename) end rescue SassC::NotRenderedError map = input[:metadata][:map] end context.metadata.merge(data: css, map: map) end
Private Instance Methods
engine_options(input, context)
click to toggle source
# File lib/sprockets/sassc_processor.rb, line 273 def engine_options(input, context) merge_options({ filename: input[:filename], syntax: self.class.syntax, load_paths: input[:environment].paths, importer: @importer_class, source_map_contents: false, source_map_file: "#{input[:filename]}.map", omit_source_map_url: true, sprockets: { context: context, environment: input[:environment], dependencies: context.metadata[:dependencies] } }) end
merge_options(options)
click to toggle source
# File lib/sprockets/sassc_processor.rb, line 78 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