rack-preview 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://www.rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (MIT License)
2
+
3
+ Copyright (c) 2010 Adam Prescott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # Rack::Preview
2
+
3
+ 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.
4
+
5
+ To see the effect, check [Martin Sutherland's write-up for Safari](http://sunpig.com/martin/archives/2010/01/08/how-to-detect-a-page-request-from-safari-4s-top-sites-feature.html). [Opera's dev blog](http://dev.opera.com/articles/view/opera-speed-dial-enhancements/#with-x-purpose) also has more.
6
+
7
+ # Installation
8
+
9
+ To install from RubyGems:
10
+
11
+ gem install rack-preview
12
+
13
+ To get the source:
14
+
15
+ git clone https://github.com/aprescott/rack-preview.git
16
+
17
+ # Example
18
+
19
+ use Rack::Preview, [%Q{<h1 style="font-size: 10em;">Welcome to the preview!</h1>}]
20
+
21
+ run lambda { |env| [200, { "Content-Type" => "text/html" }, ["Hello world!"]] }
22
+
23
+ # Contribute
24
+
25
+ * Fork it
26
+ * Make a new feature branch: `git checkout -b some-new-thing master`
27
+ * Hack away and write tests that pass
28
+ * Pull request
@@ -0,0 +1 @@
1
+ require "rack/preview"
@@ -0,0 +1,26 @@
1
+ # Copyright (c) 2010 Adam Prescott
2
+ # Licensed under the MIT license. See LICENSE.
3
+
4
+ require "rack"
5
+
6
+ class Rack::Preview
7
+ def initialize(app, preview_body = nil, &block)
8
+ @app = app
9
+ @preview = (preview_body ? [preview_body] : block.call)
10
+ end
11
+
12
+ def call(env)
13
+ status, headers, response = @app.call(env)
14
+
15
+ previewing = env["HTTP_X_PURPOSE"] =~ /preview/i # note http://code.google.com/p/chromium/issues/detail?id=80824
16
+ ua_string = env["HTTP_USER_AGENT"]
17
+ safari_preview = ua_string !~ /Chrome/ && ua_string =~ /Safari/ # Chrome sends "Safari" in its UA
18
+ opera_preview = ua_string =~ /Opera/ # Opera documentation says they'll send X-Purpose: preview
19
+
20
+ if previewing && (safari_preview || opera_preview)
21
+ [status, headers, @preview]
22
+ else
23
+ [status, headers, response]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rack-preview"
3
+ s.version = "0.0.1"
4
+ s.authors = ["Adam Prescott"]
5
+ s.email = ["adam@aprescott.com"]
6
+ s.homepage = "https://github.com/aprescott/rack-preview"
7
+ s.summary = "Manipulate page preview thumbnails for your Rack app."
8
+ s.description = "Manipulate page preview thumbnails for your Rack app."
9
+ s.files = Dir["{lib/**/*}"] + %w[rack-preview.gemspec LICENSE Gemfile README.md]
10
+ s.require_path = "lib"
11
+ s.test_files = Dir["test/*"]
12
+ s.add_dependency "rack"
13
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-preview
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Adam Prescott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-19 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: Manipulate page preview thumbnails for your Rack app.
27
+ email:
28
+ - adam@aprescott.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - lib/rack-preview.rb
37
+ - lib/rack/preview.rb
38
+ - rack-preview.gemspec
39
+ - LICENSE
40
+ - Gemfile
41
+ - README.md
42
+ homepage: https://github.com/aprescott/rack-preview
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.2
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Manipulate page preview thumbnails for your Rack app.
69
+ test_files: []
70
+