rack-noie6 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,46 @@
1
+ # rack-noie6
2
+
3
+ rack-noie6 does _everyone_ a favor: it shows the way out of your website to poor souls out there using Internet Explorer 6 (or a user configurable minimum).
4
+
5
+ Originally developed by [juliocesar](http://github.com/juliocesar), [sant0sk1](http://github.com/sant0sk1) forked and gemified for easier distribution and [wjessop](http://github.com/wjessop) added the minimum version option.
6
+
7
+ # general usage
8
+
9
+ just
10
+
11
+ gem install sant0sk1-rack-noie6 --source http://gems.github.com
12
+ require 'noie6'
13
+
14
+ and
15
+
16
+ use Rack::NoIE6, :redirect => '/noieplease.html'
17
+
18
+ the above will redirect to a page noieplease.html in your website. You can redirect to
19
+ a URL as well, like so
20
+
21
+ use Rack::NoIE6, :redirect => 'http://slashdot.org'
22
+
23
+ or let the default kick in
24
+
25
+ use Rack::NoIE6
26
+
27
+ You can even specify a minimum version of IE like so
28
+
29
+ use Rack::NoIE6, :redirect => 'http://slashdot.org', :minimum => 6.0
30
+
31
+ # Rails usage
32
+
33
+ inside environment.rb's Rails::Initializer.run
34
+
35
+ config.gem 'sant0sk1-rack-noie6', :lib => 'noie6'
36
+ config.middleware.use "Rack::NoIE6"
37
+
38
+ Piece o' cake!
39
+
40
+ # disclaimer
41
+
42
+ The default URL points to Microsoft's IE8 upgrade page.
43
+
44
+ # license
45
+
46
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rake/testtask'
2
+
3
+ task :default => [:test]
4
+
5
+ Rake::TestTask.new do |task|
6
+ task.pattern = 'test/noie6_test.rb'
7
+ task.warning, task.verbose = true, true
8
+ end
9
+
10
+ begin
11
+ require 'jeweler'
12
+ Jeweler::Tasks.new do |gemspec|
13
+ gemspec.name = "rack-noie6"
14
+ gemspec.summary = "A Rack middleware to redirect IE6 users out of your website"
15
+ gemspec.email = "jerod.santo@gmail.com"
16
+ gemspec.homepage = "http://github.com/sant0sk1/rack-noie6"
17
+ gemspec.authors = ["Jerod Santo", "Julio Cesar Ody", "Will Jessop"]
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
21
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 1
4
+ :minor: 1
data/lib/noie6.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Rack
2
+ class NoIE6
3
+ def initialize(app, options = {})
4
+ @app = app
5
+ @options = options
6
+ @options[:redirect] ||= 'http://www.microsoft.com/windows/internet-explorer/default.aspx'
7
+ @options[:minimum] ||= 7.0
8
+ end
9
+
10
+ def call(env)
11
+ ie6_found_in?(env) ? kick_it : @app.call(env)
12
+ end
13
+
14
+ private
15
+ def ie6_found_in?(env)
16
+ if env['HTTP_USER_AGENT']
17
+ is_ie?(env['HTTP_USER_AGENT']) and ie_version(env['HTTP_USER_AGENT']) < @options[:minimum] and @options[:redirect] != env['PATH_INFO']
18
+ end
19
+ end
20
+
21
+ def is_ie?(ua_string)
22
+ # We need at least one digit to be able to get the version, hence the \d
23
+ ua_string.match(/MSIE \d/) ? true : false
24
+ end
25
+
26
+ def ie_version(ua_string)
27
+ ua_string.match(/MSIE (\S+)/)[1].to_f
28
+ end
29
+
30
+ def kick_it
31
+ [301, {'Location' => @options[:redirect]}, 'Fail browser is fail']
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,60 @@
1
+ require 'test/unit'
2
+
3
+ require 'rubygems'
4
+ require 'rack/mock'
5
+
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'noie6')
7
+
8
+ class TestApp
9
+ def call(env)
10
+ [200, {}, 'Hi Internets!']
11
+ end
12
+ end
13
+
14
+ class NoieTest < Test::Unit::TestCase
15
+
16
+ def test_redirects_to_where_it_should_if_ie6
17
+ request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org'}))
18
+ response = request.get('/', {'HTTP_USER_AGENT' => 'MSIE 6.0' })
19
+ assert_equal 301, response.status
20
+ assert_equal response.location, 'http://slashdot.org'
21
+ end
22
+
23
+ def test_redirects_to_where_it_should_if_user_specified_minimum_not_met
24
+ request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org', :minimum => 6.0}))
25
+ response = request.get('/', {'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 5.5b1; Mac_PowerPC)' })
26
+ assert_equal 301, response.status
27
+ assert_equal response.location, 'http://slashdot.org'
28
+ end
29
+
30
+ def test_redirects_to_local_urls
31
+ request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => '/foo'}))
32
+ response = request.get('/foo', {'HTTP_USER_AGENT' => 'MSIE 6.0' })
33
+ assert_equal "Hi Internets!", response.body
34
+ end
35
+
36
+ def test_allows_if_not_ie6
37
+ request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org'}))
38
+ response = request.get('/', {'HTTP_USER_AGENT' => 'Mozilla/5.0'})
39
+ assert_equal "Hi Internets!", response.body
40
+ end
41
+
42
+ def test_allows_if_UA_version_greater_than_minimum
43
+ request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org'}))
44
+ response = request.get('/', {'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows XP)'})
45
+ assert_equal "Hi Internets!", response.body
46
+ end
47
+
48
+ def test_allows_if_no_UA_version_no_available
49
+ request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org'}))
50
+ response = request.get('/', {'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE l4me; Windows XP)'})
51
+ assert_equal "Hi Internets!", response.body
52
+ end
53
+
54
+ def test_allows_if_no_user_agent_specified
55
+ request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org'}))
56
+ response = request.get('/')
57
+ assert_equal "Hi Internets!", response.body
58
+ end
59
+
60
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-noie6
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jerod Santo
8
+ - Julio Cesar Ody
9
+ - Will Jessop
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-05-30 00:00:00 -05:00
15
+ default_executable:
16
+ dependencies: []
17
+
18
+ description:
19
+ email: jerod.santo@gmail.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files:
25
+ - README.markdown
26
+ files:
27
+ - README.markdown
28
+ - Rakefile
29
+ - VERSION.yml
30
+ - lib/noie6.rb
31
+ - test/noie6_test.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/sant0sk1/rack-noie6
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --charset=UTF-8
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: A Rack middleware to redirect IE6 users out of your website
60
+ test_files:
61
+ - test/noie6_test.rb