Class: Sprockets::SassProcessor
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/sprockets/sass_processor.rb, lib/sprockets/sass_cache_store.rb |
Overview
Processor engine class for the SASS/SCSS compiler. Depends on the sass
gem.
For more information see:
Class Method Summary
- .cache_key
- .call(input)
-
.instance
Public: Return singleton instance with default options.
-
.new(options = {}, &block) ⇒ SassProcessor
constructor
Public: Initialize template with custom options.
-
.syntax
Internal: Defines default sass syntax to use.
Instance Attribute Summary
- #cache_key readonly
Instance Method Summary
- #call(input)
-
#build_cache_store(input, version)
private
Public: Build the cache store to be used by the Sass engine.
- #merge_options(options) private
Constructor Details
.new(options = {}, &block) ⇒ SassProcessor
Public: Initialize template with custom options.
options - Hash cache_version - String custom cache version. Used to force a cache
change after code changes are made to Sass Functions.
# File 'lib/sprockets/sass_processor.rb', line 47
def initialize( = {}, &block) @cache_version = [:cache_version] @cache_key = "#{self.class.name}:#{VERSION}:#{Autoload::Sass::VERSION}:#{@cache_version}".freeze @importer_class = [:importer] || Sass::Importers::Filesystem @sass_config = [:sass_config] || {} @functions = Module.new do include Functions include [:functions] if [:functions] class_eval(&block) if block_given? end end
Class Method Details
.cache_key
[ GitHub ]# File 'lib/sprockets/sass_processor.rb', line 35
def self.cache_key instance.cache_key end
.call(input)
[ GitHub ]# File 'lib/sprockets/sass_processor.rb', line 31
def self.call(input) instance.call(input) end
.instance
Public: Return singleton instance with default options.
Returns SassProcessor object.
# File 'lib/sprockets/sass_processor.rb', line 27
def self.instance @instance ||= new end
.syntax
Internal: Defines default sass syntax to use. Exposed so the ScssProcessor
may override it.
# File 'lib/sprockets/sass_processor.rb', line 20
def self.syntax :sass end
Instance Attribute Details
#cache_key (readonly)
[ GitHub ]# File 'lib/sprockets/sass_processor.rb', line 39
attr_reader :cache_key
Instance Method Details
#build_cache_store(input, version) (private)
Public: Build the cache store to be used by the Sass engine.
input - the input hash. version - the cache version.
Override this method if you need to use a different cache than the ::Sprockets
cache.
# File 'lib/sprockets/sass_processor.rb', line 105
def build_cache_store(input, version) CacheStore.new(input[:cache], version) end
#call(input)
[ GitHub ]# File 'lib/sprockets/sass_processor.rb', line 59
def call(input) context = input[:environment].context_class.new(input) = ({ 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. [:dependencies] } }) engine = Autoload::Sass::Engine.new(input[:data], ) 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[: ][:map], map) # Track all imported files sass_dependencies = Set.new([input[:filename]]) engine.dependencies.map do |dependency| sass_dependencies << dependency. [:filename] context. [:dependencies] << URIUtils.build_file_digest_uri(dependency. [:filename]) end context. .merge(data: css, sass_dependencies: sass_dependencies, map: map) end
#merge_options(options) (private)
[ GitHub ]# File 'lib/sprockets/sass_processor.rb', line 109
def ( ) defaults = @sass_config.dup if load_paths = defaults.delete(:load_paths) [:load_paths] += load_paths end .merge!(defaults) end