Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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