0.0
No commit activity in last 3 years
No release in over 3 years
Manipulate page preview thumbnails for your Rack app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

Rack::Preview

Rack::Preview is a simple piece of Rack middleware to let you serve a different response to requests made as part of Safari's Top Sites and Opera's Speed Dial thumbnail previews, by hooking into the X-Purpose: preview HTTP header.

To see the effect, check Martin Sutherland's write-up for Safari. Opera's dev blog also has more.

Installation

To install from RubyGems:

gem install rack-preview

To get the source:

git clone https://github.com/aprescott/rack-preview.git

Example

require "rack/preview"

Rack::Server.start(app: Rack::Builder.app do
  use Rack::Preview, %Q{<h1 style="font-size: 10em;">Welcome to the preview!</h1>}

  run lambda { |env| [200, { "Content-Type" => "text/html" }, ["Hello world!"]] }
end)
# Regular response.
$ curl http://localhost:8080/
Hello world!

# Responses to requests with X-Purpose
# from the relevant browsers.
$ curl -H "X-Purpose: preview" --user-agent "Safari" http://localhost:8080/
<h1 style="font-size: 10em;">Welcome to the preview!</h1>

Contribute

  • Fork it
  • Make a new feature branch: git checkout -b some-new-thing master
  • Hack away and write tests that pass
  • Pull request