cssuseragent-rails 0.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/cssuseragent-rails.gemspec +19 -0
- data/lib/cssuseragent-rails.rb +8 -0
- data/lib/cssuseragent-rails/version.rb +5 -0
- data/vendor/assets/javascripts/cssua.js +343 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77fad83dca920c42dfaf07f228839a668556925d
|
4
|
+
data.tar.gz: db4ce167e7eae27a449625c43fd8973352df5eb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11cf7c450ef5ea25dd3b39fe6e38b9016d8c8099cc8ff5ab460e8826d39760f89fa589cfcb8380588395d71348016be33a3ab31cc08203bd656b8a0263c50686
|
7
|
+
data.tar.gz: d67bce6d9f951cd684da8785329b396ebf66274c2d73dfd2cfa4790bedfa662c89d4afd66bf8e78328f6131f36e99bc78f62d87defbf26e44eb3b76af8b73ebe
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Robb Irrgang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# cssuseragent
|
2
|
+
|
3
|
+
Integrates [cssuseragent](http://cssuseragent.org) with the rails asset pipeline.
|
4
|
+
|
5
|
+
CssUserAgent is written by Stephen M. McKamey.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'cssuseragent'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install cssuseragent
|
20
|
+
|
21
|
+
Add this to your application.js file:
|
22
|
+
|
23
|
+
//= require cssuseragent
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cssuseragent"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/cssuseragent-rails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Robb Irrgang"]
|
6
|
+
gem.email = ["robb@irrg.org"]
|
7
|
+
gem.description = %q{CSSUserAgent for use in Rails asset pipeline}
|
8
|
+
gem.summary = %q{add UA dependent class names to the HTML element}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "cssuseragent-rails"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Cssuseragent::Rails::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "railties", "> 3.1"
|
19
|
+
end
|
@@ -0,0 +1,343 @@
|
|
1
|
+
/**
|
2
|
+
* CssUserAgent (cssua.js) v2.1.28
|
3
|
+
* http://cssuseragent.org
|
4
|
+
*
|
5
|
+
* Copyright (c)2006-2014 Stephen M. McKamey.
|
6
|
+
* Licensed under The MIT License.
|
7
|
+
*/
|
8
|
+
/*jshint smarttabs:true, regexp:false, browser:true */
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @type {Object}
|
12
|
+
*/
|
13
|
+
var cssua = (
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @param html {Object} root DOM element
|
17
|
+
* @param userAgent {string} browser userAgent string
|
18
|
+
* @return {Object}
|
19
|
+
*/
|
20
|
+
function(html, userAgent, sa) {
|
21
|
+
'use strict';
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @const
|
25
|
+
* @type {string}
|
26
|
+
*/
|
27
|
+
var PREFIX = ' ua-';
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @const
|
31
|
+
* @type {RegExp}
|
32
|
+
*/
|
33
|
+
var R_Platform = /\s*([\-\w ]+)[\s\/\:]([\d_]+\b(?:[\-\._\/]\w+)*)/;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* @const
|
37
|
+
* @type {RegExp}
|
38
|
+
*/
|
39
|
+
var R_Version = /([\w\-\.]+[\s\/][v]?[\d_]+\b(?:[\-\._\/]\w+)*)/g;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @const
|
43
|
+
* @type {RegExp}
|
44
|
+
*/
|
45
|
+
var R_BlackBerry = /\b(?:(blackberry\w*|bb10)|(rim tablet os))(?:\/(\d+\.\d+(?:\.\w+)*))?/;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @const
|
49
|
+
* @type {RegExp}
|
50
|
+
*/
|
51
|
+
var R_Silk = /\bsilk-accelerated=true\b/;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @const
|
55
|
+
* @type {RegExp}
|
56
|
+
*/
|
57
|
+
var R_FluidApp = /\bfluidapp\b/;
|
58
|
+
|
59
|
+
/**
|
60
|
+
* @const
|
61
|
+
* @type {RegExp}
|
62
|
+
*/
|
63
|
+
var R_desktop = /(\bwindows\b|\bmacintosh\b|\blinux\b|\bunix\b)/;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* @const
|
67
|
+
* @type {RegExp}
|
68
|
+
*/
|
69
|
+
var R_mobile = /(\bandroid\b|\bipad\b|\bipod\b|\bwindows phone\b|\bwpdesktop\b|\bxblwp7\b|\bzunewp7\b|\bwindows ce\b|\bblackberry\w*|\bbb10\b|\brim tablet os\b|\bmeego|\bwebos\b|\bpalm|\bsymbian|\bj2me\b|\bdocomo\b|\bpda\b|\bchtml\b|\bmidp\b|\bcldc\b|\w*?mobile\w*?|\w*?phone\w*?)/;
|
70
|
+
|
71
|
+
/**
|
72
|
+
* @const
|
73
|
+
* @type {RegExp}
|
74
|
+
*/
|
75
|
+
var R_game = /(\bxbox\b|\bplaystation\b|\bnintendo\s+\w+)/;
|
76
|
+
|
77
|
+
/**
|
78
|
+
* The root CssUserAgent
|
79
|
+
* @type {Object}
|
80
|
+
*/
|
81
|
+
var cssua = {
|
82
|
+
|
83
|
+
parse:
|
84
|
+
/**
|
85
|
+
* @param uaStr {string}
|
86
|
+
* @return {Object}
|
87
|
+
*/
|
88
|
+
function(uaStr, sa) {
|
89
|
+
|
90
|
+
/**
|
91
|
+
* @type {Object}
|
92
|
+
*/
|
93
|
+
var ua = {};
|
94
|
+
if (sa) {
|
95
|
+
ua.standalone = sa;
|
96
|
+
}
|
97
|
+
|
98
|
+
uaStr = (''+uaStr).toLowerCase();
|
99
|
+
if (!uaStr) {
|
100
|
+
return ua;
|
101
|
+
}
|
102
|
+
|
103
|
+
var i, count, raw = uaStr.split(/[()]/);
|
104
|
+
for (var j=0, rawCount=raw.length; j<rawCount; j++) {
|
105
|
+
if (j%2) {
|
106
|
+
// inside parens covers platform identifiers
|
107
|
+
var platforms = raw[j].split(';');
|
108
|
+
for (i=0, count=platforms.length; i<count; i++) {
|
109
|
+
if (R_Platform.exec(platforms[i])) {
|
110
|
+
var key = RegExp.$1.split(' ').join('_'),
|
111
|
+
val = RegExp.$2;
|
112
|
+
|
113
|
+
// if duplicate entries favor highest version
|
114
|
+
if ((!ua[key] || parseFloat(ua[key]) < parseFloat(val))) {
|
115
|
+
ua[key] = val;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
} else {
|
121
|
+
// outside parens covers most version identifiers
|
122
|
+
var uas = raw[j].match(R_Version);
|
123
|
+
if (uas) {
|
124
|
+
for (i=0, count=uas.length; i<count; i++) {
|
125
|
+
var parts = uas[i].split(/[\/\s]+/);
|
126
|
+
if (parts.length && parts[0] !== 'mozilla') {
|
127
|
+
ua[parts[0].split(' ').join('_')] = parts.slice(1).join('-');
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
if (R_mobile.exec(uaStr)) {
|
135
|
+
// mobile device indicators
|
136
|
+
ua.mobile = RegExp.$1;
|
137
|
+
if (R_BlackBerry.exec(uaStr)) {
|
138
|
+
delete ua[ua.mobile];
|
139
|
+
ua.blackberry = ua.version || RegExp.$3 || RegExp.$2 || RegExp.$1;
|
140
|
+
if (RegExp.$1) {
|
141
|
+
// standardize non-tablet blackberry
|
142
|
+
ua.mobile = 'blackberry';
|
143
|
+
} else if (ua.version === '0.0.1') {
|
144
|
+
// fix playbook 1.0 quirk
|
145
|
+
ua.blackberry = '7.1.0.0';
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
} else if (R_desktop.exec(uaStr)) {
|
150
|
+
// desktop OS indicators
|
151
|
+
ua.desktop = RegExp.$1;
|
152
|
+
|
153
|
+
} else if (R_game.exec(uaStr)) {
|
154
|
+
// game console indicators
|
155
|
+
ua.game = RegExp.$1;
|
156
|
+
var game = ua.game.split(' ').join('_');
|
157
|
+
|
158
|
+
if (ua.version && !ua[game]) {
|
159
|
+
ua[game] = ua.version;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
// platform naming standardizations
|
164
|
+
if (ua.intel_mac_os_x) {
|
165
|
+
ua.mac_os_x = ua.intel_mac_os_x.split('_').join('.');
|
166
|
+
delete ua.intel_mac_os_x;
|
167
|
+
|
168
|
+
} else if (ua.cpu_iphone_os) {
|
169
|
+
ua.ios = ua.cpu_iphone_os.split('_').join('.');
|
170
|
+
delete ua.cpu_iphone_os;
|
171
|
+
|
172
|
+
} else if (ua.cpu_os) {
|
173
|
+
ua.ios = ua.cpu_os.split('_').join('.');
|
174
|
+
delete ua.cpu_os;
|
175
|
+
|
176
|
+
} else if (ua.mobile === 'iphone' && !ua.ios) {
|
177
|
+
ua.ios = '1';
|
178
|
+
}
|
179
|
+
|
180
|
+
// UA naming standardizations
|
181
|
+
if (ua.opera && ua.version) {
|
182
|
+
ua.opera = ua.version;
|
183
|
+
// version/XXX refers to opera
|
184
|
+
delete ua.blackberry;
|
185
|
+
|
186
|
+
} else if (R_Silk.exec(uaStr)) {
|
187
|
+
ua.silk_accelerated = true;
|
188
|
+
|
189
|
+
} else if (R_FluidApp.exec(uaStr)) {
|
190
|
+
ua.fluidapp = ua.version;
|
191
|
+
}
|
192
|
+
|
193
|
+
if (ua.applewebkit) {
|
194
|
+
ua.webkit = ua.applewebkit;
|
195
|
+
delete ua.applewebkit;
|
196
|
+
|
197
|
+
if (ua.opr) {
|
198
|
+
ua.opera = ua.opr;
|
199
|
+
delete ua.opr;
|
200
|
+
delete ua.chrome;
|
201
|
+
}
|
202
|
+
|
203
|
+
if (ua.safari) {
|
204
|
+
if (ua.chrome || ua.crios || ua.opera || ua.silk || ua.fluidapp || ua.phantomjs || (ua.mobile && !ua.ios)) {
|
205
|
+
delete ua.safari;
|
206
|
+
|
207
|
+
} else if (ua.version && !ua.rim_tablet_os) {
|
208
|
+
ua.safari = ua.version;
|
209
|
+
|
210
|
+
} else {
|
211
|
+
ua.safari = ({
|
212
|
+
'419': '2.0.4',
|
213
|
+
'417': '2.0.3',
|
214
|
+
'416': '2.0.2',
|
215
|
+
'412': '2.0',
|
216
|
+
'312': '1.3',
|
217
|
+
'125': '1.2',
|
218
|
+
'85': '1.0'
|
219
|
+
})[parseInt(ua.safari, 10)] || ua.safari;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
} else if (ua.msie || ua.trident) {
|
224
|
+
if (!ua.opera) {
|
225
|
+
// standardize Internet Explorer
|
226
|
+
ua.ie = ua.msie || ua.rv;
|
227
|
+
}
|
228
|
+
delete ua.msie;
|
229
|
+
|
230
|
+
if (ua.windows_phone_os) {
|
231
|
+
// standardize window phone
|
232
|
+
ua.windows_phone = ua.windows_phone_os;
|
233
|
+
delete ua.windows_phone_os;
|
234
|
+
|
235
|
+
} else if (ua.mobile === 'wpdesktop' || ua.mobile === 'xblwp7' || ua.mobile === 'zunewp7') {
|
236
|
+
ua.mobile = 'windows desktop';
|
237
|
+
ua.windows_phone = (+ua.ie < 9) ? '7.0' : (+ua.ie < 10) ? '7.5' : '8.0';
|
238
|
+
delete ua.windows_nt;
|
239
|
+
}
|
240
|
+
|
241
|
+
} else if (ua.gecko || ua.firefox) {
|
242
|
+
ua.gecko = ua.rv;
|
243
|
+
}
|
244
|
+
|
245
|
+
if (ua.rv) {
|
246
|
+
delete ua.rv;
|
247
|
+
}
|
248
|
+
if (ua.version) {
|
249
|
+
delete ua.version;
|
250
|
+
}
|
251
|
+
|
252
|
+
return ua;
|
253
|
+
},
|
254
|
+
|
255
|
+
format:
|
256
|
+
/**
|
257
|
+
* @param ua {Object}
|
258
|
+
* @return {string}
|
259
|
+
*/
|
260
|
+
function (ua) {
|
261
|
+
/**
|
262
|
+
* @param b {string} browser key
|
263
|
+
* @param v {string} browser value
|
264
|
+
* @return {string} formatted CSS classes
|
265
|
+
*/
|
266
|
+
function format(b, v) {
|
267
|
+
b = b.split('.').join('-');
|
268
|
+
|
269
|
+
/**
|
270
|
+
* @type {string}
|
271
|
+
*/
|
272
|
+
var css = PREFIX+b;
|
273
|
+
if (typeof v === 'string') {
|
274
|
+
v = v.split(' ').join('_').split('.').join('-');
|
275
|
+
var i = v.indexOf('-');
|
276
|
+
while (i > 0) {
|
277
|
+
// loop through chopping last '-' to end off
|
278
|
+
// concat result onto return string
|
279
|
+
css += PREFIX+b+'-'+v.substring(0, i);
|
280
|
+
i = v.indexOf('-', i+1);
|
281
|
+
}
|
282
|
+
css += PREFIX+b+'-'+v;
|
283
|
+
}
|
284
|
+
return css;
|
285
|
+
}
|
286
|
+
|
287
|
+
/**
|
288
|
+
* @type {string}
|
289
|
+
*/
|
290
|
+
var uaCss = '';
|
291
|
+
for (var b in ua) {
|
292
|
+
if (b && ua.hasOwnProperty(b)) {
|
293
|
+
uaCss += format(b, ua[b]);
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
// user-agent classNames
|
298
|
+
return uaCss;
|
299
|
+
},
|
300
|
+
|
301
|
+
encode:
|
302
|
+
/**
|
303
|
+
* Encodes parsed userAgent object as a compact URI-Encoded key-value collection
|
304
|
+
* @param ua {Object}
|
305
|
+
* @return {string}
|
306
|
+
*/
|
307
|
+
function(ua) {
|
308
|
+
var query = '';
|
309
|
+
for (var b in ua) {
|
310
|
+
if (b && ua.hasOwnProperty(b)) {
|
311
|
+
if (query) {
|
312
|
+
query += '&';
|
313
|
+
}
|
314
|
+
query += encodeURIComponent(b)+'='+encodeURIComponent(ua[b]);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
return query;
|
318
|
+
}
|
319
|
+
};
|
320
|
+
|
321
|
+
/**
|
322
|
+
* @const
|
323
|
+
* @type {Object}
|
324
|
+
*/
|
325
|
+
cssua.userAgent = cssua.ua = cssua.parse(userAgent, sa);
|
326
|
+
|
327
|
+
/**
|
328
|
+
* @const
|
329
|
+
* @type {string}
|
330
|
+
*/
|
331
|
+
var ua = cssua.format(cssua.ua)+' js';
|
332
|
+
|
333
|
+
// append CSS classes to HTML node
|
334
|
+
if (html.className) {
|
335
|
+
html.className = html.className.replace(/\bno-js\b/g, '') + ua;
|
336
|
+
|
337
|
+
} else {
|
338
|
+
html.className = ua.substr(1);
|
339
|
+
}
|
340
|
+
|
341
|
+
return cssua;
|
342
|
+
|
343
|
+
})(document.documentElement, navigator.userAgent, navigator.standalone);
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cssuseragent-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robb Irrgang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
description: CSSUserAgent for use in Rails asset pipeline
|
28
|
+
email:
|
29
|
+
- robb@irrg.org
|
30
|
+
executables:
|
31
|
+
- console
|
32
|
+
- setup
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- bin/console
|
42
|
+
- bin/setup
|
43
|
+
- cssuseragent-rails.gemspec
|
44
|
+
- lib/cssuseragent-rails.rb
|
45
|
+
- lib/cssuseragent-rails/version.rb
|
46
|
+
- vendor/assets/javascripts/cssua.js
|
47
|
+
homepage: ''
|
48
|
+
licenses: []
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.2.0
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: add UA dependent class names to the HTML element
|
70
|
+
test_files: []
|