rack-html5-rails_helper 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Christian Felder
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = rack-html5-rails_helper
2
+
3
+ Rack::Html5 adds a HTTP header for each HTML5 feature the browser supports. This code provides convenient rails helper methods wrapping those headers.
4
+
5
+ == Usage
6
+
7
+ Provides the following methods you can use in controllers and views:
8
+
9
+ * browser_supports_wysiwyg?
10
+ * browser_supports_classname?
11
+ * browser_supports_elements?
12
+ * browser_supports_canvas?
13
+ * browser_supports_messaging?
14
+ * browser_supports_audio?
15
+ * browser_supports_video?
16
+ * browser_supports_textapi?
17
+ * browser_supports_draganddrop?
18
+ * browser_supports_offline?
19
+ * browser_supports_svg?
20
+ * browser_supports_forms?
21
+
22
+ == Installation
23
+
24
+ gem install rack-html5
25
+ gem install rack-html5-rails_helper
26
+
27
+ === Configuration for Rails 2
28
+
29
+ Add the following lines to the config block in your environment.rb file:
30
+ config.gem "rack-html5"
31
+ config.middleware.use "Rack::Html5"
32
+
33
+ Include module in ApplicationController:
34
+ include RackHtml5RailsHelper
35
+
36
+ === Configuration for Rails 3
37
+
38
+ Add the gem dependency to Gemfile:
39
+ gem 'rack-html5'
40
+
41
+ Install the gem with bundler:
42
+ sudo bundler install
43
+
44
+ Add the Rack middleware to config.ru:
45
+ use Rack::Html5
46
+
47
+ Include module in ApplicationController:
48
+ include RackHtml5RailsHelper
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ # Load all tasks in rake directory
2
+ Dir[File.join(File.expand_path(File.dirname(__FILE__)), "rake", "**", "*.rb")].each { |file| require file }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'rack-html5'
3
+ rescue LoadError
4
+ puts "Gem rack-html5 is not available. Install it with: sudo gem install rack-html5"
5
+ end
6
+
7
+ module RackHtml5RailsHelper
8
+
9
+ # Defines a method and a helper for each header the rack-html5 gem sets.
10
+ # Example: <tt>browser_supports_canvas?</tt> will return true if the <tt>HTTP_X_SUPPORTS_HTML5_CANVAS</tt> header is set.
11
+ def self.included(base)
12
+ features = [:wysiwyg, :classname, :elements, :canvas, :messaging, :audio, :video, :textapi, :draganddrop, :offline, :forms, :svg]
13
+
14
+ features.each do |header|
15
+ method_name = "browser_supports_#{header}?".to_sym
16
+ define_method method_name do
17
+ request.headers.has_key?("HTTP_X_SUPPORTS_HTML5_#{header.upcase}")
18
+ end
19
+
20
+ base.send(:helper_method, method_name)
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+ require 'rack-html5-rails_helper'
3
+
4
+ class RackHtml5RailsHelperTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ RackHtml5RailsHelperTest.stubs(:helper_method)
8
+ RackHtml5RailsHelperTest.class_eval do
9
+ include RackHtml5RailsHelper
10
+ end
11
+ end
12
+
13
+ should "define method browser_supports_wysiwyg?" do
14
+ assert methods.include?(:browser_supports_wysiwyg?)
15
+ end
16
+
17
+ should "define method browser_supports_classname?" do
18
+ assert methods.include?(:browser_supports_classname?)
19
+ end
20
+
21
+ should "define method browser_supports_elements?" do
22
+ assert methods.include?(:browser_supports_elements?)
23
+ end
24
+
25
+ should "define method browser_supports_canvas?" do
26
+ assert methods.include?(:browser_supports_canvas?)
27
+ end
28
+
29
+ should "define method browser_supports_messaging?" do
30
+ assert methods.include?(:browser_supports_messaging?)
31
+ end
32
+
33
+ should "define method browser_supports_audio?" do
34
+ assert methods.include?(:browser_supports_audio?)
35
+ end
36
+
37
+ should "define method browser_supports_video?" do
38
+ assert methods.include?(:browser_supports_video?)
39
+ end
40
+
41
+ should "define method browser_supports_textapi?" do
42
+ assert methods.include?(:browser_supports_textapi?)
43
+ end
44
+
45
+ should "define method browser_supports_draganddrop?" do
46
+ assert methods.include?(:browser_supports_draganddrop?)
47
+ end
48
+
49
+ should "define method browser_supports_offline?" do
50
+ assert methods.include?(:browser_supports_offline?)
51
+ end
52
+
53
+ should "define method browser_supports_forms?" do
54
+ assert methods.include?(:browser_supports_forms?)
55
+ end
56
+
57
+ context "method browser_supports_svg?" do
58
+
59
+ should "be defined" do
60
+ assert methods.include?(:browser_supports_svg?)
61
+ end
62
+
63
+ should "define helper" do
64
+ RackHtml5RailsHelperTest.expects(:helper_method).with(:browser_supports_svg?)
65
+ RackHtml5RailsHelperTest.class_eval do
66
+ include RackHtml5RailsHelper
67
+ end
68
+ end
69
+
70
+ should "return true if HTTP_X_SUPPORTS_HTML5_SVG header is set" do
71
+ request = mock(:headers => { 'HTTP_X_SUPPORTS_HTML5_SVG' => 'true' })
72
+ self.expects(:request).returns(request)
73
+ assert browser_supports_svg?
74
+ end
75
+
76
+ should "return false if HTTP_X_SUPPORTS_HTML5_SVG header is no set" do
77
+ request = mock(:headers => {})
78
+ self.expects(:request).returns(request)
79
+ assert_equal false, browser_supports_svg?
80
+ end
81
+
82
+ end
83
+
84
+ # TODO: NEGATIVTEST
85
+
86
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require 'mocha'
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-html5-rails_helper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Christian Felder (masone)
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-15 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: mocha
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Provides Rails helper methods wrapping the HTTP headers set by Rack::Html5.
47
+ email: ema@rh-productions.ch
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ - Rakefile
59
+ - VERSION
60
+ - lib/rack-html5-rails_helper.rb
61
+ - test/rack-html5-rails_helper_test.rb
62
+ - test/test_helper.rb
63
+ has_rdoc: true
64
+ homepage: http://github.com/masone/rack-html5-rails_helper
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.7
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Provides Rails helper methods wrapping the HTTP headers set by Rack::Html5.
95
+ test_files:
96
+ - test/rack-html5-rails_helper_test.rb
97
+ - test/test_helper.rb