Class: Jekyll::Converters::PostCss

Inherits:
Converter
  • Object
show all
Defined in:
lib/jekyll/converters/postcss.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ PostCss

Returns a new instance of PostCss.



12
13
14
15
16
17
18
19
20
# File 'lib/jekyll/converters/postcss.rb', line 12

def initialize(config = {})
  super

  @cache_enabled = config.fetch("postcss", {}).fetch("cache", true)
  @socket = config.fetch("socket") { ::PostCss::Socket.new }
  @raw_cache = nil
  @import_raw_cache = {}
  @converted_cache = nil
end

Instance Method Details

#convert(content) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jekyll/converters/postcss.rb', line 30

def convert(content)
  raise PostCssNotFoundError unless Dir.exist?("./node_modules/postcss")

  @raw_digest = Digest::MD5.hexdigest content
  @raw_import_digests = import_digests(content)

  if cache_disabled? || cache_miss?
    @raw_cache = @raw_digest.dup
    @import_raw_cache = @raw_import_digests.dup

    @socket.write content

    @converted_cache = @socket.read
  end

  reset

  @converted_cache
end

#matches(ext) ⇒ Object



22
23
24
# File 'lib/jekyll/converters/postcss.rb', line 22

def matches(ext)
  [".css", ".scss", ".sass"].include?(ext.downcase)
end

#output_ext(ext) ⇒ Object



26
27
28
# File 'lib/jekyll/converters/postcss.rb', line 26

def output_ext(ext)
  ext
end