Class: Jekyll::Autoprefixer::Autoprefixer

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/autoprefixer/autoprefixer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Autoprefixer

Returns a new instance of Autoprefixer.



11
12
13
14
# File 'lib/jekyll/autoprefixer/autoprefixer.rb', line 11

def initialize(site)
  @site = site
  @batch = Array.new
end

Instance Attribute Details

#batchObject (readonly)

Returns the value of attribute batch.



9
10
11
# File 'lib/jekyll/autoprefixer/autoprefixer.rb', line 9

def batch
  @batch
end

#siteObject (readonly)

Returns the value of attribute site.



9
10
11
# File 'lib/jekyll/autoprefixer/autoprefixer.rb', line 9

def site
  @site
end

Instance Method Details

#processObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll/autoprefixer/autoprefixer.rb', line 16

def process()
  options = @site.config['autoprefixer'] || {}

  if !options['only_production'] || Jekyll.env == "production"
    @batch.each do |item|
      path = item.destination(@site.dest)

      File.open(path, 'r+') do |file|
        content = file.read
        file.truncate(0)
        file.rewind
        file.write(AutoprefixerRails.process(content, options))
      end
    end
  end

  @batch.clear
end