rack-body_classes 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 226f2d4ab682d4f6db8994a742d668a2595a94e9
4
+ data.tar.gz: 9453609460896643dfd08b5c5a214d880bd336b0
5
+ SHA512:
6
+ metadata.gz: 7626d13169a13703c3fbfa051dfc209ea43290a2d52c1b30226554e59a4c805c7db893b0b9bfc7e6adb8e8a80c1e81f40ae0961d1f7f6622087ccdcb95ad6d5c
7
+ data.tar.gz: dfe6e0283c5c84c22d930471ac952bca291449db86e0afc111f861faaeeec45d99f7b36585d7a87272bc85929428cb45c4b257e360dd65b5d840c21e7d89e14a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-19mode
7
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+
5
+ group :test do
6
+ gem 'sinatra', require: false
7
+ gem 'minitest', require: false
8
+ gem 'minitest-spec-context', require: false
9
+ gem 'minitest-reporters', require: false
10
+ gem 'mocha', require: false
11
+ gem 'rack-test', require: false
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eric Marden
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,50 @@
1
+ # Rack::BodyClasses
2
+
3
+ Decorate your `<body>` with CSS Classes indicating platform, browser, browser version, and more.
4
+
5
+ ## Project Status
6
+
7
+ - Build: [![Build Status](https://secure.travis-ci.org/xentek/rack-body_classes.png)](http://travis-ci.org/xentek/rack-body_classes)
8
+ - Dependencies: [![Dependency Status](https://gemnasium.com/xentek/rack-body_classes.png)](https://gemnasium.com/xentek/rack-body_classes)
9
+ - Code Quality: [![Code Climate](https://d3s6mut3hikguw.cloudfront.net/github/xentek/rack-body_classes.png)](https://codeclimate.com/github/xentek/rack-body_classes)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'rack-body_classes'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ ## Usage
22
+
23
+ First, add the middlware to your application...
24
+
25
+ #### Rack/Sinatra
26
+
27
+ use Rack::BodyClasses
28
+
29
+ #### Rails
30
+
31
+ config.middleware.use Rack::BodyClasses
32
+
33
+
34
+ Then, in your layout, output `env['rack.body_classes']` in your `<body>` tag's `class` attribute.
35
+
36
+ Here's a trivial layout file, formatted with the `slim` templating engine, to give you an example:
37
+
38
+ html
39
+ head
40
+ body class="#{env['rack.body_classes']}"
41
+ == yield
42
+
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'rake'
4
+ require "bundler/gem_tasks"
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "spec"
8
+ t.pattern = "spec/**/*_spec.rb"
9
+ end
10
+ task :default => [:test]
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rack'
4
+ require 'browser'
5
+ require 'mobvious'
6
+ require 'rack/body_classes/version'
7
+
8
+ Mobvious.configure do |config|
9
+ config.strategies = [ Mobvious::Strategies::MobileESP.new(:mobile_tablet_desktop) ]
10
+ end
11
+
12
+ module Rack
13
+ class BodyClasses
14
+ def initialize(app)
15
+ @app = app
16
+ @mobvious = Mobvious::Manager.new(app)
17
+ end
18
+
19
+ 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(" ")
23
+ status, headers, body = @app.call(env)
24
+ [status, headers, body]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class BodyClasses
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $:.unshift(lib) unless $:.include?(lib)
5
+
6
+ require 'rack/body_classes/version'
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'rack-body_classes'
10
+ gem.version = Rack::BodyClasses::VERSION
11
+ gem.authors = ['Eric Marden']
12
+ gem.email = ['eric@xentek.net']
13
+ gem.description = %q{Decorate your <body> with CSS Classes indicating platform, browser, browser version, and more.}
14
+ gem.summary = %q{Decorate your <body> with CSS Classes}
15
+ gem.homepage = 'https://github.com/xentek/rack-body_classes'
16
+ gem.license = 'MIT'
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ['lib']
22
+
23
+ gem.add_dependency 'rack'
24
+ gem.add_dependency 'browser'
25
+ gem.add_dependency 'mobvious'
26
+
27
+ gem.add_development_dependency 'bundler', '~> 1.3'
28
+ gem.add_development_dependency 'rake'
29
+ gem.add_development_dependency 'gem-release'
30
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+
5
+
6
+ describe Rack::BodyClasses do
7
+ it "returns body classes" do
8
+ get '/'
9
+ last_response.body.must_match(/<body class="desktop other other0"><\/body>/)
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ ENV['RACK_ENV'] = 'test'
4
+
5
+ lib_path = File.expand_path('../../lib', __FILE__)
6
+ ($:.unshift lib_path) unless ($:.include? lib_path)
7
+
8
+ Bundler.setup(:default, ENV['RACK_ENV'])
9
+
10
+ require 'rack/body_classes'
11
+
12
+ require 'minitest/autorun'
13
+ require 'minitest/reporters'
14
+
15
+ MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
16
+
17
+ require 'rack/test'
18
+ include Rack::Test::Methods
19
+
20
+ require 'sinatra/base'
21
+ class App < Sinatra::Base
22
+ use Rack::BodyClasses
23
+ enable :logging
24
+
25
+ get '/' do
26
+ %Q{<html><head></head><body class="#{env['rack.body_classes']}"></body></html>}
27
+ end
28
+ end
29
+
30
+ def app
31
+ App.new
32
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-body_classes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Marden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: browser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mobvious
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: gem-release
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Decorate your <body> with CSS Classes indicating platform, browser, browser
98
+ version, and more.
99
+ email:
100
+ - eric@xentek.net
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .travis.yml
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/rack/body_classes.rb
112
+ - lib/rack/body_classes/version.rb
113
+ - rack-body_classes.gemspec
114
+ - spec/rack/body_classes_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/xentek/rack-body_classes
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.5
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Decorate your <body> with CSS Classes
140
+ test_files:
141
+ - spec/rack/body_classes_spec.rb
142
+ - spec/spec_helper.rb