Skip to content

Instantly share code, notes, and snippets.

@ku1ik
Created May 8, 2009 19:01
Show Gist options
  • Save ku1ik/108935 to your computer and use it in GitHub Desktop.
Save ku1ik/108935 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'tidy'
require 'sinatra'
module Rack
class Tidy
def initialize(app)
@app = app
::Tidy.path = "/usr/lib/libtidy-0.99.so.0" # or "/usr/lib/libtidy.A.dylib" on Mac
end
def call(env)
status, headers, content = @app.call(env)
::Tidy.open(:show_warnings => true, "char-encoding" => "utf8") do |tidy|
tidy.clean(content)
puts tidy.errors
puts tidy.diagnostics
end
[status, headers, content]
end
end
end
get '/' do
"<html><head><title>T1TL3</title></head><body>OHAI!<p>yikes!</div></body></html>"
end
use Rack::Tidy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment