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.
9 10 11 |
# File 'lib/autoprefixer-rails/processor.rb', line 9 def initialize(params = { }) @params = params || { } end |
Instance Method Details
#info ⇒ Object
Return, which browsers and prefixes will be used
34 35 36 |
# File 'lib/autoprefixer-rails/processor.rb', line 34 def info runtime.eval("autoprefixer(#{ js_params }).info()") end |
#parse_config(config) ⇒ Object
Parse Browserslist config
39 40 41 42 43 44 |
# File 'lib/autoprefixer-rails/processor.rb', line 39 def parse_config(config) config.gsub(/#[^\n]*/, '') .split(/\n/) .map(&:strip) .reject(&:empty?) 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.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/autoprefixer-rails/processor.rb', line 19 def process(css, opts = {}) opts = (opts) apply_wrapper = "(function(opts) {" + "processor = autoprefixer(" + js_params(opts[:from]) + ");" + "return eval(process.apply(this, opts));" + "})" result = runtime.call(apply_wrapper, [css, opts]) Result.new(result['css'], result['map']) end |