rack-body_classes 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/rack/body_classes.rb +13 -9
- data/lib/rack/body_classes/version.rb +1 -1
- data/rack-body_classes.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc7d86b8df2ce7b7aa90d6f6c8bbd296dd6ebb24
|
4
|
+
data.tar.gz: 4c98bb0a9eb0b13b4ca18697307dacf2ea52f757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9d8078ec67e995486269ce1f8a18877fd50be922f29787bcec4a3937869cb28c5465a999038d09f2ef452bc3e8bb872276f88003896f738074bef4c1fe9137
|
7
|
+
data.tar.gz: 49a135ba32810023c624facdd47ad856101a59ed3244f3e54d55fa474b4e61ead638d7e2b808bc121dad4953f08fe60aaa660e6ff71a61e15300e9373cb3e58e
|
data/README.md
CHANGED
@@ -40,7 +40,10 @@ Here's a trivial layout file, formatted with the `slim` templating engine, to gi
|
|
40
40
|
body class="#{env['rack.body_classes']}"
|
41
41
|
== yield
|
42
42
|
|
43
|
-
|
43
|
+
When rendered, the body tag will look something like this:
|
44
|
+
|
45
|
+
<body class="desktop chrome modern mac webkit">
|
46
|
+
|
44
47
|
## Contributing
|
45
48
|
|
46
49
|
1. Fork it
|
@@ -48,3 +51,7 @@ Here's a trivial layout file, formatted with the `slim` templating engine, to gi
|
|
48
51
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
52
|
4. Push to the branch (`git push origin my-new-feature`)
|
50
53
|
5. Create new Pull Request
|
54
|
+
|
55
|
+
## Shout Outs
|
56
|
+
|
57
|
+
This middleware is made possible by `Browser` [gem](https://github.com/fnando/browser) and `MobileESP (converted)` [gem](https://github.com/jistr/mobileesp_converted) and borrows a bit of code from `Mobvious` [gem](https://github.com/jistr/mobvious). Mad props and many thank yous to these gem authors.
|
data/lib/rack/body_classes.rb
CHANGED
@@ -2,26 +2,30 @@
|
|
2
2
|
|
3
3
|
require 'rack'
|
4
4
|
require 'browser'
|
5
|
-
require '
|
5
|
+
require 'mobileesp_converted'
|
6
6
|
require 'rack/body_classes/version'
|
7
7
|
|
8
|
-
Mobvious.configure do |config|
|
9
|
-
config.strategies = [ Mobvious::Strategies::MobileESP.new(:mobile_tablet_desktop) ]
|
10
|
-
end
|
11
|
-
|
12
8
|
module Rack
|
13
9
|
class BodyClasses
|
14
10
|
def initialize(app)
|
15
11
|
@app = app
|
16
|
-
@mobvious = Mobvious::Manager.new(app)
|
17
12
|
end
|
18
13
|
|
19
14
|
def call(env)
|
20
|
-
|
21
|
-
|
22
|
-
env['rack.body_classes'] = [
|
15
|
+
browser = Browser.new(ua: env["HTTP_USER_AGENT"], accept_language: env['HTTP_ACCEPT_LANGUAGE']).meta
|
16
|
+
device = mobile_esp(env["HTTP_USER_AGENT"], env['HTTP_ACCEPT'])
|
17
|
+
env['rack.body_classes'] = [device, browser].flatten.compact.join(" ")
|
23
18
|
status, headers, body = @app.call(env)
|
24
19
|
[status, headers, body]
|
25
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def mobile_esp(user_agent, http_accept)
|
25
|
+
mobileesp = MobileESPConverted::UserAgentInfo.new(user_agent, http_accept)
|
26
|
+
return :mobile if mobileesp.is_tier_generic_mobile || mobileesp.is_tier_iphone || mobileesp.is_tier_rich_css
|
27
|
+
return :tablet if mobileesp.is_tier_tablet
|
28
|
+
return :desktop
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
data/rack-body_classes.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
|
|
22
22
|
|
23
23
|
gem.add_dependency 'rack'
|
24
24
|
gem.add_dependency 'browser'
|
25
|
-
gem.add_dependency '
|
25
|
+
gem.add_dependency 'mobileesp_converted'
|
26
26
|
|
27
27
|
gem.add_development_dependency 'bundler', '~> 1.3'
|
28
28
|
gem.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-body_classes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Marden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: mobileesp_converted
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '>='
|