Skip to content

Instantly share code, notes, and snippets.

@alexdunae
Last active April 19, 2019 06:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdunae/c6ec418fb166fdebc42b to your computer and use it in GitHub Desktop.
Save alexdunae/c6ec418fb166fdebc42b to your computer and use it in GitHub Desktop.
Guard + sass + autoprefixer
source 'https://rubygems.org/'
gem 'guard'
gem 'guard-sass', git: 'git@github.com:alexdunae/guard-sass.git'
gem 'autoprefixer-rails'
require 'autoprefixer-rails'
guard :sass, {
input: 'www/wp-content/themes/example/css',
output: 'www/wp-content/themes/example',
style: :compressed,
smart_partials: true,
all_on_start: true
} do
callback(:run_on_changes_end) do |_, _, files|
Array(files).each do |file|
time = Benchmark.realtime { autoprefix_file(file) }
benchmark = "[\e[33m%2.2fs\e[0m] " % time
::Guard::UI.info("\t\e[1;37mAutoprefixer\e[0m %s%s" % [benchmark, file])
end
end
end
def autoprefix_file(file)
original_css = File.read(file)
File.open(file, 'w') do |io|
io << ::AutoprefixerRails.process(original_css, browsers: ['> 1%', 'ie >= 7'])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment