Skip to content

Instantly share code, notes, and snippets.

@lotsofcode
Created June 25, 2014 11:23
Show Gist options
  • Select an option

  • Save lotsofcode/445ccf33e65ad8b255ba to your computer and use it in GitHub Desktop.

Select an option

Save lotsofcode/445ccf33e65ad8b255ba to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'premailer'
require 'json'
configure :production do
set :port, 80
end
get '/premailer' do
<<-eos
<form method="POST">
<textarea name="html"></textarea>
<button>Submit</button>
<input type="hidden" name="with_warnings" value="1"/>
</form>
eos
end
post '/premailer' do
error 400 if !params[:html]
with_warnings = params[:with_warnings] == '1' ? true : false
html = params[:html]
premailer = Premailer.new(html, :warn_level => Premailer::Warnings::SAFE, :with_html_string => true)
content_type :json
data = {:html => premailer.to_inline_css}
data[:warnings] = premailer.warnings if with_warnings
data.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment