Class: Condenser::SassTransformer
- Inherits:
-
Object
- Object
- Condenser::SassTransformer
- Defined in:
- lib/condenser/transformers/sass_transformer.rb,
lib/condenser/transformers/sass_transformer/importer.rb
Overview
Transformer engine class for the SASS/SCSS compiler. Depends on the sass gem.
For more infomation see:
https://github.com/sass/sass
https://github.com/rails/sass-rails
Direct Known Subclasses
Defined Under Namespace
Modules: Functions Classes: Importer
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .cache_key ⇒ Object
- .call(environment, input) ⇒ Object
-
.instance ⇒ Object
Public: Return singleton instance with default options.
- .setup(environment) ⇒ Object
-
.syntax ⇒ Object
Internal: Defines default sass syntax to use.
Instance Method Summary collapse
- #call(environment, input) ⇒ Object
-
#initialize(options = {}, &block) ⇒ SassTransformer
constructor
Public: Initialize template with custom options.
- #name ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ SassTransformer
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.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 52 def initialize( = {}, &block) @options = @cache_version = [:cache_version] # @cache_key = "#{self.class.name}:#{VERSION}:#{Autoload::Sass::VERSION}:#{@cache_version}".freeze @importer_class = [:importer] || Condenser::SassTransformer::Importer @sass_config = [:sass_config] || {} @functions = Module.new do include Functions include [:functions] if [:functions] class_eval(&block) if block_given? end # puts @functions.method(:asset_path).source_location end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Returns the value of attribute cache_key.
40 41 42 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 40 def cache_key @cache_key end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 13 def @options end |
Class Method Details
.cache_key ⇒ Object
36 37 38 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 36 def self.cache_key instance.cache_key end |
.call(environment, input) ⇒ Object
32 33 34 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 32 def self.call(environment, input) instance.call(environment, input) end |
.instance ⇒ Object
Public: Return singleton instance with default options.
Returns SassProcessor object.
28 29 30 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 28 def self.instance @instance ||= new end |
.setup(environment) ⇒ Object
21 22 23 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 21 def self.setup(environment) require "sassc" unless defined?(::SassC::Engine) end |
.syntax ⇒ Object
Internal: Defines default sass syntax to use. Exposed so the ScssProcessor may override it.
17 18 19 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 17 def self.syntax :sass end |
Instance Method Details
#call(environment, input) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 67 def call(environment, input) # context = input[:environment].context_class.new(input) = ({ syntax: self.class.syntax, filename: input[:filename], source_map_file: "#{input[:filename]}.map", source_map_contents: true, # cache_store: Cache.new(environment.cache), load_paths: environment.path, importer: @importer_class, condenser: { context: environment.new_context_class, environment: environment }, asset: input }) engine = SassC::Engine.new(input[:source], ) css = Utils.module_include(SassC::Script::Functions, @functions) do engine.render end css.delete_suffix!("\n/*# sourceMappingURL=#{File.basename(input[:filename])}.map */") # engine.source_map # css = css.delete_suffix!("\n/*# sourceMappingURL= */\n") input[:source] = css # input[:map] = map.to_json({}) end |
#name ⇒ Object
42 43 44 |
# File 'lib/condenser/transformers/sass_transformer.rb', line 42 def name self.class.name end |