Created
July 18, 2014 18:18
-
-
Save SebAshton/2f039c350b5b1c88ef3b to your computer and use it in GitHub Desktop.
A shell script to inline html styles from a static html page. requires premailer.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "premailer" | |
require "optparse" | |
OptionParser.new do |o| | |
o.on('-d OUTPUT_FOLDER') { |b| $destination = b } | |
o.on('-o OUTPUT_FILENAME') { |b| $output = b } | |
o.on('-f INPUT_FILENAME') { |filename| $filename = filename } | |
o.on('-h') { puts o; exit } | |
o.parse! | |
end | |
unless File.directory?("./build") | |
p "Bro... Seriously trying to run this without building the middleman!?" | |
exit | |
end | |
unless File.exist?("./build/#{$filename}") | |
p "Can't find that email, sorry bro" | |
exit | |
end | |
premailer = Premailer.new("./build/#{$filename}", :warn_level => Premailer::Warnings::SAFE) | |
output_dir = $destination || "email" | |
output_filename = $output || $filename | |
if !File.directory?("#{Dir.pwd}/#{output_dir}") | |
Dir.mkdir("#{Dir.pwd}/#{output_dir}") | |
end | |
output_path = "#{Dir.pwd}/#{output_dir}/#{output_filename}" | |
p output_path | |
File.open(output_path, "w") do |fout| | |
fout.puts premailer.to_inline_css | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment