Previews raw HTML source as HTML. Useful for showing raw HTML from pastie services or gists in more readable formatted form.
Simply run it as a rack app and add ?url=<your-gist-url> in order to preview it.
| .rvmrc | |
| .bundle |
| #!/usr/bin/env rackup | |
| # encoding: utf-8 | |
| require "open-uri" | |
| class Preview | |
| def call(env) | |
| request = Rack::Request.new(env) | |
| if url = request.params["url"] | |
| data = open(url, &:read) | |
| body = <<-EOF | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| </head> | |
| <body> | |
| #{data} | |
| <footer>From <a href="#{url}">#{url}</a>. Powered by <a href="https://gist.github.com/913640">Gist 913640</a>.</footer> | |
| </body> | |
| </html> | |
| EOF | |
| [200, {"Content-Length" => body.bytesize.to_s, "Content-Type" => "text/html"}, [body]] | |
| else | |
| body = <<-EOF | |
| <h1>Not Found</h1> | |
| <p> | |
| You have to provide <code>?url=url_with_raw_html_data</code> in order to preview it as HTML! | |
| </p> | |
| EOF | |
| [404, {"Content-Length" => body.bytesize.to_s, "Content-Type" => "text/html"}, [body]] | |
| end | |
| end | |
| end | |
| map "/preview" do | |
| run Preview.new | |
| end |
| # encoding: utf-8 | |
| source "http://gemcutter.org" | |
| gem "rack" |
| #!/bin/sh | |
| ROOT=/webs/services/preview | |
| PIDFILE=/var/run/preview.pid | |
| start () { | |
| $ROOT/config.ru --port=1001 --env=production --daemonize --pid $PIDFILE | |
| } | |
| stop () { | |
| kill -9 $(cat $PIDFILE) | |
| } | |
| case "$1" in | |
| start|"") | |
| start ;; | |
| restart) | |
| stop && start ;; | |
| stop) | |
| stop ;; | |
| *) | |
| echo "Usage: $0 [start|restart|stop]" >&2 | |
| exit 1 | |
| ;; | |
| esac |