Skip to content

Instantly share code, notes, and snippets.

@solarsailer
Created March 15, 2016 20:53
Show Gist options
  • Save solarsailer/e2c9d7bef3ba06984ca1 to your computer and use it in GitHub Desktop.
Save solarsailer/e2c9d7bef3ba06984ca1 to your computer and use it in GitHub Desktop.
Jekyll Autoprefixer
# ...
# In the _config.yml, add the code below to set the destination folder of the autoprefixer plugin.
# If no folder is set, the destination will be Jekyll's default.
autoprefixer:
dir: /path/to/css
# ...
# Forked from: https://github.com/octopress/autoprefixer/blob/master/lib/octopress-autoprefixer.rb
require 'autoprefixer-rails'
require 'find'
module AutoPrefixer
Jekyll::Hooks.register :site, :post_write, priority: :low do |site|
AutoPrefixer.process(site)
end
def self.find_stylesheets(dir)
return [] unless Dir.exist? dir
Find.find(dir).to_a.reject { |f| File.extname(f) != '.css' }
end
def self.process(site)
# Get config.
config = site.config['autoprefixer'] || {}
target_dir = config['dir'] || ''
find_stylesheets(site.config['destination'] + target_dir).each do |file|
prefix(file)
end
end
def self.prefix(stylesheet)
content = File.open(stylesheet).read
File.open(stylesheet, 'w') do |f|
f.write(AutoprefixerRails.process(content))
end
end
end
# ...
# Add this to your Gemfile:
gem 'autoprefixer-rails'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment