midas-guilded 0.2.6 → 0.2.7
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.
- data/History.txt +10 -0
- data/guilded.gemspec +1 -1
- data/lib/guilded.rb +1 -1
- data/lib/guilded/browser_detector.rb +28 -24
- data/lib/guilded/rails/view_helpers.rb +24 -8
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
= 0.2.7 2009-06-10
|
2
|
+
|
3
|
+
* Changed the BrowserDetector to need to be instantiated to use. No longer just static methods.
|
4
|
+
|
5
|
+
|
6
|
+
= 0.2.6 2009-06-10
|
7
|
+
|
8
|
+
* Added some more view helpers for the browser detector.
|
9
|
+
|
10
|
+
|
1
11
|
= 0.2.5 2009-06-10
|
2
12
|
|
3
13
|
* Added BrowserDetector to assist with determining which browser is making a request.
|
data/guilded.gemspec
CHANGED
data/lib/guilded.rb
CHANGED
@@ -73,7 +73,7 @@ require 'guilded/rails/inactive_record/human_attribute_hint'
|
|
73
73
|
# <%= g_load_alerter :skin => 'blueish', :id => 'load_alerter' %>
|
74
74
|
#
|
75
75
|
module Guilded
|
76
|
-
VERSION = '0.2.
|
76
|
+
VERSION = '0.2.7'
|
77
77
|
end
|
78
78
|
|
79
79
|
ActionView::Base.send( :include, Guilded::Rails::ViewHelpers ) if defined?( ActionView )
|
@@ -5,6 +5,10 @@ module Guilded
|
|
5
5
|
#
|
6
6
|
class BrowserDetector
|
7
7
|
|
8
|
+
def initialize( request )
|
9
|
+
@request = request
|
10
|
+
end
|
11
|
+
|
8
12
|
# Returns true if the browser matches the options ent in, otherwise returns false.
|
9
13
|
#
|
10
14
|
# === Request
|
@@ -14,15 +18,14 @@ module Guilded
|
|
14
18
|
# * +:name+ - The name of the browser. For example 'ie'.
|
15
19
|
# * +:version+ - The version of the browser. For example '7'.
|
16
20
|
#
|
17
|
-
def
|
18
|
-
#name = name.to_s.strip
|
21
|
+
def browser_is?( options={} )
|
19
22
|
name = options[:name].to_s.strip
|
20
23
|
version = options[:version].to_s.strip
|
21
24
|
|
22
|
-
return true if browser_name
|
23
|
-
return true if name == 'mozilla' && browser_name
|
24
|
-
return true if name == 'ie' && browser_name
|
25
|
-
return true if name == 'webkit' && browser_name
|
25
|
+
return true if browser_name == name
|
26
|
+
return true if name == 'mozilla' && browser_name == 'gecko'
|
27
|
+
#return true if name == 'ie' && browser_name.index( 'ie' )
|
28
|
+
return true if name == 'webkit' && browser_name == 'safari'
|
26
29
|
end
|
27
30
|
|
28
31
|
# Returns the name of the browser that is making this request. For example 'ie'.
|
@@ -30,9 +33,9 @@ module Guilded
|
|
30
33
|
# === Request
|
31
34
|
# * +request+ - The request object.
|
32
35
|
#
|
33
|
-
def
|
36
|
+
def browser_name
|
34
37
|
@browser_name ||= begin
|
35
|
-
ua = request.env['HTTP_USER_AGENT']
|
38
|
+
ua = @request.env['HTTP_USER_AGENT']
|
36
39
|
if ua.nil?
|
37
40
|
'unknown'
|
38
41
|
else
|
@@ -40,9 +43,9 @@ module Guilded
|
|
40
43
|
|
41
44
|
if ua.index( 'msie' ) && !ua.index( 'opera' ) && !ua.index( 'webtv' )
|
42
45
|
if ua.index( 'windows ce' )
|
43
|
-
'ie' + ua[ua.index( 'msie' ) + 5].chr
|
46
|
+
'ie' + '_ce' #+ ua[ua.index( 'msie' ) + 5].chr
|
44
47
|
else
|
45
|
-
'ie' + ua[ua.index( 'msie' ) + 5].chr
|
48
|
+
'ie' # + ua[ua.index( 'msie' ) + 5].chr
|
46
49
|
end
|
47
50
|
elsif ua.index( 'netscape' )
|
48
51
|
'netscape'
|
@@ -70,8 +73,8 @@ module Guilded
|
|
70
73
|
# === Request
|
71
74
|
# * +request+ - The request object.
|
72
75
|
#
|
73
|
-
def
|
74
|
-
browser_name
|
76
|
+
def browser_full_name
|
77
|
+
browser_name + browser_version
|
75
78
|
end
|
76
79
|
|
77
80
|
# Returns the version of the browser that is making this request. For example '7'.
|
@@ -79,26 +82,27 @@ module Guilded
|
|
79
82
|
# === Request
|
80
83
|
# * +request+ - The request object.
|
81
84
|
#
|
82
|
-
def
|
85
|
+
def browser_version
|
83
86
|
@browser_version ||= begin
|
84
|
-
ua = request.env['HTTP_USER_AGENT'].downcase
|
87
|
+
ua = @request.env['HTTP_USER_AGENT'].downcase
|
85
88
|
|
86
|
-
if browser_name
|
89
|
+
if browser_name == 'opera'
|
87
90
|
ua[ua.index( 'opera' ) + 6].chr
|
88
|
-
elsif browser_name
|
89
|
-
ua[ua.index( 'firefox' ) + 8
|
90
|
-
elsif browser_name
|
91
|
+
elsif browser_name == 'firefox'
|
92
|
+
ua[ua.index( 'firefox' ) + 8].chr
|
93
|
+
elsif browser_name == 'netscape'
|
91
94
|
ua[ua.index( 'netscape' ) + 9].chr
|
92
|
-
elsif browser_name
|
95
|
+
elsif browser_name.index( 'ie' )
|
93
96
|
ua[ua.index( 'msie' ) + 5].chr
|
97
|
+
elsif browser_name.index( 'safari' )
|
98
|
+
ua[ua.index( 'version' ) + 8].chr
|
94
99
|
else
|
95
100
|
'unknown'
|
96
101
|
end
|
97
|
-
|
98
102
|
end
|
99
103
|
end
|
100
104
|
|
101
|
-
def
|
105
|
+
def can_use_png?
|
102
106
|
if browser_name.index( 'ie' ) == 0
|
103
107
|
if browser_version.to_i < 7
|
104
108
|
false
|
@@ -113,12 +117,12 @@ module Guilded
|
|
113
117
|
end
|
114
118
|
|
115
119
|
def self.all_browsers
|
116
|
-
%W( ie7, ie6, opera, firefox, netscape, konqueror, safari )
|
120
|
+
%W( ie8, ie7, ie6, opera, firefox, netscape, konqueror, safari )
|
117
121
|
end
|
118
122
|
|
119
123
|
def self.all_mobile_browsers
|
120
|
-
%w(
|
124
|
+
%w( ie_ce4 )
|
121
125
|
end
|
122
|
-
|
126
|
+
|
123
127
|
end
|
124
128
|
end
|
@@ -83,32 +83,48 @@ module Guilded
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
# Returns the name of the browser that is making this request. For example 'ie'.
|
86
|
+
# Returns the name of the browser that is making this request. For example 'ie'. When using
|
87
|
+
# the browser detector in the contoller you may put a :g_browser_detector variabe in the session if
|
88
|
+
# you wish to keep the BrowserDetector from being instantiated more than once per request.
|
87
89
|
#
|
88
90
|
def g_browser_name
|
89
|
-
|
91
|
+
@g_browser_detector = session[:g_browser_detector] if respond_to?( :session )
|
92
|
+
@g_browser_detector ||= Guilded::BrowserDetector.new( request )
|
93
|
+
@g_browser_detector.browser_name
|
90
94
|
end
|
91
95
|
|
92
|
-
# Returns the version of the browser that is making this request. For example '7'.
|
96
|
+
# Returns the version of the browser that is making this request. For example '7'. When using
|
97
|
+
# the browser detector in the contoller you may put a :g_browser_detector variabe in the session if
|
98
|
+
# you wish to keep the BrowserDetector from being instantiated more than once per request.
|
93
99
|
#
|
94
100
|
def g_browser_version
|
95
|
-
|
101
|
+
@g_browser_detector = session[:g_browser_detector] if respond_to?( :session )
|
102
|
+
@g_browser_detector ||= Guilded::BrowserDetector.new( request )
|
103
|
+
@g_browser_detector.browser_version
|
96
104
|
end
|
97
105
|
|
98
|
-
# Returns the browser name concatenated with the browser version. for example, 'ie7'.
|
106
|
+
# Returns the browser name concatenated with the browser version. for example, 'ie7'. When using
|
107
|
+
# the browser detector in the contoller you may put a :g_browser_detector variabe in the session if
|
108
|
+
# you wish to keep the BrowserDetector from being instantiated more than once per request.
|
99
109
|
#
|
100
110
|
def g_browser_full_name
|
101
|
-
|
111
|
+
@g_browser_detector = session[:g_browser_detector] if respond_to?( :session )
|
112
|
+
@g_browser_detector ||= Guilded::BrowserDetector.new( request )
|
113
|
+
@g_browser_detector.browser_full_name
|
102
114
|
end
|
103
115
|
|
104
|
-
# Returns true if the browser matches the options ent in, otherwise returns false.
|
116
|
+
# Returns true if the browser matches the options ent in, otherwise returns false. When using
|
117
|
+
# the browser detector in the contoller you may put a :g_browser_detector variabe in the session if
|
118
|
+
# you wish to keep the BrowserDetector from being instantiated more than once per request.
|
105
119
|
#
|
106
120
|
# === Options
|
107
121
|
# * +:name+ - The name of the browser. For example 'ie'.
|
108
122
|
# * +:version+ - The version of the browser. For example '7'.
|
109
123
|
#
|
110
124
|
def g_browser_is?( options={} )
|
111
|
-
|
125
|
+
@g_browser_detector = session[:g_browser_detector] if respond_to?( :session )
|
126
|
+
@g_browser_detector ||= Guilded::BrowserDetector.new( request )
|
127
|
+
@g_browser_detector.browser_is?( options )
|
112
128
|
end
|
113
129
|
|
114
130
|
end
|