Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added gemspec

  • Loading branch information...
commit 6824946edf6310acd96faf4614c90ef182783ad8 1 parent 038b1a7
@tmlee tmlee authored faun committed
View
4 Gemfile
@@ -0,0 +1,4 @@
+source :gemcutter
+
+# Specify your gem's dependencies in browser_detect.gemspec
+gemspec
View
2  Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
View
22 browser_detect.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path("../lib/browser_detect/version", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "browser_detect"
+ s.version = "0.0.1"
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["faunzy"]
+ s.email = []
+ s.homepage = "http://rubygems.org/gems/browser_detect"
+ s.summary = "Detects the client's browser"
+ s.description = "Detects the client's browser"
+
+ s.required_rubygems_version = ">= 1.3.6"
+ s.rubyforge_project = "browser_detect"
+
+ s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
+
+ s.files = `git ls-files`.split("\n")
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
+ s.require_path = 'lib'
+end
View
2  lib/browser_detect.rb
@@ -0,0 +1,2 @@
+require 'browser_detect/browser_detect_helper'
+ActionView::Base.send(:include, BrowserDetectHelper)
View
42 lib/browser_detect/browser_detect_helper.rb
@@ -0,0 +1,42 @@
+
+module BrowserDetectHelper
+
+ def browser_is? name
+
+ name = name.to_s.strip
+
+ return true if browser_name == name
+ return true if name == 'mozilla' && browser_name == 'gecko'
+ return true if name == 'ie' && browser_name.index('ie')
+ return true if name == 'webkit' && browser_name == ('safari' or 'chrome' or 'iphone' or 'ipad')
+ end
+
+ def browser_name
+ @browser_name ||= begin
+
+ ua = request.env['HTTP_USER_AGENT'].downcase
+
+ if ua.index('msie') && !ua.index('opera') && !ua.index('webtv')
+ 'ie'+ua[ua.index('msie')+5].chr
+ elsif ua.index('gecko/')
+ 'gecko'
+ elsif ua.index('opera')
+ 'opera'
+ elsif ua.index('konqueror')
+ 'konqueror'
+ elsif ua.index('ipad')
+ 'ipad'
+ elsif ua.index('iphone')
+ 'iphone'
+ elsif ua.index('chrome/')
+ 'chrome'
+ elsif ua.index('applewebkit/')
+ 'safari'
+ elsif ua.index('mozilla/')
+ 'gecko'
+ end
+
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.