rack-html5 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +15 -15
- data/VERSION +1 -1
- data/lib/rack/html5.rb +22 -25
- data/rack-html5.gemspec +5 -3
- data/rake/jeweler.rb +1 -1
- data/test/rack/html5_test.rb +48 -10
- metadata +5 -3
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Christian Felder
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -14,24 +14,24 @@ Rack::Html5 detects the browser and its version by parsing the user agent. It th
|
|
14
14
|
|
15
15
|
Rack::Html5 then sets the following HTTP headers:
|
16
16
|
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
22
|
-
*
|
23
|
-
*
|
24
|
-
*
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
30
|
-
*
|
17
|
+
* HTTP_X_DETECTED_BROWSER: Browser that has been DETECTED, eg.: Firefox
|
18
|
+
* HTTP_X_DETECTED_VERSION: Version of the browser that has been DETECTED, eg.: 3.6.6
|
19
|
+
* HTTP_X_SUPPORTS_HTML5_WYSIWYG: WYSIWYG editable elements
|
20
|
+
* HTTP_X_SUPPORTS_HTML5_CLASSNAME: getElementsByClassName
|
21
|
+
* HTTP_X_SUPPORTS_HTML5_ELEMENTS: Stylable HTML5 elements
|
22
|
+
* HTTP_X_SUPPORTS_HTML5_CANVAS: Canvas (basic support)
|
23
|
+
* HTTP_X_SUPPORTS_HTML5_MESSAGING: Cross-document messaging
|
24
|
+
* HTTP_X_SUPPORTS_HTML5_AUDIO: Audio element
|
25
|
+
* HTTP_X_SUPPORTS_HTML5_VIDEO: Video element
|
26
|
+
* HTTP_X_SUPPORTS_HTML5_TEXTAPI: Text API for canvas
|
27
|
+
* HTTP_X_SUPPORTS_HTML5_DRAGANDDROP: Drag and drop
|
28
|
+
* HTTP_X_SUPPORTS_HTML5_OFFLINE: Offline web applications
|
29
|
+
* HTTP_X_SUPPORTS_HTML5_SVG: Inline SVG
|
30
|
+
* HTTP_X_SUPPORTS_HTML5_FORMS: Form features (Web Forms 2.0)
|
31
31
|
|
32
32
|
== Rails
|
33
33
|
|
34
|
-
|
34
|
+
The Rack-Html5-rails_helper gem provides Rails helper methods, so you don't have to read the headers by yourself: http://github.com/masone/rack-html5-rails_helper
|
35
35
|
|
36
36
|
=== Configuration for Rails 2
|
37
37
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/rack/html5.rb
CHANGED
@@ -4,50 +4,49 @@ module Rack # :nodoc:
|
|
4
4
|
# It does this by parsing the user agent and matching the features to the browser version based on information provided on: http://caniuse.com/#eras=farpast,past,now&cats=HTML5&statuses=rec,pr,cr,wd,ietf&nodetails=1
|
5
5
|
#
|
6
6
|
# The headers that are being set:
|
7
|
-
# *
|
8
|
-
# *
|
9
|
-
# *
|
10
|
-
# *
|
11
|
-
# *
|
12
|
-
# *
|
13
|
-
# *
|
14
|
-
# *
|
15
|
-
# *
|
16
|
-
# *
|
17
|
-
# *
|
18
|
-
# *
|
19
|
-
# *
|
20
|
-
# *
|
7
|
+
# * HTTP_X_DETECTED_BROWSER: Browser that has been DETECTED, eg.: Firefox
|
8
|
+
# * HTTP_X_DETECTED_VERSION: Version of the browser that has been DETECTED, eg.: 3.6.6
|
9
|
+
# * HTTP_X_SUPPORTS_HTML5_WYSIWYG: WYSIWYG editable elements
|
10
|
+
# * HTTP_X_SUPPORTS_HTML5_CLASSNAME: getElementsByClassName
|
11
|
+
# * HTTP_X_SUPPORTS_HTML5_ELEMENTS: Stylable HTML5 elements
|
12
|
+
# * HTTP_X_SUPPORTS_HTML5_CANVAS: Canvas (basic support)
|
13
|
+
# * HTTP_X_SUPPORTS_HTML5_MESSAGING: Cross-document messaging
|
14
|
+
# * HTTP_X_SUPPORTS_HTML5_AUDIO: Audio element
|
15
|
+
# * HTTP_X_SUPPORTS_HTML5_VIDEO: Video element
|
16
|
+
# * HTTP_X_SUPPORTS_HTML5_TEXTAPI: Text API for canvas
|
17
|
+
# * HTTP_X_SUPPORTS_HTML5_DRAGANDDROP: Drag and drop
|
18
|
+
# * HTTP_X_SUPPORTS_HTML5_OFFLINE: Offline web applications
|
19
|
+
# * HTTP_X_SUPPORTS_HTML5_SVG: Inline SVG
|
20
|
+
# * HTTP_X_SUPPORTS_HTML5_FORMS: Form features (Web Forms 2.0)
|
21
21
|
#
|
22
22
|
# Please note:
|
23
23
|
# * If the feature is not supported, the header will not be set.
|
24
24
|
# * If a browser implements a feature only partially, the corresponding header will not be set.
|
25
25
|
class Html5
|
26
|
-
attr_accessor :version, :browser, :user_agent, :features, :
|
26
|
+
attr_accessor :version, :browser, :user_agent, :features, :env
|
27
27
|
|
28
28
|
def initialize(app)
|
29
29
|
@app = app
|
30
|
+
@features = []
|
30
31
|
end
|
31
32
|
|
32
33
|
def generate_headers
|
33
|
-
|
34
|
-
|
34
|
+
@env['HTTP_X_DETECTED_VERSION'] = version
|
35
|
+
@env['HTTP_X_DETECTED_BROWSER'] = browser.to_s
|
35
36
|
@features.each do |feature|
|
36
|
-
|
37
|
+
@env["HTTP_X_SUPPORTS_HTML5_#{feature.upcase}"] = "true"
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
41
|
def call(env)
|
41
|
-
|
42
|
-
@user_agent = env['HTTP_USER_AGENT']
|
43
|
-
@features = []
|
44
|
-
@headers = headers
|
42
|
+
@env = env
|
43
|
+
@user_agent = @env['HTTP_USER_AGENT']
|
45
44
|
|
46
45
|
detect_browser
|
47
46
|
detect_features
|
48
47
|
generate_headers
|
49
48
|
|
50
|
-
|
49
|
+
@app.call(@env)
|
51
50
|
end
|
52
51
|
|
53
52
|
# Detects the browser and version based on the user agent
|
@@ -82,8 +81,6 @@ module Rack # :nodoc:
|
|
82
81
|
def comparable_version(v)
|
83
82
|
v.split(".")[0..1].join
|
84
83
|
end
|
85
|
-
|
86
|
-
private
|
87
84
|
|
88
85
|
# Feature to browser version mapping according to the information provided on: http://caniuse.com/#eras=farpast,past,now&cats=HTML5&statuses=rec,pr,cr,wd,ietf&nodetails=1
|
89
86
|
def feature_mapping
|
data/rack-html5.gemspec
CHANGED
@@ -5,18 +5,20 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-html5}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Christian Felder (masone)"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-15}
|
13
13
|
s.description = %q{Rack::Html5 sets custom headers for each HTML5 feature the browser supports.}
|
14
14
|
s.email = %q{ema@rh-productions.ch}
|
15
15
|
s.extra_rdoc_files = [
|
16
|
-
"
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
17
18
|
]
|
18
19
|
s.files = [
|
19
20
|
".gitignore",
|
21
|
+
"LICENSE",
|
20
22
|
"README.rdoc",
|
21
23
|
"Rakefile",
|
22
24
|
"VERSION",
|
data/rake/jeweler.rb
CHANGED
@@ -7,7 +7,7 @@ begin
|
|
7
7
|
s.email = "ema@rh-productions.ch"
|
8
8
|
s.homepage = "http://github.com/masone/rack-html5"
|
9
9
|
s.authors = ["Christian Felder (masone)"]
|
10
|
-
s.add_development_dependency "shoulda"
|
10
|
+
s.add_development_dependency "shoulda"
|
11
11
|
end
|
12
12
|
Jeweler::GemcutterTasks.new
|
13
13
|
rescue LoadError
|
data/test/rack/html5_test.rb
CHANGED
@@ -90,28 +90,66 @@ class Rack::Html5Test < Test::Unit::TestCase
|
|
90
90
|
|
91
91
|
context "headers" do
|
92
92
|
|
93
|
-
should "set the
|
93
|
+
should "set the HTTP_X_DETECTED_VERSION header to 5.0.307.11" do
|
94
94
|
env = { 'HTTP_USER_AGENT' => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9" }
|
95
|
-
|
96
|
-
assert_equal "5.0.307.11",
|
95
|
+
@rack.call(env)
|
96
|
+
assert_equal "5.0.307.11", @rack.env['HTTP_X_DETECTED_VERSION']
|
97
97
|
end
|
98
98
|
|
99
|
-
should "set the
|
99
|
+
should "set the HTTP_X_DETECTED_BROWSER header to " do
|
100
100
|
env = { 'HTTP_USER_AGENT' => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9" }
|
101
|
-
|
102
|
-
assert_equal "chrome",
|
101
|
+
@rack.call(env)
|
102
|
+
assert_equal "chrome", @rack.env['HTTP_X_DETECTED_BROWSER']
|
103
103
|
end
|
104
104
|
|
105
|
-
should "set the
|
105
|
+
should "set the HTTP_X_SUPPORTS_HTML5_ELEMENTS header to true for Firefox 5.0" do
|
106
106
|
env = { 'HTTP_USER_AGENT' => "Mozilla/5.0 (X11; U; Darwin Power Macintosh; en-US; rv:1.8.0.12) Gecko/20070803 Firefox/5.0.10 Fink Community Edition" }
|
107
|
-
|
108
|
-
assert_equal "true",
|
107
|
+
@rack.call(env)
|
108
|
+
assert_equal "true", @rack.env['HTTP_X_SUPPORTS_HTML5_ELEMENTS']
|
109
109
|
end
|
110
110
|
|
111
111
|
should "not include the x headers if user agent cannot be detected properly" do
|
112
112
|
env = { 'HTTP_USER_AGENT' => "Mozilla/5.0 Gecko/20070803 Notabrowser/9.9.99" }
|
113
113
|
status, headers, response = @rack.call(env)
|
114
|
-
assert_equal false,
|
114
|
+
assert_equal false, @rack.env.has_key?('HTTP_X_SUPPORTS_HTML5_WYSIWYG')
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
context "feature_mapping" do
|
119
|
+
|
120
|
+
setup do
|
121
|
+
@features = [:wysiwyg, :classname, :elements, :canvas, :messaging, :audio, :video, :textapi, :draganddrop, :offline, :forms, :svg]
|
122
|
+
end
|
123
|
+
|
124
|
+
should "map exactly the same number of elements as expected" do
|
125
|
+
@rack.feature_mapping.each do |browser, features|
|
126
|
+
assert_equal @features.length, features.keys.length, "Wrong number of elements for #{browser}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
should "contain all necessary elements for each browser" do
|
131
|
+
@rack.feature_mapping.each do |browser, features|
|
132
|
+
@features.each do |feature|
|
133
|
+
assert features.has_key?(feature), "Element #{feature} is missing for #{browser}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "comparable version" do
|
140
|
+
|
141
|
+
should "return 105 for 10.5" do
|
142
|
+
assert_equal "105", @rack.comparable_version("10.5")
|
143
|
+
end
|
144
|
+
|
145
|
+
should "return 1050 for 10.50.2.0" do
|
146
|
+
assert_equal "1050", @rack.comparable_version("10.50.2.0")
|
147
|
+
end
|
148
|
+
|
149
|
+
should "return 7 for 7" do
|
150
|
+
assert_equal "7", @rack.comparable_version("7")
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
117
155
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Christian Felder (masone)
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-15 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -37,9 +37,11 @@ executables: []
|
|
37
37
|
extensions: []
|
38
38
|
|
39
39
|
extra_rdoc_files:
|
40
|
+
- LICENSE
|
40
41
|
- README.rdoc
|
41
42
|
files:
|
42
43
|
- .gitignore
|
44
|
+
- LICENSE
|
43
45
|
- README.rdoc
|
44
46
|
- Rakefile
|
45
47
|
- VERSION
|