×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Ruby
Posted by: calaverse
Added: Jan 21, 2015 9:11 PM
Modified: Apr 12, 2015 4:19 AM
Views: 15
1. Run: gem install autoprefixer-rails
2. Add the lines below to the compass config.rb file
  1. =begin
  2. Automatically adds browser extensions to sass/compass
  3. May be used with compass watch
  4.  
  5. Example.
  6. Original CSS:
  7.  
  8. #id {
  9.   transform: translateY(5%);
  10. }
  11.  
  12. After AutoprefixerRails:
  13.  
  14. #id {
  15.   -webkit-transform: translateY(5%);
  16.       -ms-transform: translateY(5%);
  17.           transform: translateY(5%);
  18. }
  19.  
  20. https://github.com/ai/autoprefixer-rails
  21. http://compass-style.org/help/documentation/configuration-reference/#callbacks
  22. =end
  23.  
  24. require "autoprefixer-rails"
  25.  
  26. on_stylesheet_saved do |file|
  27.   css = File.read(file)
  28.   map = file + '.map'
  29.  
  30.   if File.exists? map
  31.     result = AutoprefixerRails.process(css,
  32.       from: file,
  33.       to:   file,
  34.       map:  { prev: map, inline: false })
  35.     File.open(file, 'w') { |io| io << result.css }
  36.     File.open(map,  'w') { |io| io << result.map }
  37.   else
  38.     File.open(file, 'w') { |io| io << AutoprefixerRails.process(css) }
  39.   end
  40. end