Last active
August 29, 2015 14:05
-
-
Save egid/18f497fb87e91cf10c49 to your computer and use it in GitHub Desktop.
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
require 'premailer' | |
### | |
# Helpers | |
### | |
# Integrated Premailer from https://github.com/RyanParsley/OMP-Generator/blob/master/config.rb | |
# Premailer API: http://premailer.dialect.ca/api | |
module PreMailer | |
class << self | |
def registered(app) | |
require 'premailer' | |
app.after_build do |builder| | |
prefix = build_dir + File::SEPARATOR | |
Dir.chdir(build_dir) do | |
Dir.glob('**/*.html') do |file| | |
premailer = Premailer.new(file, :warn_level => Premailer::Warnings::SAFE, :adapter => :nokogiri, :preserve_styles => false, :remove_comments => false, :remove_ids => true, :'query-string' => '') | |
fileout = File.open(file, 'w') | |
fileout.puts premailer.to_inline_css | |
fileout.close | |
premailer.warnings.each do |w| | |
builder.say_status :premailer, "#{w[:message]} (#{w[:level]}) may not render properly in #{w[:clients]}" | |
end | |
builder.say_status :premailer, prefix+file | |
end | |
end | |
end | |
end | |
alias :included :registered | |
end | |
end | |
::Middleman::Extensions.register(:inline_premailer, PreMailer) | |
activate :inline_premailer | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment