Created
March 15, 2016 20:53
-
-
Save solarsailer/e2c9d7bef3ba06984ca1 to your computer and use it in GitHub Desktop.
Jekyll Autoprefixer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# 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 | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# 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