cowtech-rails 1.3.0.0 → 1.4.0.0
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.
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This file is part of the cowtech-rails gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
|
4
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Cowtech
|
8
|
+
module RubyOnRails
|
9
|
+
module Helpers
|
10
|
+
module BrowserHelper
|
11
|
+
def browser_detect
|
12
|
+
rv = {:engine => :unknown, :version => "0", :platform => :unknown, :agent => request.user_agent || request.env['HTTP_USER_AGENT'].downcase || ""}
|
13
|
+
agent = rv[:agent].downcase
|
14
|
+
|
15
|
+
# Identify engine
|
16
|
+
if agent =~ /opera/ then
|
17
|
+
rv[:engine] = :opera
|
18
|
+
elsif agent =~ /webkit/ then
|
19
|
+
rv[:engine] = (agent =~ /chrome|chromium/ ? :chrome : :safari)
|
20
|
+
elsif agent =~ /msie/ || agent =~ /webtv/ then
|
21
|
+
rv[:engine] = :msie
|
22
|
+
elsif agent =~ /mozilla/ && agent !~ /compatible/ then
|
23
|
+
rv[:engine] = :mozilla
|
24
|
+
end
|
25
|
+
|
26
|
+
# Identify version
|
27
|
+
rv[:version] = $1 if agent =~ /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/
|
28
|
+
rv[:version_number] = rv[:version].to_f
|
29
|
+
|
30
|
+
# Identify platform
|
31
|
+
if agent =~ /linux/
|
32
|
+
rv[:platform] = :linux
|
33
|
+
elsif agent =~ /macintosh|mac os x/ then
|
34
|
+
rv[:platform] = :mac
|
35
|
+
elsif agent =~ /windows|win32|win64/ then
|
36
|
+
rv[:platform] = :windows
|
37
|
+
end
|
38
|
+
|
39
|
+
@browser = rv
|
40
|
+
end
|
41
|
+
|
42
|
+
def browser_classes
|
43
|
+
self.browser_detect unless @browser
|
44
|
+
rv = []
|
45
|
+
|
46
|
+
# Add name and platform
|
47
|
+
rv << @browser[:engine].to_s
|
48
|
+
rv << "platform-#{@browser[:platform].to_s}"
|
49
|
+
|
50
|
+
# Add versions
|
51
|
+
version = "version-"
|
52
|
+
i = -1
|
53
|
+
@browser[:version].split(/\./).each do |v|
|
54
|
+
i += 1
|
55
|
+
version += "#{i > 0 ? "_" : ""}#{v}"
|
56
|
+
rv << version
|
57
|
+
end
|
58
|
+
|
59
|
+
rv.join(" ")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -8,33 +8,6 @@ module Cowtech
|
|
8
8
|
module RubyOnRails
|
9
9
|
module Helpers
|
10
10
|
module FormatHelper
|
11
|
-
def browser
|
12
|
-
unless @browser then
|
13
|
-
rv = OpenStruct.new({:engine => :other, :version => 1.0})
|
14
|
-
|
15
|
-
unless request.env['HTTP_USER_AGENT'].blank? then
|
16
|
-
ua = request.env['HTTP_USER_AGENT'].downcase
|
17
|
-
|
18
|
-
if ua.index('msie') and !ua.index('opera') and !ua.index('webtv') then
|
19
|
-
rv.engine = :msie
|
20
|
-
rv.version = /.+msie ([0-9\.]+).+/.match(ua)[1].to_f
|
21
|
-
elsif ua.index('gecko/') or ua.index("mozilla/")
|
22
|
-
rv.engine = :gecko
|
23
|
-
elsif ua.index('opera')
|
24
|
-
rv.engine = :opera
|
25
|
-
elsif ua.index('konqueror')
|
26
|
-
rv.engine = :konqueror
|
27
|
-
elsif ua.index('webkit/')
|
28
|
-
rv.engine = :webkit
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
@browser = rv
|
33
|
-
end
|
34
|
-
|
35
|
-
@browser
|
36
|
-
end
|
37
|
-
|
38
11
|
def format_field(field, default = nil)
|
39
12
|
if field.is_a?(Fixnum) then
|
40
13
|
field
|
data/lib/cowtech/version.rb
CHANGED
metadata
CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
7
|
+
- 4
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.4.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shogun
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-19 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -29,6 +29,7 @@ extra_rdoc_files:
|
|
29
29
|
- README
|
30
30
|
files:
|
31
31
|
- app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb
|
32
|
+
- app/helpers/cowtech/ruby_on_rails/helpers/browser_helper.rb
|
32
33
|
- app/helpers/cowtech/ruby_on_rails/helpers/crud_helper.rb
|
33
34
|
- app/helpers/cowtech/ruby_on_rails/helpers/format_helper.rb
|
34
35
|
- app/helpers/cowtech/ruby_on_rails/helpers/validation_helper.rb
|