which_browser 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,22 +1,53 @@
1
1
  Which Browser
2
- -------------
2
+ =============
3
3
 
4
- Which Browser adds a few helper methods to a rack request so you can write cleaner logic in your views.
4
+ Which Browser adds a few helper methods to a rack request so you can write cleaner browser-related logic.
5
5
 
6
6
  For example, the age old battle against IE 5 & 6 can be handled like so:
7
7
 
8
- stylesheet_link_tag "ie" if request.old_ie?
8
+ stylesheet_link_tag "ie" if request.ie_lt7?
9
+
10
+ And for a nice browser warning:
11
+
12
+ - if request.ie6?
13
+ IE6 makes the internet suck.
14
+ - elsif request.ie5?
15
+ You've got to be kidding me.
16
+
17
+
18
+ Or in your rails controller, decide which layout:
19
+
20
+ render :layout => request.mobile_safari? ? 'mobile' : 'application'
21
+
9
22
 
10
23
 
11
24
  Here's some other popular helpers:
12
25
 
13
26
  request.ie?
14
27
  request.ie6?
28
+ request.ie_lt6?
29
+ request.ie_gte7?
30
+
15
31
  request.ipad?
16
32
  request.ipod?
17
33
  request.iphone?
18
34
  request.mobile_safari?
19
-
35
+
36
+
37
+
38
+ Testing
39
+ -------
40
+
41
+ Shouda tests can be run with:
42
+
43
+ git clone git://github.com/citrus/which_browser.git
44
+ rake
45
+
46
+ There is also a ramaze app in test/dummy for a demo, development and real-life testing. Install ramaze (`gem install ramaze`) if you don't have it, then run:
47
+
48
+ ruby test/dummy/app.rb
49
+
50
+ Now open your browser to [http://localhost:7000](http://localhost:7000)
20
51
 
21
52
 
22
53
  License
data/lib/which_browser.rb CHANGED
@@ -46,6 +46,7 @@ module WhichBrowser
46
46
  def firefox?
47
47
  test_user_agent(/Firefox/)
48
48
  end
49
+ alias :ff? :firefox?
49
50
 
50
51
  def chrome?
51
52
  test_user_agent(/Chrome/)
@@ -1,3 +1,3 @@
1
1
  module WhichBrowser
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/test/dummy/app.rb CHANGED
@@ -5,20 +5,28 @@ require File.expand_path("../../../lib/which_browser", __FILE__)
5
5
 
6
6
  class MainController < Ramaze::Controller
7
7
  def index
8
- {
9
8
 
10
- "USER AGENT" => request.user_agent,
11
- "IE" => request.ie?,
12
- "IE 6?" => request.ie6?,
13
- "IE 7?" => request.ie7?,
14
- "IE LT 6?" => request.ie_lt6?,
15
- "IE LT 7?" => request.ie_lt7?,
16
- "IE GT 7?" => request.ie_gt7?,
17
- "IE LTE 6?" => request.ie_lte6?,
18
- "IE LTE 7?" => request.ie_lte7?,
19
- "IE GTE 7?" => request.ie_gte7?
20
- }.to_a.collect!{ |key,value|
21
- "#{key}: \t\t #{value}"
9
+ # add other methods you'd like to see to the list:
10
+ [
11
+ :user_agent,
12
+ :ie?,
13
+ :ie6?,
14
+ :ie_lt6?,
15
+ :ie_lte7?,
16
+ :ie_gte6?,
17
+ :safari?,
18
+ :safari_version,
19
+ :ff?,
20
+ :ff_version,
21
+ :opera?,
22
+ :chrome?,
23
+ :chrome?,
24
+ :pc?,
25
+ :mac?,
26
+ :linux?
27
+ ].collect{ |method|
28
+ v = request.send(method)
29
+ %(#{method} &nbsp; <span style="color: #{v == false ? 'red' : 'green' }; font-weight: #{v == false ? 'normal' : 'bold'}">#{v}</span>)
22
30
  }.join("<br/>")
23
31
  end
24
32
  end
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_dependency('rack', '>= 1.0.1')
21
+
21
22
  s.add_development_dependency('shoulda', '>= 2.11.3')
23
+ s.add_development_dependency('ramaze', '>= 2011.01.30')
22
24
 
23
25
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: which_browser
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Spencer Steffen
@@ -35,6 +35,17 @@ dependencies:
35
35
  version: 2.11.3
36
36
  type: :development
37
37
  version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: ramaze
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2011.01.30
47
+ type: :development
48
+ version_requirements: *id003
38
49
  description: Which Browser adds a few helper methods to a rack request.
39
50
  email:
40
51
  - spencer@citrusme.com