browser 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg
2
+ coverage
3
+ doc
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://gems.simplesideias.com.br"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ browser (0.1.3)
5
+
6
+ GEM
7
+ remote: http://gems.simplesideias.com.br/
8
+ specs:
9
+ abstract (1.0.0)
10
+ actionpack (3.0.9)
11
+ activemodel (= 3.0.9)
12
+ activesupport (= 3.0.9)
13
+ builder (~> 2.1.2)
14
+ erubis (~> 2.6.6)
15
+ i18n (~> 0.5.0)
16
+ rack (~> 1.2.1)
17
+ rack-mount (~> 0.6.14)
18
+ rack-test (~> 0.5.7)
19
+ tzinfo (~> 0.3.23)
20
+ activemodel (3.0.9)
21
+ activesupport (= 3.0.9)
22
+ builder (~> 2.1.2)
23
+ i18n (~> 0.5.0)
24
+ activesupport (3.0.9)
25
+ builder (2.1.2)
26
+ erubis (2.6.6)
27
+ abstract (>= 1.0.0)
28
+ i18n (0.5.0)
29
+ rack (1.2.3)
30
+ rack-mount (0.6.14)
31
+ rack (>= 1.0.0)
32
+ rack-test (0.5.7)
33
+ rack (>= 1.0)
34
+ rake (0.9.2)
35
+ tzinfo (0.3.29)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ actionpack (~> 3.0)
42
+ browser!
43
+ rake (~> 0.9)
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
- require "rake/testtask"
2
- require "rake/rdoctask"
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
3
4
  require "./lib/browser/version"
4
5
 
6
+ require "rake/testtask"
5
7
  Rake::TestTask.new do |t|
6
8
  t.libs << "lib"
7
9
  t.libs << "test"
@@ -10,6 +12,7 @@ Rake::TestTask.new do |t|
10
12
  t.ruby_opts = %w[-rubygems]
11
13
  end
12
14
 
15
+ require "rdoc/task"
13
16
  Rake::RDocTask.new do |rdoc|
14
17
  rdoc.main = "README.rdoc"
15
18
  rdoc.rdoc_dir = "doc"
@@ -18,21 +21,3 @@ Rake::RDocTask.new do |rdoc|
18
21
  rdoc.rdoc_files.include("README.rdoc")
19
22
  rdoc.rdoc_files.include("lib/**/*.rb")
20
23
  end
21
-
22
- begin
23
- require "jeweler"
24
-
25
- Jeweler::Tasks.new do |gem|
26
- gem.name = "browser"
27
- gem.email = "fnando.vieira@gmail.com"
28
- gem.homepage = "http://github.com/fnando/browser"
29
- gem.authors = ["Nando Vieira"]
30
- gem.version = Browser::Version::STRING
31
- gem.summary = "Do some browser detection with Ruby."
32
- gem.files = FileList["README.rdoc", "{lib,test}/**/*", "Rakefile"]
33
- end
34
-
35
- Jeweler::GemcutterTasks.new
36
- rescue LoadError => e
37
- puts "You need to install jeweler to build this gem."
38
- end
data/browser.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "browser/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "browser"
7
+ s.version = Browser::Version::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nando Vieira"]
10
+ s.email = ["fnando.vieira@gmail.com"]
11
+ s.homepage = "http://github.com/fnando/browser"
12
+ s.summary = "Do some browser detection with Ruby."
13
+ s.description = s.summary
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "actionpack" , "~> 3.0"
21
+ s.add_development_dependency "rake" , "~> 0.9"
22
+ end
data/lib/browser.rb CHANGED
@@ -30,6 +30,8 @@ class Browser
30
30
 
31
31
  VERSION_REGEX = /(?:Version|MSIE|Opera|Firefox|Chrome|QuickTime|BlackBerry[^\/]+|CoreMedia v)[\/ ]?([a-z0-9.]+)/i
32
32
 
33
+ COMPATIBILITY_VIEW_REGEXP = /Trident\/([0-9.]+)/
34
+
33
35
  LANGUAGES = {
34
36
  "af" => "Afrikaans",
35
37
  "sq" => "Albanian",
@@ -200,7 +202,13 @@ class Browser
200
202
 
201
203
  # Return the full version.
202
204
  def full_version
203
- _, v = *ua.match(VERSION_REGEX)
205
+ if compatibility_view?
206
+ _, v = *ua.match(COMPATIBILITY_VIEW_REGEXP)
207
+ v.gsub!(/^([0-9])/) { $1.to_i + 4 }
208
+ else
209
+ _, v = *ua.match(VERSION_REGEX)
210
+ end
211
+
204
212
  v || "0.0"
205
213
  end
206
214
 
@@ -209,6 +217,10 @@ class Browser
209
217
  webkit? || firefox? || opera? || (ie? && version >= "7")
210
218
  end
211
219
 
220
+ def compatibility_view?
221
+ ie? && ua.match(COMPATIBILITY_VIEW_REGEXP)
222
+ end
223
+
212
224
  # Detect if browser is WebKit-based.
213
225
  def webkit?
214
226
  !!(ua =~ /AppleWebKit/i)
@@ -2,7 +2,7 @@ class Browser
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 2
5
+ PATCH = 3
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/test/browser_test.rb CHANGED
@@ -1,14 +1,4 @@
1
- require "test/unit"
2
-
3
- begin
4
- require "action_controller"
5
- rescue LoadError => e
6
- require "rubygems"
7
- require "action_controller"
8
- end
9
-
10
- require "browser"
11
-
1
+ require "test_helper"
12
2
 
13
3
  class BrowserTest < Test::Unit::TestCase
14
4
  IPHONE = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3"
@@ -18,7 +8,9 @@ class BrowserTest < Test::Unit::TestCase
18
8
  IE6 = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
19
9
  IE7 = "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)"
20
10
  IE8 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
11
+ IE8_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; Media Center PC 5.0; .NET CLR 3.5.21022)"
21
12
  IE9 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
13
+ IE9_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)"
22
14
  OPERA = "Opera/9.99 (Windows NT 5.1; U; pl) Presto/9.9.9"
23
15
  FIREFOX = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
24
16
  CHROME = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4"
@@ -149,6 +141,18 @@ class BrowserTest < Test::Unit::TestCase
149
141
  assert_equal "8", @browser.version
150
142
  end
151
143
 
144
+ def test_detect_ie8_in_compatibility_view
145
+ @browser.ua = IE8_COMPAT
146
+
147
+ assert_equal "Internet Explorer", @browser.name
148
+ assert @browser.ie?
149
+ assert @browser.ie8?
150
+ assert @browser.capable?
151
+ assert @browser.compatibility_view?
152
+ assert_equal "8.0", @browser.full_version
153
+ assert_equal "8", @browser.version
154
+ end
155
+
152
156
  def test_detect_ie9
153
157
  @browser.ua = IE9
154
158
 
@@ -160,6 +164,18 @@ class BrowserTest < Test::Unit::TestCase
160
164
  assert_equal "9", @browser.version
161
165
  end
162
166
 
167
+ def test_detect_ie9_in_compatibility_view
168
+ @browser.ua = IE9_COMPAT
169
+
170
+ assert_equal "Internet Explorer", @browser.name
171
+ assert @browser.ie?
172
+ assert @browser.ie9?
173
+ assert @browser.capable?
174
+ assert @browser.compatibility_view?
175
+ assert_equal "9.0", @browser.full_version
176
+ assert_equal "9", @browser.version
177
+ end
178
+
163
179
  def test_detect_opera
164
180
  @browser.ua = OPERA
165
181
 
@@ -0,0 +1,3 @@
1
+ require "test/unit"
2
+ require "action_controller"
3
+ require "browser"
metadata CHANGED
@@ -1,69 +1,86 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: browser
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 2
9
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Nando Vieira
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-10-28 00:00:00 -02:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description:
22
- email: fnando.vieira@gmail.com
12
+ date: 2011-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionpack
16
+ requirement: &70196031340500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70196031340500
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70196031339680 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70196031339680
36
+ description: Do some browser detection with Ruby.
37
+ email:
38
+ - fnando.vieira@gmail.com
23
39
  executables: []
24
-
25
40
  extensions: []
26
-
27
- extra_rdoc_files:
28
- - README.rdoc
29
- files:
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Gemfile.lock
30
46
  - README.rdoc
31
47
  - Rakefile
48
+ - browser.gemspec
32
49
  - lib/browser.rb
33
50
  - lib/browser/action_controller.rb
34
51
  - lib/browser/version.rb
35
52
  - test/browser_test.rb
36
- has_rdoc: true
53
+ - test/test_helper.rb
37
54
  homepage: http://github.com/fnando/browser
38
55
  licenses: []
39
-
40
56
  post_install_message:
41
- rdoc_options:
42
- - --charset=UTF-8
43
- require_paths:
57
+ rdoc_options: []
58
+ require_paths:
44
59
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
60
+ required_ruby_version: !ruby/object:Gem::Requirement
46
61
  none: false
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- segments:
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ segments:
51
67
  - 0
52
- version: "0"
53
- required_rubygems_version: !ruby/object:Gem::Requirement
68
+ hash: 1304431903925043845
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
70
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- segments:
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ segments:
59
76
  - 0
60
- version: "0"
77
+ hash: 1304431903925043845
61
78
  requirements: []
62
-
63
79
  rubyforge_project:
64
- rubygems_version: 1.3.7
80
+ rubygems_version: 1.8.6
65
81
  signing_key:
66
82
  specification_version: 3
67
83
  summary: Do some browser detection with Ruby.
68
- test_files:
84
+ test_files:
69
85
  - test/browser_test.rb
86
+ - test/test_helper.rb