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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 226f2d4ab682d4f6db8994a742d668a2595a94e9
4
- data.tar.gz: 9453609460896643dfd08b5c5a214d880bd336b0
3
+ metadata.gz: dc7d86b8df2ce7b7aa90d6f6c8bbd296dd6ebb24
4
+ data.tar.gz: 4c98bb0a9eb0b13b4ca18697307dacf2ea52f757
5
5
  SHA512:
6
- metadata.gz: 7626d13169a13703c3fbfa051dfc209ea43290a2d52c1b30226554e59a4c805c7db893b0b9bfc7e6adb8e8a80c1e81f40ae0961d1f7f6622087ccdcb95ad6d5c
7
- data.tar.gz: dfe6e0283c5c84c22d930471ac952bca291449db86e0afc111f861faaeeec45d99f7b36585d7a87272bc85929428cb45c4b257e360dd65b5d840c21e7d89e14a
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.
@@ -2,26 +2,30 @@
2
2
 
3
3
  require 'rack'
4
4
  require 'browser'
5
- require 'mobvious'
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
- @mobvious.call(env)
21
- browser = Browser.new(ua: env["HTTP_USER_AGENT"], accept_language: env['HTTP_ACCEPT_LANGUAGE'])
22
- env['rack.body_classes'] = [env['mobvious.device_type'], browser.meta].flatten.compact.join(" ")
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class BodyClasses
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -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 'mobvious'
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.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-16 00:00:00.000000000 Z
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: mobvious
42
+ name: mobileesp_converted
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='