Class: SassC::Rails::SassTemplate
- Inherits:
-
Sprockets::SassProcessor
- Object
- Sprockets::SassProcessor
- SassC::Rails::SassTemplate
- Defined in:
- lib/sassc/rails/template.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Functions
Instance Method Summary collapse
- #call(input) ⇒ Object
- #config_options ⇒ Object
-
#initialize(options = {}, &block) ⇒ SassTemplate
constructor
rubocop:disable Lint/MissingSuper.
- #line_comments? ⇒ Boolean
- #load_paths ⇒ Object
- #safe_merge(_key, left, right) ⇒ Object
- #sass_style ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ SassTemplate
rubocop:disable Lint/MissingSuper
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sassc/rails/template.rb', line 10 def initialize( = {}, &block) # rubocop:disable Lint/MissingSuper @cache_version = [:cache_version] @cache_key = "#{self.class.name}:#{VERSION}:#{SassC::VERSION}:#{@cache_version}" # @importer_class = options[: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 |
Instance Method Details
#call(input) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sassc/rails/template.rb', line 22 def call(input) context = input[:environment].context_class.new(input) = { filename: input[:filename], line_comments: line_comments?, syntax: self.class.syntax, load_paths: input[:environment].paths, importer: SassC::Rails::Importer, sprockets: { context: context, environment: input[:environment], dependencies: context.[:dependency_paths] } }.merge!() { |key, left, right| safe_merge(key, left, right) } engine = ::SassC::Engine.new(input[:data], ) css = Sprockets::Utils.module_include(::SassC::Script::Functions, @functions) do engine.render end context..merge(data: css) end |
#config_options ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sassc/rails/template.rb', line 47 def opts = { style: sass_style, load_paths: load_paths } if ::Rails.application.config.sass.inline_source_maps opts.merge!(source_map_file: '.', source_map_embed: true, source_map_contents: true) end opts end |
#line_comments? ⇒ Boolean
67 68 69 |
# File 'lib/sassc/rails/template.rb', line 67 def line_comments? ::Rails.application.config.sass.line_comments end |
#load_paths ⇒ Object
63 64 65 |
# File 'lib/sassc/rails/template.rb', line 63 def load_paths ::Rails.application.config.sass.load_paths || [] end |
#safe_merge(_key, left, right) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/sassc/rails/template.rb', line 71 def safe_merge(_key, left, right) if [left, right].all? { |v| v.is_a? Hash } left.merge(right) { |k, l, r| safe_merge(k, l, r) } elsif [left, right].all? { |v| v.is_a? Array } (left + right).uniq else right end end |
#sass_style ⇒ Object
59 60 61 |
# File 'lib/sassc/rails/template.rb', line 59 def sass_style (::Rails.application.config.sass.style || :expanded).to_sym end |