rails-browscap 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +51 -0
- data/install.rb +1 -2
- data/lib/browscap_compat.rb +71 -0
- data/lib/generators/rails_browscap/install/USAGE +9 -0
- data/lib/generators/rails_browscap/install/install_generator.rb +25 -0
- data/lib/generators/rails_browscap/install/templates/browscap.rb +4 -0
- data/lib/rails-browscap.rb +25 -0
- data/lib/rails-browscap/controllers/helpers.rb +15 -0
- metadata +89 -11
- data/README +0 -14
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
Browscap
|
2
|
+
========
|
3
|
+
|
4
|
+
Using the excellent http://github.com/lfittl/browscap parser as a rail plugin
|
5
|
+
|
6
|
+
run rake browscap:update to get the new browscap.ini from http://browsers.garykeith.com
|
7
|
+
|
8
|
+
Known Issues
|
9
|
+
========
|
10
|
+
|
11
|
+
Ruby 1.9:
|
12
|
+
|
13
|
+
The file is ISO-8859-1
|
14
|
+
|
15
|
+
The hex escape char \xdf in
|
16
|
+
|
17
|
+
Line 3553
|
18
|
+
|
19
|
+
[Der gro\xdfe BilderSauger*]
|
20
|
+
Parent=Image Crawlers
|
21
|
+
Browser=Gallery Grabber
|
22
|
+
|
23
|
+
makes the current version of browscap choke. I have monkey patched browscap so you should be fine.
|
24
|
+
|
25
|
+
Also Line 5228
|
26
|
+
|
27
|
+
[www.substancia.com AutoHTTPAgent (ver *)]
|
28
|
+
Parent=Version Checkers
|
29
|
+
Browser=Substância
|
30
|
+
|
31
|
+
the 'â' make inifile < 0.4.0 choke.
|
32
|
+
|
33
|
+
The lib requires inifile >= 0.4.0 so this should be fine.
|
34
|
+
|
35
|
+
Example
|
36
|
+
=======
|
37
|
+
|
38
|
+
initializer/application.rb
|
39
|
+
|
40
|
+
BROWSCAP = Browscap.new 'config/browscap.ini'
|
41
|
+
|
42
|
+
application_controller.rb
|
43
|
+
|
44
|
+
def current_browser
|
45
|
+
@current_browser ||= BROWSCAP.query(request.user_agent)
|
46
|
+
end
|
47
|
+
|
48
|
+
TODO
|
49
|
+
=======
|
50
|
+
|
51
|
+
Copyright (c) 2010 [Gilles Devaux], released under the MIT license
|
data/install.rb
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
puts "Run rake browscap:update to finish the install"
|
1
|
+
puts "Run rails generate rails_browscap:install to finish the install"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#browscap-0.1.0 does not use the encoding option, monkey patch it waiting for native support
|
2
|
+
class Browscap
|
3
|
+
|
4
|
+
def initialize(filename = 'browscap.ini', encoding='ISO-8859-1')
|
5
|
+
@@user_agent_properties ||= {}
|
6
|
+
@@user_agent_regexps ||= {}
|
7
|
+
@@match_cache ||= {}
|
8
|
+
|
9
|
+
if @@user_agent_properties.empty? || @@user_agent_regexps.empty?
|
10
|
+
ini = IniFile.load(filename, {:encoding => encoding})
|
11
|
+
|
12
|
+
# Remote meta sections
|
13
|
+
ini.delete_section '*'
|
14
|
+
ini.delete_section 'GJK_Browscap_Version'
|
15
|
+
|
16
|
+
# Create a list of non-parent sections
|
17
|
+
child_sections = ini.sections.dup
|
18
|
+
ini.sections.each do |section|
|
19
|
+
child_sections.delete ini[section]["Parent"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Populate user_agent_properties and user_agent_regexps
|
23
|
+
child_sections.each do |section|
|
24
|
+
properties = _get_browser_props(ini, section)
|
25
|
+
|
26
|
+
browser = Browser.new
|
27
|
+
browser.browser = properties['Browser']
|
28
|
+
browser.version = properties['Version']
|
29
|
+
browser.major_ver = properties['MajorVer'].to_i
|
30
|
+
browser.minor_ver = properties['MinorVer'].to_i
|
31
|
+
browser.platform = properties['Platform']
|
32
|
+
browser.alpha = properties['Alpha'].downcase == 'true'
|
33
|
+
browser.beta = properties['Beta'].downcase == 'true'
|
34
|
+
browser.win16 = properties['Win16'].downcase == 'true'
|
35
|
+
browser.win32 = properties['Win32'].downcase == 'true'
|
36
|
+
browser.win64 = properties['Win64'].downcase == 'true'
|
37
|
+
browser.frames = properties['Frames'].downcase == 'true'
|
38
|
+
browser.iframes = properties['IFrames'].downcase == 'true'
|
39
|
+
browser.tables = properties['Tables'].downcase == 'true'
|
40
|
+
browser.cookies = properties['Cookies'].downcase == 'true'
|
41
|
+
browser.background_sounds = properties['BackgroundSounds'].downcase == 'true'
|
42
|
+
browser.javascript = properties['JavaScript'].downcase == 'true'
|
43
|
+
browser.vbscript = properties['VBScript'].downcase == 'true'
|
44
|
+
browser.java_applets = properties['JavaApplets'].downcase == 'true'
|
45
|
+
browser.activex_controls = properties['ActiveXControls'].downcase == 'true'
|
46
|
+
browser.is_banned = properties['isBanned'].downcase == 'true'
|
47
|
+
browser.is_mobile_device = properties['isMobileDevice'].downcase == 'true'
|
48
|
+
browser.is_syndication_reader = properties['isSyndicationReader'].downcase == 'true'
|
49
|
+
browser.crawler = properties['Crawler'].downcase == 'true'
|
50
|
+
browser.css_version = properties['CssVersion'].to_i
|
51
|
+
browser.supports_css = properties['supportsCSS'].downcase == 'true'
|
52
|
+
browser.aol_version = properties['aolVersion'].to_i
|
53
|
+
browser.aol = properties['AOL'].downcase == 'true'
|
54
|
+
|
55
|
+
@@user_agent_properties[section] = browser
|
56
|
+
|
57
|
+
# Convert .ini file regexp syntax into ruby regexp syntax
|
58
|
+
regexp = section.dup
|
59
|
+
regexp.gsub! /([\^\$\(\)\[\]\.\-])/, "\\\\\\1"
|
60
|
+
regexp.gsub! "?", "."
|
61
|
+
regexp.gsub! "*", ".*?"
|
62
|
+
|
63
|
+
if RUBY_VERSION < '1.9'
|
64
|
+
@@user_agent_regexps[section] = Regexp.new(("^%s$" % regexp))
|
65
|
+
else
|
66
|
+
@@user_agent_regexps[section] = Regexp.new(("^%s$" % regexp).force_encoding(encoding))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module RailsBrowscap
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
desc 'install browscap'
|
9
|
+
|
10
|
+
def install
|
11
|
+
|
12
|
+
#downlad browscap.ini
|
13
|
+
|
14
|
+
Net::HTTP.start("browsers.garykeith.com") { |http|
|
15
|
+
resp = http.get("/stream.asp?BrowsCapINI", {'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9'})
|
16
|
+
create_file("config/browscap.ini", resp.body)
|
17
|
+
}
|
18
|
+
|
19
|
+
#initialize
|
20
|
+
copy_file "browscap.rb", "config/initializers/browscap.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/rails-browscap.rb
CHANGED
@@ -1,2 +1,27 @@
|
|
1
1
|
require 'inifile'
|
2
2
|
require 'browscap'
|
3
|
+
|
4
|
+
require 'rails'
|
5
|
+
require 'action_controller'
|
6
|
+
|
7
|
+
require 'rails-browscap/controllers/helpers'
|
8
|
+
|
9
|
+
#force ISO-8859-1 until browscap updates
|
10
|
+
require 'browscap_compat'
|
11
|
+
|
12
|
+
module RailsBrowscap
|
13
|
+
class Railtie < Rails::Railtie
|
14
|
+
rake_tasks do
|
15
|
+
load "tasks/rails-browscap_tasks.rake"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
module RailsBrowscap
|
22
|
+
def self.query(user_agent)
|
23
|
+
@@browscap.query(user_agent)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
ActionController::Base.send :include, RailsBrowscap::Controllers::Helpers
|
27
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RailsBrowscap
|
2
|
+
module Controllers
|
3
|
+
module Helpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
helper_method :current_browser
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_browser
|
11
|
+
@current_browser ||= RailsBrowscap.query(request.user_agent)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-browscap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
8
|
+
- 1
|
7
9
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.4
|
10
|
+
version: 0.1.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Gilles Devaux
|
@@ -14,37 +15,105 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-18 00:00:00 -08:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
+
name: rails
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ~>
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 3.0.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: browscap
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 27
|
27
46
|
segments:
|
28
47
|
- 0
|
29
48
|
- 1
|
30
49
|
- 0
|
31
50
|
version: 0.1.0
|
32
51
|
type: :runtime
|
33
|
-
version_requirements: *
|
52
|
+
version_requirements: *id002
|
34
53
|
- !ruby/object:Gem::Dependency
|
35
54
|
name: inifile
|
36
55
|
prerelease: false
|
37
|
-
requirement: &
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
38
58
|
requirements:
|
39
59
|
- - ~>
|
40
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 15
|
41
62
|
segments:
|
42
63
|
- 0
|
64
|
+
- 4
|
65
|
+
- 0
|
66
|
+
version: 0.4.0
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 15
|
78
|
+
segments:
|
43
79
|
- 3
|
44
80
|
- 0
|
45
|
-
|
81
|
+
- 4
|
82
|
+
version: 3.0.4
|
46
83
|
type: :runtime
|
47
|
-
version_requirements: *
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: i18n
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 11
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
- 5
|
97
|
+
- 0
|
98
|
+
version: 0.5.0
|
99
|
+
type: :runtime
|
100
|
+
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: test-unit
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - "="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 7
|
110
|
+
segments:
|
111
|
+
- 2
|
112
|
+
- 2
|
113
|
+
- 0
|
114
|
+
version: 2.2.0
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id006
|
48
117
|
description:
|
49
118
|
email: gilles.devaux@gmail.com
|
50
119
|
executables: []
|
@@ -52,13 +121,18 @@ executables: []
|
|
52
121
|
extensions: []
|
53
122
|
|
54
123
|
extra_rdoc_files:
|
55
|
-
- README
|
124
|
+
- README.md
|
56
125
|
files:
|
57
126
|
- rails/init.rb
|
127
|
+
- lib/browscap_compat.rb
|
128
|
+
- lib/generators/rails_browscap/install/install_generator.rb
|
129
|
+
- lib/generators/rails_browscap/install/templates/browscap.rb
|
130
|
+
- lib/generators/rails_browscap/install/USAGE
|
131
|
+
- lib/rails-browscap/controllers/helpers.rb
|
58
132
|
- lib/rails-browscap.rb
|
59
133
|
- lib/tasks/rails-browscap_tasks.rake
|
60
134
|
- MIT-LICENSE
|
61
|
-
- README
|
135
|
+
- README.md
|
62
136
|
- install.rb
|
63
137
|
- uninstall.rb
|
64
138
|
has_rdoc: true
|
@@ -71,23 +145,27 @@ rdoc_options: []
|
|
71
145
|
require_paths:
|
72
146
|
- lib
|
73
147
|
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
74
149
|
requirements:
|
75
150
|
- - ">="
|
76
151
|
- !ruby/object:Gem::Version
|
152
|
+
hash: 3
|
77
153
|
segments:
|
78
154
|
- 0
|
79
155
|
version: "0"
|
80
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
81
158
|
requirements:
|
82
159
|
- - ">="
|
83
160
|
- !ruby/object:Gem::Version
|
161
|
+
hash: 3
|
84
162
|
segments:
|
85
163
|
- 0
|
86
164
|
version: "0"
|
87
165
|
requirements: []
|
88
166
|
|
89
167
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.3.
|
168
|
+
rubygems_version: 1.3.7
|
91
169
|
signing_key:
|
92
170
|
specification_version: 3
|
93
171
|
summary: rails plugin around the broswcap gem
|
data/README
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
Browscap
|
2
|
-
========
|
3
|
-
|
4
|
-
Using the excellent http://github.com/lfittl/browscap parser as a rail plugin
|
5
|
-
|
6
|
-
run rake browscap:update to get the new browscap.ini from http://browsers.garykeith.com
|
7
|
-
|
8
|
-
Example
|
9
|
-
=======
|
10
|
-
|
11
|
-
Example goes here.
|
12
|
-
|
13
|
-
|
14
|
-
Copyright (c) 2010 [name of plugin creator], released under the MIT license
|