Class: AutoprefixerRails::Processor
- Inherits:
-
Object
- Object
- AutoprefixerRails::Processor
- Defined in:
- lib/autoprefixer-rails/processor.rb
Overview
Ruby to JS wrapper for Autoprefixer processor instance
Instance Method Summary collapse
-
#info ⇒ Object
Return, which browsers and prefixes will be used.
-
#initialize(params = { }) ⇒ Processor
constructor
A new instance of Processor.
-
#parse_config(config) ⇒ Object
Parse Browserslist config.
-
#process(css, opts = { }) ⇒ Object
Process ‘css` and return result.
Constructor Details
#initialize(params = { }) ⇒ Processor
Returns a new instance of Processor.
11 12 13 |
# File 'lib/autoprefixer-rails/processor.rb', line 11 def initialize(params = { }) @params = params || { } end |
Instance Method Details
#info ⇒ Object
Return, which browsers and prefixes will be used
36 37 38 |
# File 'lib/autoprefixer-rails/processor.rb', line 36 def info runtime.eval("autoprefixer(#{ js_params }).info()") end |
#parse_config(config) ⇒ Object
Parse Browserslist config
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/autoprefixer-rails/processor.rb', line 41 def parse_config(config) sections = { 'defaults' => [] } current = 'defaults' config.gsub(/#[^\n]*/, '') .split(/\n/) .map(&:strip) .reject(&:empty?) .each do |line| if line =~ IS_SECTION current = line.match(IS_SECTION)[1].strip sections[current] ||= [] else sections[current] << line end end sections end |
#process(css, opts = { }) ⇒ Object
Process ‘css` and return result.
Options can be:
-
‘from` with input CSS file name. Will be used in error messages.
-
‘to` with output CSS file name.
-
‘map` with true to generate new source map or with previous map.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/autoprefixer-rails/processor.rb', line 21 def process(css, opts = { }) opts = (opts) apply_wrapper = "(function(opts) {" + "return eval(process.apply(this, opts));" + "})" params = params_with_browsers(opts[:from]).merge(opts) result = runtime.call(apply_wrapper, [css, params]) Result.new(result['css'], result['map'], result['warnings']) end |