autoprefixer-rails 0.8.20131213 → 1.0.20131222

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -31,17 +31,18 @@ support to add vendor prefixes automatically using the Asset Pipeline:
31
31
 
32
32
  ```css
33
33
  :-webkit-full-screen a {
34
- -webkit-transition: -webkit-transform 1s;
35
- transition: transform 1s;
34
+ -webkit-transition: -webkit-transform 1s;
35
+ transition: transform 1s
36
36
  }
37
-
38
37
  :-moz-full-screen a {
39
- transition: transform 1s;
38
+ transition: transform 1s
39
+ }
40
+ :-ms-fullscreen a {
41
+ transition: transform 1s
40
42
  }
41
-
42
43
  :fullscreen a {
43
- -webkit-transition: -webkit-transform 1s;
44
- transition: transform 1s;
44
+ -webkit-transition: -webkit-transform 1s;
45
+ transition: transform 1s
45
46
  }
46
47
  ```
47
48
 
@@ -52,17 +53,17 @@ to `config/autoprefixer.yml`. See [browser section] in Autoprefixer docs.
52
53
  browsers:
53
54
  - "last 1 version"
54
55
  - "> 1%"
55
- - "ie 8"
56
+ - "explorer 10"
56
57
  ```
57
58
 
58
- You can inspect what properties will be changed using a Rake task:
59
+ You can get what properties will be changed using a Rake task:
59
60
 
60
61
  ```sh
61
- rake autoprefixer:inspect
62
+ rake autoprefixer:info
62
63
  ```
63
64
 
64
- By default, Autoprefixer uses `> 1%, last 2 versions, ff 17, opera 12.1`:
65
- * Firefox 17 is a latest [ESR].
65
+ By default, Autoprefixer uses `> 1%, last 2 versions, firefox 24, opera 12.1`:
66
+ * Firefox 24 is a latest [ESR].
66
67
  * Opera 12.1 will be in list until Opera supports non-Blink 12.x branch.
67
68
 
68
69
  [browser section]: https://github.com/ai/autoprefixer#browsers
@@ -89,5 +90,41 @@ If you need to call Autoprefixer from plain Ruby code, it’s very easy:
89
90
 
90
91
  ```ruby
91
92
  require "autoprefixer-rails"
92
- prefixed = AutoprefixerRails.compile(css)
93
+ prefixed = AutoprefixerRails.process(css, from: 'main.css').css
94
+ ```
95
+
96
+ You can specify browsers by `browsers` option:
97
+
98
+ ```ruby
99
+ AutoprefixerRails.process(css, from: 'a.css', browsers: ['> 1%', 'ie 10']).css
100
+ ```
101
+
102
+ ### Source Map
103
+
104
+ Autoprefixer will generate source map, if you set `map` option to `true` in
105
+ `process` method.
106
+
107
+ You must set input and output CSS files paths (by `from` and `to` options)
108
+ to generate correct map.
109
+
110
+ ```ruby
111
+ result = AutoprefixerRails.process(css,
112
+ map: true,
113
+ from: 'main.css',
114
+ to: 'main.out.css')
115
+
116
+ result.css #=> Prefixed CSS
117
+ result.map #=> Source map content
118
+ ```
119
+
120
+ Autoprefixer can also modify previous source map (for example, from Sass
121
+ compilation). Just set original source map content (as string) to `map` option:
122
+
123
+ ```ruby
124
+ result = AutoprefixerRails.process(css, {
125
+ map: File.read('main.sass.css.map'),
126
+ from: 'main.sass.css',
127
+ to: 'main.min.css')
128
+
129
+ result.map #=> Source map from main.sass to main.min.css
93
130
  ```
@@ -10,13 +10,13 @@ Gem::Specification.new do |s|
10
10
 
11
11
  s.files = `git ls-files`.split("\n")
12
12
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
13
- s.extra_rdoc_files = ['README.md', 'LICENSE', 'ChangeLog']
13
+ s.extra_rdoc_files = ['README.md', 'LICENSE', 'ChangeLog.md']
14
14
  s.require_path = 'lib'
15
15
 
16
16
  s.author = 'Andrey "A.I." Sitnik'
17
17
  s.email = 'andrey@sitnik.ru'
18
18
  s.homepage = 'https://github.com/ai/autoprefixer-rails'
19
- s.license = 'LGPL-3'
19
+ s.license = 'MIT'
20
20
 
21
21
  s.add_dependency "execjs", [">= 0"]
22
22
  end
@@ -1,62 +1,38 @@
1
- =begin
2
- Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
3
- sponsored by Evil Martians.
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU Lesser General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- =end
18
-
19
1
  require 'pathname'
20
2
 
21
3
  # Ruby integration with Autoprefixer JS library, which parse CSS and adds
22
4
  # only actual prefixed
23
5
  module AutoprefixerRails
24
- # Parse `css` and add vendor prefixes for `browsers`
25
- def self.compile(css, browsers = nil)
26
- compiler(browsers).compile(css)
6
+ autoload :Sprockets, 'autoprefixer-rails/sprockets'
7
+
8
+ # Add prefixes to `css`. See `Processor#process` for options.
9
+ def self.process(css, opts = { })
10
+ browsers = opts.delete(:browsers)
11
+ processor(browsers).process(css, opts)
27
12
  end
28
13
 
29
14
  # Add Autoprefixer for Sprockets environment in `assets`.
30
15
  # You can specify `browsers` actual in your project.
31
16
  def self.install(assets, browsers = nil)
32
- instance = compiler(browsers)
33
- assets.register_postprocessor 'text/css', :autoprefixer do |context, css|
34
- if defined?(Sass::Rails) or defined?(Sprockets::Sass)
35
- begin
36
- instance.compile(css)
37
- rescue ExecJS::ProgramError => e
38
- if e.message =~ /Can't parse CSS/
39
- css
40
- else
41
- raise e
42
- end
43
- end
44
- else
45
- instance.compile(css)
46
- end
47
- end
17
+ Sprockets.new( processor(browsers) ).install(assets)
48
18
  end
49
19
 
50
- # Cache compiler instances
51
- def self.compiler(browsers)
20
+ # Cache processor instances
21
+ def self.processor(browsers=nil)
52
22
  @cache ||= { }
53
- @cache[browsers] ||= Compiler.new(browsers)
23
+ @cache[browsers] ||= Processor.new(browsers)
24
+ end
25
+
26
+ # Deprecated method. Use `process` instead.
27
+ def self.compile(css, browsers = nil)
28
+ processor(browsers).compile(css)
54
29
  end
55
30
  end
56
31
 
57
32
  dir = Pathname(__FILE__).dirname.join('autoprefixer-rails')
58
33
 
34
+ require dir.join('result').to_s
59
35
  require dir.join('version').to_s
60
- require dir.join('compiler').to_s
36
+ require dir.join('processor').to_s
61
37
 
62
38
  require dir.join('railtie').to_s if defined?(Rails)
@@ -0,0 +1,90 @@
1
+ require 'execjs'
2
+
3
+ module AutoprefixerRails
4
+ # Ruby to JS wrapper for Autoprefixer processor instance
5
+ class Processor
6
+ def initialize(browsers=nil)
7
+ @browsers = browsers || []
8
+ end
9
+
10
+ # Process `css` and return result.
11
+ #
12
+ # Options can be:
13
+ # * `from` with input CSS file name. Will be used in error messages.
14
+ # * `to` with output CSS file name.
15
+ # * `map` with true to generate new source map or with previous map.
16
+ def process(css, opts = { })
17
+ result = processor.call('process', css, opts)
18
+ Result.new(result['css'], result['map'])
19
+ end
20
+
21
+ # Return, which browsers and prefixes will be used
22
+ def info
23
+ processor.call('info')
24
+ end
25
+
26
+ # Lazy load for JS instance
27
+ def processor
28
+ @processor ||= ExecJS.compile(build_js)
29
+ end
30
+
31
+ # Deprecated method. Use `process` instead.
32
+ def compile(css)
33
+ warn 'autoprefixer-rails: Replace compile() to process(). ' +
34
+ 'Method compile() is deprecated and will be removed in 1.1.'
35
+ processor.call('process', css)['css']
36
+ end
37
+
38
+ private
39
+
40
+ # Print warning to logger or STDERR
41
+ def warn(message)
42
+ $stderr.puts(message)
43
+ end
44
+
45
+ # Cache autoprefixer.js content
46
+ def read_js
47
+ @@js ||= Pathname(__FILE__).join("../../../vendor/autoprefixer.js").read
48
+ end
49
+
50
+ # Return processor JS with some extra methods
51
+ def build_js
52
+ create_global + read_js + create_instance +
53
+ process_proxy + info_proxy
54
+ end
55
+
56
+ # Return JS code to create `global` namespace
57
+ def create_global
58
+ 'var global = this;'
59
+ end
60
+
61
+ # Return JS code to create Autoprefixer instance
62
+ def create_instance
63
+ if @browsers.empty?
64
+ "var processor = autoprefixer;"
65
+ else
66
+ browsers = @browsers.map(&:to_s).join("', '")
67
+ "var processor = autoprefixer('#{browsers}');"
68
+ end
69
+ end
70
+
71
+ # Return JS code for process method proxy
72
+ def process_proxy
73
+ <<-JS
74
+ var process = function() {
75
+ var result = processor.process.apply(processor, arguments);
76
+ return { css: result.css, map: result.map };
77
+ };
78
+ JS
79
+ end
80
+
81
+ # Return JS code for info method proxy
82
+ def info_proxy
83
+ <<-JS
84
+ var info = function() {
85
+ return processor.info.apply(processor);
86
+ };
87
+ JS
88
+ end
89
+ end
90
+ end
@@ -1,21 +1,3 @@
1
- =begin
2
- Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
3
- sponsored by Evil Martians.
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU Lesser General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- =end
18
-
19
1
  begin
20
2
  require 'sprockets/railtie'
21
3
 
@@ -0,0 +1,20 @@
1
+ module AutoprefixerRails
2
+ # Container of prefixed CSS and source map with changes
3
+ class Result
4
+ # Prefixed CSS after Autoprefixer
5
+ attr_reader :css
6
+
7
+ # Source map of changes
8
+ attr_reader :map
9
+
10
+ def initialize(css, map)
11
+ @css = css
12
+ @map = map
13
+ end
14
+
15
+ # Stringify prefixed CSS
16
+ def to_s
17
+ @css
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,56 @@
1
+ module AutoprefixerRails
2
+ # Register autoprefixer postprocessor in Sprockets and fix common issues
3
+ class Sprockets
4
+ def initialize(processor)
5
+ @processor = processor
6
+ end
7
+
8
+ # Add prefixes for `css`
9
+ def process(context, css)
10
+ root = Pathname.new(context.root_path)
11
+ input = context.pathname.relative_path_from(root).to_s
12
+ output = input.chomp(File.extname(input)) + '.css'
13
+
14
+ @processor.process(css, from: input, to: output).css
15
+ end
16
+
17
+ # Add prefixes only if in `content` will be CSS.
18
+ def process_only_css(context, content)
19
+ begin
20
+ process(context, content)
21
+ rescue ExecJS::ProgramError => e
22
+ if e.message =~ /Can't parse CSS/
23
+ content
24
+ else
25
+ raise e
26
+ end
27
+ end
28
+ end
29
+
30
+ # Register postprocessor in Sprockets depend on issues with other gems
31
+ def install(assets)
32
+ if ignore_syntax_error?
33
+ register(assets) { |context, css| process_only_css(context, css) }
34
+ else
35
+ register(assets) { |context, css| process(context, css) }
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # Add `block` as `assets` postprocessor
42
+ def register(assets, &block)
43
+ assets.register_postprocessor('text/css', :autoprefixer, &block)
44
+ end
45
+
46
+ # Return true if broken sass-rails is loaded
47
+ def ignore_syntax_error?
48
+ return false unless defined? Sass::Rails
49
+
50
+ fixed = Gem::Version.new('4.0.1')
51
+ current = Gem::Version.new(Sass::Rails::VERSION)
52
+
53
+ current < fixed
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module AutoprefixerRails
2
- VERSION = '0.8.20131213'.freeze unless defined? AutoprefixerRails::VERSION
2
+ VERSION = '1.0.20131222'.freeze unless defined? AutoprefixerRails::VERSION
3
3
  end
@@ -1,21 +1,3 @@
1
- =begin
2
- Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
3
- sponsored by Evil Martians.
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU Lesser General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- =end
18
-
19
1
  require 'rake'
20
2
  require 'rake/tasklib'
21
3
  require 'autoprefixer-rails'
@@ -30,15 +12,15 @@ module Rake
30
12
 
31
13
  def initialize(browsers = [])
32
14
  @browsers = browsers
33
- @compiler = AutoprefixerRails.compiler(@browsers)
15
+ @processor = AutoprefixerRails.processor(@browsers)
34
16
  define
35
17
  end
36
18
 
37
19
  def define
38
20
  namespace :autoprefixer do
39
21
  desc 'Show selected browsers and prefixed CSS properties and values'
40
- task :inspect do
41
- puts @compiler.inspect
22
+ task :info do
23
+ puts @processor.info
42
24
  end
43
25
  end
44
26
  end
@@ -0,0 +1,2 @@
1
+ a
2
+ transition: all 1s
@@ -0,0 +1 @@
1
+ @import "loaded"
@@ -1,6 +1,6 @@
1
1
  class CssController < ApplicationController
2
2
  def test
3
3
  file = params[:file] + '.css'
4
- render :text => Rails.application.assets[file]
4
+ render text: Rails.application.assets[file]
5
5
  end
6
6
  end
@@ -4,7 +4,7 @@ require "action_controller/railtie"
4
4
  require "sprockets/railtie"
5
5
 
6
6
  if defined?(Bundler)
7
- Bundler.require(*Rails.groups(:assets => %w(development test)))
7
+ Bundler.require(*Rails.groups(assets: %w(development test)))
8
8
  end
9
9
 
10
10
  module App