access_kit 0.01 → 0.02

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+
3
+ group :development do
4
+ gem 'bundler', '~> 1.0.7'
5
+ end
6
+
7
+ gemspec
8
+
9
+ gem 'ruby-debug', :platform => :ruby_18, :require => 'ruby-debug'
10
+ gem 'ruby-debug19', :platform => :ruby_19, :require => 'ruby-debug'
data/README ADDED
@@ -0,0 +1,3 @@
1
+ AccessKit : the CSUN Accessibility Compliance Toolkit
2
+
3
+ A series of tools built with ruby to help ensure HTML is accessible, including an automated evaluation tool and helpers to generate accessible output for common elements.
@@ -0,0 +1,25 @@
1
+ require 'rails/all'
2
+
3
+ raise "ActionView::Helpers::UrlHelper not loaded!" unless defined?(ActionView::Helpers::UrlHelper)
4
+ raise "AccessKit::UrlHelperAdditions not loaded!" unless defined?(AccessKit::UrlHelperAdditions)
5
+
6
+ module ActionView
7
+ module Helpers
8
+ module UrlHelper
9
+
10
+ def link_to_with_supplement(*args, &block)
11
+ if !block_given? && AccessKit::UrlHelperAdditions.args_for_link_to_with_supplement?(*args)
12
+ new_opts = AccessKit::UrlHelperAdditions.process_options_for_link_to_with_supplement(*args)
13
+ new_name = AccessKit::UrlHelperAdditions.add_supplement_to_text(args[0], new_opts)
14
+ args.shift
15
+
16
+ link_to_without_supplement(new_name, *args)
17
+ else
18
+ link_to_without_supplement(*args, &block)
19
+ end
20
+ end
21
+
22
+ alias_method_chain :link_to, :supplement
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ module AccessKit
2
+ module UrlHelperAdditions
3
+ extend ActiveSupport::Concern
4
+
5
+ class << self
6
+ DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT = :intro
7
+ DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT = :outro
8
+
9
+ def add_supplement_to_text(text, opts={})
10
+ default_opts = {DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT => nil, DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT => nil, :auto_pad => true}
11
+ opts = default_opts.merge(opts)
12
+
13
+ padding = begin
14
+ if opts[:auto_pad] === true
15
+ ' '
16
+ elsif opts[:auto_pad] === false
17
+ ''
18
+ else
19
+ opts[:auto_pad].to_s
20
+ end
21
+ end
22
+
23
+ before_span = opts[DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT].blank? ?
24
+ "" :
25
+ span_tag(opts[DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT] + padding)
26
+
27
+ after_span = opts[DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT].blank? ?
28
+ "" :
29
+ span_tag(padding + opts[DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT])
30
+
31
+ "#{before_span}#{text}#{after_span}".html_safe
32
+ end
33
+
34
+ def args_for_link_to_with_supplement?(*args)
35
+ args[2].is_a?(Hash) && (
36
+ args[2].keys.include?(DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT) ||
37
+ args[2].keys.include?(DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT)
38
+ )
39
+ end
40
+
41
+ def process_options_for_link_to_with_supplement(*args)
42
+ [ DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT, DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT, :auto_pad ].inject({}) do |memo, k|
43
+ value = args[2].delete(k)
44
+ value.blank? ? memo : memo.merge( k => value )
45
+ end
46
+ end
47
+
48
+ private
49
+ # TODO: use Rails content_tag if available
50
+ def span_tag(content)
51
+ "<span>#{content}</span>"
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module AccessKit
2
- VERSION="0.01"
2
+ VERSION="0.02"
3
3
  end
data/lib/access_kit.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'access_kit/version'
2
+ require 'access_kit/url_helper_additions'
3
+ require 'access_kit/core_ext/url_helper'
2
4
 
3
5
  module AccessKit
4
6
  def find_errors(html)
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe AccessKit do
4
+ let(:valid_html) { IO.read( File.dirname(__FILE__) + '/../html_samples/valid.html') }
5
+
6
+ describe "#check" do
7
+ it "should have no @errors for a valid HTML document" do
8
+ AccessKit.find_errors(valid_html).should be_empty
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ module AccessKit
4
+ describe UrlHelperAdditions do
5
+ context "#link_to_with_supplement" do
6
+ include ActionView::Helpers::TagHelper
7
+ include ActionView::Helpers::UrlHelper
8
+
9
+ it "should extend link_to" do
10
+ link_to(
11
+ "unicorns",
12
+ '#unicorns',
13
+ :intro => "Click to learn about"
14
+ ).should == "<a href=\"#unicorns\"><span>Click to learn about </span>unicorns</a>"
15
+ end
16
+ end
17
+
18
+ context "#add_supplement_to_text" do
19
+ it "should add before" do
20
+ UrlHelperAdditions.add_supplement_to_text(
21
+ "unicorns",
22
+ :intro => "Click to learn more about"
23
+ ).should == "<span>Click to learn more about </span>unicorns"
24
+ end
25
+
26
+ it "should add after" do
27
+ UrlHelperAdditions.add_supplement_to_text(
28
+ "Learn more",
29
+ :outro => "about unicorns"
30
+ ).should == "Learn more<span> about unicorns</span>"
31
+ end
32
+
33
+ it "should add both before and after" do
34
+ UrlHelperAdditions.add_supplement_to_text(
35
+ "unicorns",
36
+ :intro => "Learn more about",
37
+ :outro => "by clicking here"
38
+ ).should == "<span>Learn more about </span>unicorns<span> by clicking here</span>"
39
+ end
40
+
41
+ it "should handle blank values" do
42
+ UrlHelperAdditions.add_supplement_to_text("unicorns").should == "unicorns"
43
+ UrlHelperAdditions.add_supplement_to_text("unicorns", :intro => nil).should == "unicorns"
44
+ UrlHelperAdditions.add_supplement_to_text("unicorns", :outro => nil).should == "unicorns"
45
+
46
+ UrlHelperAdditions.add_supplement_to_text(
47
+ "unicorns",
48
+ :outro => '',
49
+ :intro => ''
50
+ ).should == "unicorns"
51
+ end
52
+
53
+ context "auto_pad" do
54
+ it "should pad with one space by default" do
55
+ UrlHelperAdditions.add_supplement_to_text(
56
+ "unicorn",
57
+ :intro => "Run",
58
+ :outro => "run!"
59
+ ).should == "<span>Run </span>unicorn<span> run!</span>"
60
+ end
61
+
62
+
63
+ it "should add no padding" do
64
+ UrlHelperAdditions.add_supplement_to_text(
65
+ "unicorns",
66
+ :intro => "Learn more about",
67
+ :outro => "by clicking here",
68
+ :auto_pad => false
69
+ ).should == "<span>Learn more about</span>unicorns<span>by clicking here</span>"
70
+ end
71
+
72
+ it "should add custom padding" do
73
+ UrlHelperAdditions.add_supplement_to_text(
74
+ "unicorns",
75
+ :intro => "Learn more about",
76
+ :outro => "by clicking here",
77
+ :auto_pad => "&nbsp;"
78
+ ).should == "<span>Learn more about&nbsp;</span>unicorns<span>&nbsp;by clicking here</span>"
79
+ end
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+
8
+ <title>This is a sample valid document for testing purposes</title>
9
+
10
+ </head>
11
+
12
+ <body>
13
+
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,15 @@
1
+ require 'supermodel'
2
+ require 'ruby-debug'
3
+ require 'rails/all' # overkill, but lots of headaches trying to pick and choose needed actionpack components
4
+ require 'access_kit'
5
+
6
+ RSpec.configure do |config|
7
+ # == Mock Framework
8
+ #
9
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
10
+ #
11
+ # config.mock_with :mocha
12
+ # config.mock_with :flexmock
13
+ # config.mock_with :rr
14
+ config.mock_with :rspec
15
+ end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: access_kit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- version: "0.01"
8
+ - 2
9
+ version: "0.02"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mani Tadayon
@@ -14,55 +14,57 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-31 00:00:00 -08:00
17
+ date: 2011-02-25 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: nokogiri
21
+ name: rake
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 3
28
+ hash: 49
29
29
  segments:
30
30
  - 0
31
- version: "0"
32
- type: :runtime
31
+ - 8
32
+ - 7
33
+ version: 0.8.7
34
+ type: :development
33
35
  version_requirements: *id001
34
36
  - !ruby/object:Gem::Dependency
35
- name: rake
37
+ name: supermodel
36
38
  prerelease: false
37
39
  requirement: &id002 !ruby/object:Gem::Requirement
38
40
  none: false
39
41
  requirements:
40
- - - ~>
42
+ - - ">="
41
43
  - !ruby/object:Gem::Version
42
- hash: 49
44
+ hash: 3
43
45
  segments:
44
46
  - 0
45
- - 8
46
- - 7
47
- version: 0.8.7
47
+ version: "0"
48
48
  type: :development
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
51
- name: supermodel
51
+ name: rspec
52
52
  prerelease: false
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
- - - ">="
56
+ - - ~>
57
57
  - !ruby/object:Gem::Version
58
58
  hash: 3
59
59
  segments:
60
+ - 2
61
+ - 3
60
62
  - 0
61
- version: "0"
63
+ version: 2.3.0
62
64
  type: :development
63
65
  version_requirements: *id003
64
66
  - !ruby/object:Gem::Dependency
65
- name: rspec
67
+ name: rspec-rails
66
68
  prerelease: false
67
69
  requirement: &id004 !ruby/object:Gem::Requirement
68
70
  none: false
@@ -78,9 +80,25 @@ dependencies:
78
80
  type: :development
79
81
  version_requirements: *id004
80
82
  - !ruby/object:Gem::Dependency
81
- name: cucumber
83
+ name: rails
82
84
  prerelease: false
83
85
  requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 7
91
+ segments:
92
+ - 3
93
+ - 0
94
+ - 0
95
+ version: 3.0.0
96
+ type: :development
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ name: cucumber
100
+ prerelease: false
101
+ requirement: &id006 !ruby/object:Gem::Requirement
84
102
  none: false
85
103
  requirements:
86
104
  - - ">="
@@ -90,7 +108,7 @@ dependencies:
90
108
  - 0
91
109
  version: "0"
92
110
  type: :development
93
- version_requirements: *id005
111
+ version_requirements: *id006
94
112
  description: A series of tools built with ruby to help ensure HTML is accessibile, including an automated evaluation tool and helpers to generate accessible output for common elements.
95
113
  email: mani.tadayon@csun.edu
96
114
  executables: []
@@ -100,9 +118,17 @@ extensions: []
100
118
  extra_rdoc_files: []
101
119
 
102
120
  files:
103
- - Rakefile
121
+ - lib/access_kit/core_ext/url_helper.rb
122
+ - lib/access_kit/url_helper_additions.rb
104
123
  - lib/access_kit/version.rb
105
124
  - lib/access_kit.rb
125
+ - spec/access_kit/semantics_spec.rb
126
+ - spec/access_kit/url_helper_additions_spec.rb
127
+ - spec/html_samples/valid.html
128
+ - spec/spec_helper.rb
129
+ - Gemfile
130
+ - Rakefile
131
+ - README
106
132
  has_rdoc: true
107
133
  homepage: https://github.com/csun-student-affairs/access_kit
108
134
  licenses: []
@@ -126,14 +152,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
152
  requirements:
127
153
  - - ">="
128
154
  - !ruby/object:Gem::Version
129
- hash: 3
155
+ hash: 23
130
156
  segments:
131
- - 0
132
- version: "0"
157
+ - 1
158
+ - 3
159
+ - 6
160
+ version: 1.3.6
133
161
  requirements: []
134
162
 
135
163
  rubyforge_project:
136
- rubygems_version: 1.3.7
164
+ rubygems_version: 1.5.2
137
165
  signing_key:
138
166
  specification_version: 3
139
167
  summary: CSUN Accessibility Compliance Toolkit.