Class: Pakyow::Assets::Types::CSS

Inherits:
Asset
  • Object
show all
Defined in:
lib/pakyow/assets/types/css.rb

Instance Attribute Summary

Attributes inherited from Asset

#dependencies, #logical_path, #mime_suffix, #mime_type

Instance Method Summary collapse

Methods inherited from Asset

#bytesize, #disable_source_map, #each, #fingerprint, #fingerprinted_filename, #freeze, inherited, load, new_from_path, #public_path, #read, #source_map, #source_map?, update_path_for_emitted_type

Constructor Details

#initialize(local_path:, config:, **kwargs) ⇒ CSS

Returns a new instance of CSS.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pakyow/assets/types/css.rb', line 13

def initialize(local_path:, config:, **kwargs)
  super

  @options = @config.sass.to_h
  @options[:filename] = @local_path.to_s
  @options[:syntax] = :scss

  if @config.source_maps
    @options[:source_map_file] = File.basename(@local_path.to_s)
  end
end

Instance Method Details

#process(content) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/pakyow/assets/types/css.rb', line 25

def process(content)
  @engine = ::SassC::Engine.new(content, @options)
  @engine.render
rescue StandardError => error
  Pakyow.logger.error "[#{self.class}] #{error}"

  # Be sure to return a string.
  #
  content
end

#source_map_contentObject



36
37
38
39
40
41
# File 'lib/pakyow/assets/types/css.rb', line 36

def source_map_content
  ensure_content
  @engine.source_map
rescue SassC::NotRenderedError
  nil
end