Created
June 25, 2014 11:23
-
-
Save lotsofcode/445ccf33e65ad8b255ba to your computer and use it in GitHub Desktop.
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
| 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