aprescott / rack-preview

Manipulate page preview thumbnails for your Rack app.

Home Page:https://github.com/aprescott/rack-preview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Manipulate page preview thumbnails for your Rack app.

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

License:MIT License


Languages

Language:Ruby 100.0%