brauser 2.0.0 → 2.0.1
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/.travis-gemfile +13 -0
- data/.travis.yml +4 -2
- data/Gemfile +11 -0
- data/Rakefile +1 -8
- data/brauser.gemspec +2 -10
- data/doc/Brauser.html +3 -3
- data/doc/Brauser/Browser.html +8 -7
- data/doc/Brauser/BrowserMethods.html +3 -3
- data/doc/Brauser/BrowserMethods/Attributes.html +6 -5
- data/doc/Brauser/BrowserMethods/General.html +3 -3
- data/doc/Brauser/BrowserMethods/General/ClassMethods.html +3 -3
- data/doc/Brauser/BrowserMethods/Parsing.html +3 -3
- data/doc/Brauser/BrowserMethods/PartialQuerying.html +3 -3
- data/doc/Brauser/BrowserMethods/Querying.html +3 -3
- data/doc/Brauser/BrowserMethods/Register.html +3 -3
- data/doc/Brauser/BrowserMethods/Register/ClassMethods.html +3 -3
- data/doc/Brauser/Hooks.html +3 -3
- data/doc/Brauser/Hooks/RubyOnRails.html +3 -3
- data/doc/Brauser/Query.html +6 -5
- data/doc/Brauser/Version.html +4 -4
- data/doc/_index.html +4 -4
- data/doc/file.README.html +105 -92
- data/doc/frames.html +1 -1
- data/doc/index.html +105 -92
- data/doc/top-level-namespace.html +3 -3
- data/lib/brauser/version.rb +1 -1
- data/spec/coverage_helper.rb +6 -9
- data/spec/spec_helper.rb +0 -2
- metadata +10 -118
data/doc/_index.html
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
<head>
|
5
5
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
6
|
<title>
|
7
|
-
Documentation by YARD 0.8.
|
7
|
+
Documentation by YARD 0.8.4.1
|
8
8
|
|
9
9
|
</title>
|
10
10
|
|
@@ -56,7 +56,7 @@
|
|
56
56
|
|
57
57
|
<iframe id="search_frame"></iframe>
|
58
58
|
|
59
|
-
<div id="content"><h1 class="noborder title">Documentation by YARD 0.8.
|
59
|
+
<div id="content"><h1 class="noborder title">Documentation by YARD 0.8.4.1</h1>
|
60
60
|
<div id="listing">
|
61
61
|
<h1 class="alphaindex">Alphabetic Index</h1>
|
62
62
|
|
@@ -266,9 +266,9 @@
|
|
266
266
|
</div>
|
267
267
|
|
268
268
|
<div id="footer">
|
269
|
-
Generated on
|
269
|
+
Generated on Fri Feb 8 08:12:31 2013 by
|
270
270
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
271
|
-
0.8.
|
271
|
+
0.8.4.1 (ruby-1.9.3).
|
272
272
|
</div>
|
273
273
|
|
274
274
|
</body>
|
data/doc/file.README.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
File: README
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.
|
9
|
+
— Documentation by YARD 0.8.4.1
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -61,41 +61,43 @@
|
|
61
61
|
|
62
62
|
<iframe id="search_frame"></iframe>
|
63
63
|
|
64
|
-
<div id="content"><div id='filecontents'><h1>brauser</h1>
|
64
|
+
<div id="content"><div id='filecontents'><h1 id="brauser">brauser</h1>
|
65
65
|
|
66
|
-
<p><a href="http://travis-ci.org/ShogunPanda/brauser"><img src="https://secure.travis-ci.org/ShogunPanda/brauser.png?branch=master" alt="Build Status"
|
67
|
-
<a href="https://gemnasium.com/ShogunPanda/brauser"><img src="https://gemnasium.com/ShogunPanda/brauser.png?travis" alt="Dependency Status"
|
68
|
-
<a href="https://codeclimate.com/github/ShogunPanda/brauser"><img src="https://codeclimate.com/github/ShogunPanda/brauser.png" alt="Code Climate"
|
66
|
+
<p><a href="http://travis-ci.org/ShogunPanda/brauser"><img src="https://secure.travis-ci.org/ShogunPanda/brauser.png?branch=master" alt="Build Status" /></a>
|
67
|
+
<a href="https://gemnasium.com/ShogunPanda/brauser"><img src="https://gemnasium.com/ShogunPanda/brauser.png?travis" alt="Dependency Status" /></a>
|
68
|
+
<a href="https://codeclimate.com/github/ShogunPanda/brauser"><img src="https://codeclimate.com/github/ShogunPanda/brauser.png" alt="Code Climate" /></a></p>
|
69
69
|
|
70
70
|
<p>A framework agnostic browser detection and querying helper.</p>
|
71
71
|
|
72
|
-
<p
|
72
|
+
<p>http://sw.cow.tc/brauser</p>
|
73
73
|
|
74
|
-
<p
|
74
|
+
<p>http://rdoc.info/gems/brauser</p>
|
75
75
|
|
76
|
-
<h2>Description</h2>
|
76
|
+
<h2 id="description">Description</h2>
|
77
77
|
|
78
78
|
<p>Brauser is a framework agnostic helper that helps you in targeting your applications against most diffused browsers.</p>
|
79
79
|
|
80
|
-
<h3>Installation</h3>
|
80
|
+
<h3 id="installation">Installation</h3>
|
81
81
|
|
82
82
|
<p>Brauser comes with a Ruby on Rails hooks (more framework to follow), so for Rails you have just to add this to your Gemfile:</p>
|
83
83
|
|
84
|
-
<
|
85
|
-
|
84
|
+
<p><code>ruby
|
85
|
+
gem "brauser"
|
86
|
+
</code></p>
|
86
87
|
|
87
88
|
<p>Once done that, every controller in your application will have a <code>browser</code> method (also extended to views/layout via <code>helper_method</code>).</p>
|
88
89
|
|
89
|
-
<p>If you don&#
|
90
|
+
<p>If you don’t use Rails, you can instantiate a new browser by including the gem in your code and by doing something like this:</p>
|
90
91
|
|
91
|
-
<
|
92
|
-
|
92
|
+
<p><code>ruby
|
93
|
+
browser = Brauser::Browser.new(USER_AGENT_HEADER, ACCEPT_LANGUAGE_HEADER)
|
94
|
+
</code></p>
|
93
95
|
|
94
96
|
<p>where the first argument is the HTTP header <code>User-Agent</code>, and the second is the HTTP header <code>Accept-Language</code>.</p>
|
95
97
|
|
96
|
-
<p>For the rest of this document, let&#
|
98
|
+
<p>For the rest of this document, let’s assume you use Chrome 1.2.3 on Mac OS X.</p>
|
97
99
|
|
98
|
-
<h3>Getting browser information</h3>
|
100
|
+
<h3 id="getting-browser-information">Getting browser information</h3>
|
99
101
|
|
100
102
|
<p>Once you instantiate the browser, you can query the browser about <code>name</code>, <code>version</code> and <code>platform</code>. You can also get readable name and platforms via <code>readable_name</code> and <code>platform_name</code>.</p>
|
101
103
|
|
@@ -107,34 +109,37 @@
|
|
107
109
|
|
108
110
|
<p>For example, if you do this in a ERB view:</p>
|
109
111
|
|
110
|
-
<
|
112
|
+
<p><code>html
|
113
|
+
<body class="<%= browser.classes %>">
|
111
114
|
...
|
112
|
-
</code></
|
115
|
+
</code></p>
|
113
116
|
|
114
117
|
<p>The view will get compiled to this:</p>
|
115
118
|
|
116
|
-
<
|
119
|
+
<p><code>html
|
120
|
+
<body class="chrome version-1 version-1_2 version-1_2_3 platform-osx">
|
117
121
|
...
|
118
|
-
</code></
|
122
|
+
</code></p>
|
119
123
|
|
120
124
|
<p>And thus scoping your CSS will be trivial.</p>
|
121
125
|
|
122
|
-
<h3>Querying the browser</h3>
|
126
|
+
<h3 id="querying-the-browser">Querying the browser</h3>
|
123
127
|
|
124
128
|
<p>Brauser supports querying about name (method <code>is</code>), version (method <code>v</code>), platform (method <code>on</code>) and language (method <code>accepts</code>).</p>
|
125
129
|
|
126
130
|
<p>The <code>is</code> method queries about a browser name (or a list of names) and optionally by version and platform:</p>
|
127
131
|
|
128
|
-
<
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
132
|
+
<p><code>ruby
|
133
|
+
# We talk about the ending ? later.
|
134
|
+
browser.is?(:chrome)
|
135
|
+
# => true
|
136
|
+
browser.is?([:msie, :firefox])
|
137
|
+
# => false
|
138
|
+
browser.is?(:chrome, {:lt => "2"}, :osx)
|
139
|
+
# => true
|
140
|
+
browser.is?(:chrome, ">= 3", :windows)
|
141
|
+
# => false
|
142
|
+
</code></p>
|
138
143
|
|
139
144
|
<p>The method <code>is</code> is the only which supports direct internal propagation to version and platform.</p>
|
140
145
|
|
@@ -142,47 +147,51 @@
|
|
142
147
|
|
143
148
|
<p>In the case of hash, the syntax is <code>{:operator => value}</code>, where <code>:operator</code> is one of <code>[:lt, :lte, :eq, :gte, :gt]</code> and value can be a Float or a String.</p>
|
144
149
|
|
145
|
-
<p>In the case of expression, the syntax is <code>OPERATOR VALUE && ..</code>, where <code>OPERATOR</code> is one of <code>[&
|
150
|
+
<p>In the case of expression, the syntax is <code>OPERATOR VALUE && ..</code>, where <code>OPERATOR</code> is one of <code>["<", "<=", "=", "==", ">=", ">"]</code> and value specifies the version.</p>
|
146
151
|
|
147
152
|
<p>Examples:</p>
|
148
153
|
|
149
|
-
<
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
154
|
+
<p><code>ruby
|
155
|
+
# Those two methods are equivalent.
|
156
|
+
browser.v?({:lt => "2", :gt => 1})
|
157
|
+
# => true
|
158
|
+
browser.is?("< 2 && > 1")
|
159
|
+
# => true
|
160
|
+
</code></p>
|
155
161
|
|
156
162
|
<p>The method <code>on</code> check is the current browser in one of the specifed platform. The platform should be passed as <code>Symbol</code>.</p>
|
157
163
|
|
158
|
-
<
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
164
|
+
<p><code>ruby
|
165
|
+
browser.on?(:osx)
|
166
|
+
# => true
|
167
|
+
browser.on?([:windows, :ios])
|
168
|
+
# => false
|
169
|
+
</code></p>
|
163
170
|
|
164
171
|
<p>At the end, the method <code>accepts</code> checks if the browser accepts one of the specified languages. Languages should be passed as language codes in <code>String</code>.</p>
|
165
172
|
|
166
|
-
<
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
173
|
+
<p><code>ruby
|
174
|
+
browser.accepts?("en")
|
175
|
+
# => true
|
176
|
+
browser.accepts?(["de", "es"])
|
177
|
+
# => false
|
178
|
+
</code></p>
|
171
179
|
|
172
|
-
<p>Every query method exists in two forms: the concatenation one (the method name doesn&#
|
180
|
+
<p>Every query method exists in two forms: the concatenation one (the method name doesn’t end with a <code>?</code>.</p>
|
173
181
|
|
174
182
|
<p>The former return a <code>Query</code> object, which supports the same query method of the browser and thus enables concatenation.</p>
|
175
183
|
|
176
|
-
<p>The latter return a boolean object, and it&#
|
184
|
+
<p>The latter return a boolean object, and it’s equivalent to calling <code>result</code> on the query after concatenation.</p>
|
177
185
|
|
178
186
|
<p>Ideally, you should use the <code>?</code> version to end the query and fetch the result.</p>
|
179
187
|
|
180
|
-
<
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
188
|
+
<p><code>ruby
|
189
|
+
# These expressions are equivalent.
|
190
|
+
browser.is?(:chrome, {:lt => "2"}, :osx)
|
191
|
+
browser.is(:chrome, {:lt => "2"}, :osx).result
|
192
|
+
browser.is(:chrome).v({:lt => "2"}).on?(:osx)
|
193
|
+
browser.is(:chrome).v({:lt => "2"}).on(:osx).result
|
194
|
+
</code></p>
|
186
195
|
|
187
196
|
<p>Finally, Brauser support dynamic query operator to write simple queries without using concatenation.</p>
|
188
197
|
|
@@ -192,51 +201,54 @@
|
|
192
201
|
|
193
202
|
<p>Example:</p>
|
194
203
|
|
195
|
-
<
|
196
|
-
|
197
|
-
|
204
|
+
<p>```ruby
|
205
|
+
# These expressions are equivalent.
|
206
|
+
browser.is(:chrome).v(“< 2 && > 1.2”).on(:osx).result
|
207
|
+
browser.is_chrome__v_lt<em>2_and_gt</em>1_2__on_osx.result</p>
|
198
208
|
|
199
|
-
<
|
200
|
-
|
201
|
-
<
|
202
|
-
|
209
|
+
<h1 id="these-expressions-are-equivalent">These expressions are equivalent.</h1>
|
210
|
+
<p>browser.is(:chrome).v(“< 2 && > 1.2”).on?(:osx)
|
211
|
+
browser.is_chrome__v_lt<em>2_and_gt</em>1_2__on_osx?
|
212
|
+
```</p>
|
203
213
|
|
204
|
-
<h3>Adding new browsers</h3>
|
214
|
+
<h3 id="adding-new-browsers">Adding new browsers</h3>
|
205
215
|
|
206
216
|
<p>To add new browsers, simply call <code>register_browser</code>.</p>
|
207
217
|
|
208
218
|
<p>This methods accepts a single entry or an array of entries in the following format: <code>[name, name_match, version_match, label]</code>:</p>
|
209
219
|
|
210
220
|
<ul>
|
211
|
-
<li><code>name</code> is the name of the browser. Should be a <code>Symbol</code>.</li>
|
212
|
-
<li><code>name_match</code> is a <code>Regexp</code> to match against the user agent to detect the current browser.</li>
|
213
|
-
<li><code>version_match</code> is a <code>Regexp</code> which last capture group holds the version of the browser.</li>
|
214
|
-
<li><code>label</code> is the human readable name of the browser.</li>
|
221
|
+
<li><code>name</code> is the name of the browser. Should be a <code>Symbol</code>.</li>
|
222
|
+
<li><code>name_match</code> is a <code>Regexp</code> to match against the user agent to detect the current browser.</li>
|
223
|
+
<li><code>version_match</code> is a <code>Regexp</code> which last capture group holds the version of the browser.</li>
|
224
|
+
<li><code>label</code> is the human readable name of the browser.</li>
|
215
225
|
</ul>
|
216
226
|
|
217
227
|
<p>For example, for Google Chrome the call should be:</p>
|
218
228
|
|
219
|
-
<
|
220
|
-
|
229
|
+
<p><code>ruby
|
230
|
+
browser.register_browser(:chrome, /((chrome)|(chromium))/i, /(.+Chrom[a-z]+\/)([a-z0-9.]+)/i, "Google Chrome")
|
231
|
+
</code></p>
|
221
232
|
|
222
|
-
<h3>Adding new platforms</h3>
|
233
|
+
<h3 id="adding-new-platforms">Adding new platforms</h3>
|
223
234
|
|
224
235
|
<p>To add new platforms, simply call <code>register_platform</code>.</p>
|
225
236
|
|
226
237
|
<p>This method accepts a single entry or an array of entries in the following format: <code>[name, matcher, label]</code>:</p>
|
227
238
|
|
228
239
|
<ul>
|
229
|
-
<li><code>name</code> is the name of the platform. Should be a <code>Symbol</code>.</li>
|
230
|
-
<li><code>matcher</code> is a <code>Regexp</code> to match against the user agent to detect the current platform.</li>
|
231
|
-
<li><code>label</code> is the human readable name of the platform.</li>
|
240
|
+
<li><code>name</code> is the name of the platform. Should be a <code>Symbol</code>.</li>
|
241
|
+
<li><code>matcher</code> is a <code>Regexp</code> to match against the user agent to detect the current platform.</li>
|
242
|
+
<li><code>label</code> is the human readable name of the platform.</li>
|
232
243
|
</ul>
|
233
244
|
|
234
245
|
<p>For example, for Mac OS X the call should be:</p>
|
235
246
|
|
236
|
-
<
|
237
|
-
|
247
|
+
<p><code>ruby
|
248
|
+
browser.register_platform(:osx, /mac|macintosh|mac os x/i, "Apple MacOS X")
|
249
|
+
</code></p>
|
238
250
|
|
239
|
-
<h3>Adding new languages</h3>
|
251
|
+
<h3 id="adding-new-languages">Adding new languages</h3>
|
240
252
|
|
241
253
|
<p>To add new languages, simply call <code>register_language</code>.</p>
|
242
254
|
|
@@ -244,32 +256,33 @@
|
|
244
256
|
|
245
257
|
<p>For example, for Italian the call should be:</p>
|
246
258
|
|
247
|
-
<
|
248
|
-
|
259
|
+
<p><code>ruby
|
260
|
+
browser.register_language("it", "Italian")
|
261
|
+
</code></p>
|
249
262
|
|
250
|
-
<h2>Contributing to brauser</h2>
|
263
|
+
<h2 id="contributing-to-brauser">Contributing to brauser</h2>
|
251
264
|
|
252
265
|
<ul>
|
253
|
-
<li>Check out the latest master to make sure the feature hasn&#
|
254
|
-
<li>Check out the issue tracker to make sure someone already hasn&#
|
255
|
-
<li>Fork the project.</li>
|
256
|
-
<li>Start a feature/bugfix branch.</li>
|
257
|
-
<li>Commit and push until you are happy with your contribution.</li>
|
258
|
-
<li>Make sure to add tests for it. This is important so I don&#
|
259
|
-
<li>Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.</li>
|
266
|
+
<li>Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.</li>
|
267
|
+
<li>Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.</li>
|
268
|
+
<li>Fork the project.</li>
|
269
|
+
<li>Start a feature/bugfix branch.</li>
|
270
|
+
<li>Commit and push until you are happy with your contribution.</li>
|
271
|
+
<li>Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.</li>
|
272
|
+
<li>Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.</li>
|
260
273
|
</ul>
|
261
274
|
|
262
|
-
<h2>Copyright</h2>
|
275
|
+
<h2 id="copyright">Copyright</h2>
|
263
276
|
|
264
|
-
<p>Copyright (C) 2013 and above Shogun (
|
277
|
+
<p>Copyright (C) 2013 and above Shogun (shogun_panda@me.com).</p>
|
265
278
|
|
266
|
-
<p>Licensed under the MIT license, which can be found at
|
279
|
+
<p>Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.</p>
|
267
280
|
</div></div>
|
268
281
|
|
269
282
|
<div id="footer">
|
270
|
-
Generated on
|
283
|
+
Generated on Fri Feb 8 08:12:31 2013 by
|
271
284
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
272
|
-
0.8.
|
285
|
+
0.8.4.1 (ruby-1.9.3).
|
273
286
|
</div>
|
274
287
|
|
275
288
|
</body>
|
data/doc/frames.html
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
5
|
<head>
|
6
6
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
-
<title>Documentation by YARD 0.8.
|
7
|
+
<title>Documentation by YARD 0.8.4.1</title>
|
8
8
|
</head>
|
9
9
|
<script type="text/javascript" charset="utf-8">
|
10
10
|
window.onload = function() {
|
data/doc/index.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
File: README
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.
|
9
|
+
— Documentation by YARD 0.8.4.1
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -61,41 +61,43 @@
|
|
61
61
|
|
62
62
|
<iframe id="search_frame"></iframe>
|
63
63
|
|
64
|
-
<div id="content"><div id='filecontents'><h1>brauser</h1>
|
64
|
+
<div id="content"><div id='filecontents'><h1 id="brauser">brauser</h1>
|
65
65
|
|
66
|
-
<p><a href="http://travis-ci.org/ShogunPanda/brauser"><img src="https://secure.travis-ci.org/ShogunPanda/brauser.png?branch=master" alt="Build Status"
|
67
|
-
<a href="https://gemnasium.com/ShogunPanda/brauser"><img src="https://gemnasium.com/ShogunPanda/brauser.png?travis" alt="Dependency Status"
|
68
|
-
<a href="https://codeclimate.com/github/ShogunPanda/brauser"><img src="https://codeclimate.com/github/ShogunPanda/brauser.png" alt="Code Climate"
|
66
|
+
<p><a href="http://travis-ci.org/ShogunPanda/brauser"><img src="https://secure.travis-ci.org/ShogunPanda/brauser.png?branch=master" alt="Build Status" /></a>
|
67
|
+
<a href="https://gemnasium.com/ShogunPanda/brauser"><img src="https://gemnasium.com/ShogunPanda/brauser.png?travis" alt="Dependency Status" /></a>
|
68
|
+
<a href="https://codeclimate.com/github/ShogunPanda/brauser"><img src="https://codeclimate.com/github/ShogunPanda/brauser.png" alt="Code Climate" /></a></p>
|
69
69
|
|
70
70
|
<p>A framework agnostic browser detection and querying helper.</p>
|
71
71
|
|
72
|
-
<p
|
72
|
+
<p>http://sw.cow.tc/brauser</p>
|
73
73
|
|
74
|
-
<p
|
74
|
+
<p>http://rdoc.info/gems/brauser</p>
|
75
75
|
|
76
|
-
<h2>Description</h2>
|
76
|
+
<h2 id="description">Description</h2>
|
77
77
|
|
78
78
|
<p>Brauser is a framework agnostic helper that helps you in targeting your applications against most diffused browsers.</p>
|
79
79
|
|
80
|
-
<h3>Installation</h3>
|
80
|
+
<h3 id="installation">Installation</h3>
|
81
81
|
|
82
82
|
<p>Brauser comes with a Ruby on Rails hooks (more framework to follow), so for Rails you have just to add this to your Gemfile:</p>
|
83
83
|
|
84
|
-
<
|
85
|
-
|
84
|
+
<p><code>ruby
|
85
|
+
gem "brauser"
|
86
|
+
</code></p>
|
86
87
|
|
87
88
|
<p>Once done that, every controller in your application will have a <code>browser</code> method (also extended to views/layout via <code>helper_method</code>).</p>
|
88
89
|
|
89
|
-
<p>If you don&#
|
90
|
+
<p>If you don’t use Rails, you can instantiate a new browser by including the gem in your code and by doing something like this:</p>
|
90
91
|
|
91
|
-
<
|
92
|
-
|
92
|
+
<p><code>ruby
|
93
|
+
browser = Brauser::Browser.new(USER_AGENT_HEADER, ACCEPT_LANGUAGE_HEADER)
|
94
|
+
</code></p>
|
93
95
|
|
94
96
|
<p>where the first argument is the HTTP header <code>User-Agent</code>, and the second is the HTTP header <code>Accept-Language</code>.</p>
|
95
97
|
|
96
|
-
<p>For the rest of this document, let&#
|
98
|
+
<p>For the rest of this document, let’s assume you use Chrome 1.2.3 on Mac OS X.</p>
|
97
99
|
|
98
|
-
<h3>Getting browser information</h3>
|
100
|
+
<h3 id="getting-browser-information">Getting browser information</h3>
|
99
101
|
|
100
102
|
<p>Once you instantiate the browser, you can query the browser about <code>name</code>, <code>version</code> and <code>platform</code>. You can also get readable name and platforms via <code>readable_name</code> and <code>platform_name</code>.</p>
|
101
103
|
|
@@ -107,34 +109,37 @@
|
|
107
109
|
|
108
110
|
<p>For example, if you do this in a ERB view:</p>
|
109
111
|
|
110
|
-
<
|
112
|
+
<p><code>html
|
113
|
+
<body class="<%= browser.classes %>">
|
111
114
|
...
|
112
|
-
</code></
|
115
|
+
</code></p>
|
113
116
|
|
114
117
|
<p>The view will get compiled to this:</p>
|
115
118
|
|
116
|
-
<
|
119
|
+
<p><code>html
|
120
|
+
<body class="chrome version-1 version-1_2 version-1_2_3 platform-osx">
|
117
121
|
...
|
118
|
-
</code></
|
122
|
+
</code></p>
|
119
123
|
|
120
124
|
<p>And thus scoping your CSS will be trivial.</p>
|
121
125
|
|
122
|
-
<h3>Querying the browser</h3>
|
126
|
+
<h3 id="querying-the-browser">Querying the browser</h3>
|
123
127
|
|
124
128
|
<p>Brauser supports querying about name (method <code>is</code>), version (method <code>v</code>), platform (method <code>on</code>) and language (method <code>accepts</code>).</p>
|
125
129
|
|
126
130
|
<p>The <code>is</code> method queries about a browser name (or a list of names) and optionally by version and platform:</p>
|
127
131
|
|
128
|
-
<
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
132
|
+
<p><code>ruby
|
133
|
+
# We talk about the ending ? later.
|
134
|
+
browser.is?(:chrome)
|
135
|
+
# => true
|
136
|
+
browser.is?([:msie, :firefox])
|
137
|
+
# => false
|
138
|
+
browser.is?(:chrome, {:lt => "2"}, :osx)
|
139
|
+
# => true
|
140
|
+
browser.is?(:chrome, ">= 3", :windows)
|
141
|
+
# => false
|
142
|
+
</code></p>
|
138
143
|
|
139
144
|
<p>The method <code>is</code> is the only which supports direct internal propagation to version and platform.</p>
|
140
145
|
|
@@ -142,47 +147,51 @@
|
|
142
147
|
|
143
148
|
<p>In the case of hash, the syntax is <code>{:operator => value}</code>, where <code>:operator</code> is one of <code>[:lt, :lte, :eq, :gte, :gt]</code> and value can be a Float or a String.</p>
|
144
149
|
|
145
|
-
<p>In the case of expression, the syntax is <code>OPERATOR VALUE && ..</code>, where <code>OPERATOR</code> is one of <code>[&
|
150
|
+
<p>In the case of expression, the syntax is <code>OPERATOR VALUE && ..</code>, where <code>OPERATOR</code> is one of <code>["<", "<=", "=", "==", ">=", ">"]</code> and value specifies the version.</p>
|
146
151
|
|
147
152
|
<p>Examples:</p>
|
148
153
|
|
149
|
-
<
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
154
|
+
<p><code>ruby
|
155
|
+
# Those two methods are equivalent.
|
156
|
+
browser.v?({:lt => "2", :gt => 1})
|
157
|
+
# => true
|
158
|
+
browser.is?("< 2 && > 1")
|
159
|
+
# => true
|
160
|
+
</code></p>
|
155
161
|
|
156
162
|
<p>The method <code>on</code> check is the current browser in one of the specifed platform. The platform should be passed as <code>Symbol</code>.</p>
|
157
163
|
|
158
|
-
<
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
164
|
+
<p><code>ruby
|
165
|
+
browser.on?(:osx)
|
166
|
+
# => true
|
167
|
+
browser.on?([:windows, :ios])
|
168
|
+
# => false
|
169
|
+
</code></p>
|
163
170
|
|
164
171
|
<p>At the end, the method <code>accepts</code> checks if the browser accepts one of the specified languages. Languages should be passed as language codes in <code>String</code>.</p>
|
165
172
|
|
166
|
-
<
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
173
|
+
<p><code>ruby
|
174
|
+
browser.accepts?("en")
|
175
|
+
# => true
|
176
|
+
browser.accepts?(["de", "es"])
|
177
|
+
# => false
|
178
|
+
</code></p>
|
171
179
|
|
172
|
-
<p>Every query method exists in two forms: the concatenation one (the method name doesn&#
|
180
|
+
<p>Every query method exists in two forms: the concatenation one (the method name doesn’t end with a <code>?</code>.</p>
|
173
181
|
|
174
182
|
<p>The former return a <code>Query</code> object, which supports the same query method of the browser and thus enables concatenation.</p>
|
175
183
|
|
176
|
-
<p>The latter return a boolean object, and it&#
|
184
|
+
<p>The latter return a boolean object, and it’s equivalent to calling <code>result</code> on the query after concatenation.</p>
|
177
185
|
|
178
186
|
<p>Ideally, you should use the <code>?</code> version to end the query and fetch the result.</p>
|
179
187
|
|
180
|
-
<
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
188
|
+
<p><code>ruby
|
189
|
+
# These expressions are equivalent.
|
190
|
+
browser.is?(:chrome, {:lt => "2"}, :osx)
|
191
|
+
browser.is(:chrome, {:lt => "2"}, :osx).result
|
192
|
+
browser.is(:chrome).v({:lt => "2"}).on?(:osx)
|
193
|
+
browser.is(:chrome).v({:lt => "2"}).on(:osx).result
|
194
|
+
</code></p>
|
186
195
|
|
187
196
|
<p>Finally, Brauser support dynamic query operator to write simple queries without using concatenation.</p>
|
188
197
|
|
@@ -192,51 +201,54 @@
|
|
192
201
|
|
193
202
|
<p>Example:</p>
|
194
203
|
|
195
|
-
<
|
196
|
-
|
197
|
-
|
204
|
+
<p>```ruby
|
205
|
+
# These expressions are equivalent.
|
206
|
+
browser.is(:chrome).v(“< 2 && > 1.2”).on(:osx).result
|
207
|
+
browser.is_chrome__v_lt<em>2_and_gt</em>1_2__on_osx.result</p>
|
198
208
|
|
199
|
-
<
|
200
|
-
|
201
|
-
<
|
202
|
-
|
209
|
+
<h1 id="these-expressions-are-equivalent">These expressions are equivalent.</h1>
|
210
|
+
<p>browser.is(:chrome).v(“< 2 && > 1.2”).on?(:osx)
|
211
|
+
browser.is_chrome__v_lt<em>2_and_gt</em>1_2__on_osx?
|
212
|
+
```</p>
|
203
213
|
|
204
|
-
<h3>Adding new browsers</h3>
|
214
|
+
<h3 id="adding-new-browsers">Adding new browsers</h3>
|
205
215
|
|
206
216
|
<p>To add new browsers, simply call <code>register_browser</code>.</p>
|
207
217
|
|
208
218
|
<p>This methods accepts a single entry or an array of entries in the following format: <code>[name, name_match, version_match, label]</code>:</p>
|
209
219
|
|
210
220
|
<ul>
|
211
|
-
<li><code>name</code> is the name of the browser. Should be a <code>Symbol</code>.</li>
|
212
|
-
<li><code>name_match</code> is a <code>Regexp</code> to match against the user agent to detect the current browser.</li>
|
213
|
-
<li><code>version_match</code> is a <code>Regexp</code> which last capture group holds the version of the browser.</li>
|
214
|
-
<li><code>label</code> is the human readable name of the browser.</li>
|
221
|
+
<li><code>name</code> is the name of the browser. Should be a <code>Symbol</code>.</li>
|
222
|
+
<li><code>name_match</code> is a <code>Regexp</code> to match against the user agent to detect the current browser.</li>
|
223
|
+
<li><code>version_match</code> is a <code>Regexp</code> which last capture group holds the version of the browser.</li>
|
224
|
+
<li><code>label</code> is the human readable name of the browser.</li>
|
215
225
|
</ul>
|
216
226
|
|
217
227
|
<p>For example, for Google Chrome the call should be:</p>
|
218
228
|
|
219
|
-
<
|
220
|
-
|
229
|
+
<p><code>ruby
|
230
|
+
browser.register_browser(:chrome, /((chrome)|(chromium))/i, /(.+Chrom[a-z]+\/)([a-z0-9.]+)/i, "Google Chrome")
|
231
|
+
</code></p>
|
221
232
|
|
222
|
-
<h3>Adding new platforms</h3>
|
233
|
+
<h3 id="adding-new-platforms">Adding new platforms</h3>
|
223
234
|
|
224
235
|
<p>To add new platforms, simply call <code>register_platform</code>.</p>
|
225
236
|
|
226
237
|
<p>This method accepts a single entry or an array of entries in the following format: <code>[name, matcher, label]</code>:</p>
|
227
238
|
|
228
239
|
<ul>
|
229
|
-
<li><code>name</code> is the name of the platform. Should be a <code>Symbol</code>.</li>
|
230
|
-
<li><code>matcher</code> is a <code>Regexp</code> to match against the user agent to detect the current platform.</li>
|
231
|
-
<li><code>label</code> is the human readable name of the platform.</li>
|
240
|
+
<li><code>name</code> is the name of the platform. Should be a <code>Symbol</code>.</li>
|
241
|
+
<li><code>matcher</code> is a <code>Regexp</code> to match against the user agent to detect the current platform.</li>
|
242
|
+
<li><code>label</code> is the human readable name of the platform.</li>
|
232
243
|
</ul>
|
233
244
|
|
234
245
|
<p>For example, for Mac OS X the call should be:</p>
|
235
246
|
|
236
|
-
<
|
237
|
-
|
247
|
+
<p><code>ruby
|
248
|
+
browser.register_platform(:osx, /mac|macintosh|mac os x/i, "Apple MacOS X")
|
249
|
+
</code></p>
|
238
250
|
|
239
|
-
<h3>Adding new languages</h3>
|
251
|
+
<h3 id="adding-new-languages">Adding new languages</h3>
|
240
252
|
|
241
253
|
<p>To add new languages, simply call <code>register_language</code>.</p>
|
242
254
|
|
@@ -244,32 +256,33 @@
|
|
244
256
|
|
245
257
|
<p>For example, for Italian the call should be:</p>
|
246
258
|
|
247
|
-
<
|
248
|
-
|
259
|
+
<p><code>ruby
|
260
|
+
browser.register_language("it", "Italian")
|
261
|
+
</code></p>
|
249
262
|
|
250
|
-
<h2>Contributing to brauser</h2>
|
263
|
+
<h2 id="contributing-to-brauser">Contributing to brauser</h2>
|
251
264
|
|
252
265
|
<ul>
|
253
|
-
<li>Check out the latest master to make sure the feature hasn&#
|
254
|
-
<li>Check out the issue tracker to make sure someone already hasn&#
|
255
|
-
<li>Fork the project.</li>
|
256
|
-
<li>Start a feature/bugfix branch.</li>
|
257
|
-
<li>Commit and push until you are happy with your contribution.</li>
|
258
|
-
<li>Make sure to add tests for it. This is important so I don&#
|
259
|
-
<li>Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.</li>
|
266
|
+
<li>Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.</li>
|
267
|
+
<li>Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.</li>
|
268
|
+
<li>Fork the project.</li>
|
269
|
+
<li>Start a feature/bugfix branch.</li>
|
270
|
+
<li>Commit and push until you are happy with your contribution.</li>
|
271
|
+
<li>Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.</li>
|
272
|
+
<li>Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.</li>
|
260
273
|
</ul>
|
261
274
|
|
262
|
-
<h2>Copyright</h2>
|
275
|
+
<h2 id="copyright">Copyright</h2>
|
263
276
|
|
264
|
-
<p>Copyright (C) 2013 and above Shogun (
|
277
|
+
<p>Copyright (C) 2013 and above Shogun (shogun_panda@me.com).</p>
|
265
278
|
|
266
|
-
<p>Licensed under the MIT license, which can be found at
|
279
|
+
<p>Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.</p>
|
267
280
|
</div></div>
|
268
281
|
|
269
282
|
<div id="footer">
|
270
|
-
Generated on
|
283
|
+
Generated on Fri Feb 8 08:12:31 2013 by
|
271
284
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
272
|
-
0.8.
|
285
|
+
0.8.4.1 (ruby-1.9.3).
|
273
286
|
</div>
|
274
287
|
|
275
288
|
</body>
|