Class: RogerAutoprefixer::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/roger_autoprefixer/processor.rb

Instance Method Summary collapse

Instance Method Details

#call(release, options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :match (Array)

    An array of shell globs, defaults to [“stylesheets/*/.scss”]

  • :skip (Array)

    An array of regexps which will be skipped, defaults to [/_.*.scssZ/], Attention! Skipped files will be deleted as well!

  • :browsers (Array)

    Browsers to do autporefixing for passed to AutoprefixerRails



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/roger_autoprefixer/processor.rb', line 8

def call(release, options = {})
  options = {
    match: ["stylesheets/**/*.css"],
    skip: [],
    browsers: nil
  }.update(options)

  match = options.delete(:match)
  skip = options.delete(:skip)

  # Setup prefixer options
  prefixer_options = {}

  if options[:browsers]
    prefixer_options[:browsers] = options[:browsers]
  end

  # Prefix CSS files
  files = release.get_files(match)
  files.each do |f|
    if !skip.detect { |r| r.match(f) }
      release.log(self, "Processing: #{f}")
      # Compile SCSS
      content = File.read(f)
      File.open(f, "w") do |fh|
        fh.write AutoprefixerRails.process(content, prefixer_options.dup.update(from: f)).css
      end
    end
  end
end