accessibility 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f47f50275fb37bc7744979cabbc85b598189706
4
+ data.tar.gz: b7011b70d3e17b3857318f348497c0fcfbc1f089
5
+ SHA512:
6
+ metadata.gz: caccd7b5ee1186a3dc5745e2965ae93d5d2a52d4c0edbc678769c7d3bacff85565455633283c8545eac4d6d85d7432626ae2d320d7d207d676492ce4aed3c072
7
+ data.tar.gz: bef521edb760d52ccbfe168c954a7d11769dc86a9784436ddb21941360dc8a36973dd07e4e3a8171d507085f4f6e519f6f04ca68700dc75115277c9ad4f2b54c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in accessibility.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jaime Iniesta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,114 @@
1
+ # Accessibility [![travis build status](https://secure.travis-ci.org/sitevalidator/accessibility.png?branch=master)](http://travis-ci.org/sitevalidator/accessibility) [![Code Climate](https://codeclimate.com/github/sitevalidator/accessibility/badges/gpa.svg)](https://codeclimate.com/github/sitevalidator/accessibility) [![Dependency Status](https://gemnasium.com/sitevalidator/accessibility.png)](https://gemnasium.com/sitevalidator/accessibility)
2
+
3
+ Accessibility is a Ruby gem that lets you check for accessibility issues on web pages.
4
+
5
+ It's a wrapper around the great [AccessLint](https://github.com/accesslint/access_lint) gem, which in turn is a wrapper around the awesome [Accessibility Developer Tools](https://github.com/GoogleChrome/accessibility-developer-tools).
6
+
7
+ ## Why so many wrappers?
8
+
9
+ The Accessibility Developer Tools, ADT for short, is a JavaScript library developed by the [Google Chrome team](https://github.com/GoogleChrome), which can be used as a [Google Chrome extension](https://chrome.google.com/webstore/detail/accessibility-developer-t/fpkknkljclfencbdbgkenhalefipecmb), or from the command line via [PhantomJS](http://phantomjs.org/).
10
+
11
+ What the AccessLint gem does is wrap this JS library in a Ruby gem, so that you can easily run it on your Ruby projects in a convenient way.
12
+
13
+ I found that using the AccessLint gem directly on my Ruby projects had some drawbacks:
14
+
15
+ 1. It introduced a dependency on PhantomJS, and this is a quite heavy dependency. PhantomJS can be hard to compile and it takes a lot of memory.
16
+ 2. To get the results, AccessLint executes phantom JS via a [shell command](https://github.com/accesslint/access_lint/blob/master/lib/access_lint/runner.rb#L11), which is something I don't feel very comfortable with.
17
+ 3. The AccessLint returns a raw JSON with the results, and I'd prefer to add a more friendly API over it.
18
+
19
+ ## Enter access-lint-server
20
+
21
+ I prefer to move this heavy dependency out of my projects, so I released the [access-lint-server](https://github.com/sitevalidator/access-lint-server), which is a lightweight server based on Sinatra, that you can easily set up (for example in Heroku), to have a microservice in charge of doing the A11Y checks with the AccessLint gem. That's where the dependency on PhantomJS now resides, and not on your main project.
22
+
23
+ Also, it allows for easy scaling. ADT can take several seconds (or tens of seconds) to respond, so a suggested approach is having several access-lint-server instances and a load balancer in front of them.
24
+
25
+ To make it easier to process the raw JSON response, Accessibility is a Ruby client that uses an access-lint-server instance and gives you the results in a more friendly way.
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'accessibility'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install accessibility
42
+
43
+ ## Usage
44
+
45
+ To check accessibility on a web page, just pass Accessibility the URL to check, like this:
46
+
47
+ ```ruby
48
+ a11y = Accessibility.check('http://validationhell.com')
49
+ ```
50
+
51
+ Now you can get the errors and warnings like this:
52
+
53
+ ```ruby
54
+ a11y.errors
55
+ a11y.warnings
56
+ ```
57
+
58
+ Each of these methods will return an array of audit rules that your web page failed to comply with. Each rule has its details, let's see for example:
59
+
60
+ ```ruby
61
+ a11y = Accessibility.check('http://validationhell.com')
62
+
63
+ warning = a11y.warnings.last
64
+ warning.title # "Text elements should have a reasonable contrast ratio"
65
+ warning.element_names # ["<a href=\"/pages/why\">Why nobody validates</a>", "<a href=\"/pages/circle/1\">Limbo</a>"]
66
+ ```
67
+
68
+ ## Audit Rules
69
+
70
+ Currently, AccessLint has a [list of 17 audit rules](https://github.com/accesslint/access_lint#rules). Each of these will be checked on your documents, and
71
+ you can inspect them like this:
72
+
73
+ ```ruby
74
+ a11y = Accessibility.check('http://validationhell.com')
75
+
76
+ a11y.rules.all # all the checked rules
77
+ a11y.rules.not_applicable # rules that were not applicable to the checked page
78
+ a11y.rules.passed # rules that passed on the checked document
79
+ a11y.rules.failed # rules that failed on the checked document
80
+ a11y.errors # rules that failed with a severity of "Severe"
81
+ a11y.warnings # rules that failed with a severity of "Warning"
82
+ ```
83
+
84
+ Each rule has the following attributes:
85
+
86
+ attribute | description
87
+ --------------|-----------------------------------------------------------------
88
+ status | "NA" (not applicable), "PASS", or "FAIL"
89
+ severity | "Severe" or "Warning"
90
+ title | a description of the rule
91
+ element_names | an array of strings, each of them being a snippet of the document where the issue was found
92
+
93
+ ## Using your own access-lint-server instance
94
+
95
+ By default, Accessibility will use a demo instance of access-lint-server, which is intended only for demo purposes and not ready for production.
96
+
97
+ You're encouraged to [install your own instance](https://github.com/sitevalidator/access-lint-server) and use it like this:
98
+
99
+ ```ruby
100
+ a11y = Accessibility::Checker.new( 'http://validationhell.com',
101
+ checker_uri: 'http://mychecker.com' )
102
+ ```
103
+
104
+ ## Development
105
+
106
+ After checking out the repo, run `bundle` to install dependencies. Then, run `bundle console` for an interactive prompt that will allow you to experiment.
107
+
108
+ ## Contributing
109
+
110
+ 1. Fork it ( https://github.com/sitevalidator/accessibility/fork )
111
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
112
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
113
+ 4. Push to the branch (`git push origin my-new-feature`)
114
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+ RSpec::Core::RakeTask.new :spec
6
+
7
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'accessibility/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "accessibility"
8
+ spec.version = Accessibility::VERSION
9
+ spec.authors = ["Jaime Iniesta"]
10
+ spec.email = ["jaimeiniesta@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby client for the access-lint-server JSON API.}
13
+ spec.description = %q{Ruby client to check for accessibility issues using
14
+ Chrome's Accessibility Developer Tools on an
15
+ access-lint-server instance.}
16
+ spec.homepage = "https://github.com/sitevalidator/accessibility"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "httparty", "~> 0.13"
25
+
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.2"
28
+ spec.add_development_dependency "webmock", "~> 1.20"
29
+ end
@@ -0,0 +1,11 @@
1
+ require "forwardable"
2
+ require "accessibility/version"
3
+ require "accessibility/checker"
4
+ require "accessibility/audit"
5
+ require "accessibility/rule"
6
+
7
+ module Accessibility
8
+ def self.check(url, options = {})
9
+ Accessibility::Checker.new(url, options)
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ module Accessibility
2
+
3
+ ####
4
+ # An Accessibility::Audit is in charge of parsing the rules found on
5
+ # the raw response from the access-lint-server, available on the Checker,
6
+ # and filtering them by different criteria.
7
+ #
8
+ class Audit
9
+ def initialize(checker)
10
+ @checker = checker
11
+ end
12
+
13
+ extend Forwardable
14
+ delegate :raw => :@checker
15
+
16
+ def rules
17
+ self
18
+ end
19
+
20
+ # Returns all the rules
21
+ def all
22
+ @rules ||= raw.values.flatten.map { |rule| Accessibility::Rule.new(rule) }
23
+ end
24
+
25
+ # Returns the rules that were not applicable to the checked document
26
+ def not_applicable
27
+ @not_applicable ||= all.select { |rule| rule.status == "NA" }
28
+ end
29
+
30
+ # Returns the rules that passed on the checked document
31
+ def passed
32
+ @passed ||= all.select { |rule| rule.status == "PASS" }
33
+ end
34
+
35
+ # Returns the rules that failed on the checked document
36
+ def failed
37
+ @failed ||= all.select { |rule| rule.status == "FAIL" }
38
+ end
39
+
40
+ # Returns the rules that failed with a severity of "Severe"
41
+ def errors
42
+ @errors ||= failed.select { |rule| rule.severity == "Severe" }
43
+ end
44
+
45
+ # Returns the rules that failed with a severity of "Warning"
46
+ def warnings
47
+ @warnings ||= failed.select { |rule| rule.severity == "Warning" }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,59 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Accessibility
5
+
6
+ ####
7
+ # An Accessibility::Checker is initialized by passing it the URL of the
8
+ # web page to check.
9
+ #
10
+ # It is in charge of making the request to the access-lint-server, which
11
+ # will perform the accessibility audit using the AccessLint gem and return
12
+ # the results as JSON.
13
+ #
14
+ # It delegates the results parsing to an Accessibility::Audit, which in
15
+ # turn will consult the raw JSON from this checker to generate the collections
16
+ # of audit rules.
17
+ #
18
+ # Example:
19
+ #
20
+ # a11y = Accessibility::Checker.new('http://validationhell.com')
21
+ #
22
+ # You can (and should) specify the URL where your access-lint-server
23
+ # instance is to be found, as the default value is not a production-ready server,
24
+ # which might be under heavy load:
25
+ #
26
+ # a11y = Accessibility::Checker.new( 'http://validationhell.com',
27
+ # checker_uri: 'http://mychecker.com' )
28
+ #
29
+ # For brevity, you can use the convenience shortcut on the top-level module:
30
+ #
31
+ # a11y = Accessibility.check('http://validationhell.com')
32
+ #
33
+ class Checker
34
+ attr_reader :url, :checker_uri
35
+
36
+ def initialize(url, options = {})
37
+ options = defaults.merge(options)
38
+
39
+ @url = url
40
+ @checker_uri = options[:checker_uri]
41
+
42
+ @audit = Accessibility::Audit.new(self)
43
+ end
44
+
45
+ # Returns the parsed JSON from the response of the access-lint-server
46
+ def raw
47
+ @raw ||= JSON.parse HTTParty.get("#{checker_uri}/check?url=#{url}").body
48
+ end
49
+
50
+ extend Forwardable
51
+ delegate [:rules, :errors, :warnings] => :@audit
52
+
53
+ private
54
+
55
+ def defaults
56
+ { checker_uri: 'https://access-lint-server-demo.herokuapp.com' }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,24 @@
1
+ module Accessibility
2
+ class Rule
3
+ attr_reader :element_names, :severity, :status, :title
4
+
5
+ ####
6
+ # An Accessibility::Rule represents a single Accessibility Developer Tools
7
+ # audit rule that is checked on the document.
8
+ #
9
+ # A Rule has the following attributes:
10
+ #
11
+ # * status, which can be "NA" (not applicable), "PASS", or "FAIL"
12
+ # * severity, which can be "Severe" or "Warning"
13
+ # * title, which is a description of the rule
14
+ # * element_names, an array of strings, each of them being a snippet of
15
+ # the document where the issue was found
16
+ #
17
+ def initialize(data)
18
+ @element_names = data['element_names']
19
+ @severity = data['severity']
20
+ @status = data['status']
21
+ @title = data['title']
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Accessibility
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: accessibility
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jaime Iniesta
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.20'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.20'
69
+ description: |-
70
+ Ruby client to check for accessibility issues using
71
+ Chrome's Accessibility Developer Tools on an
72
+ access-lint-server instance.
73
+ email:
74
+ - jaimeiniesta@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - accessibility.gemspec
87
+ - lib/accessibility.rb
88
+ - lib/accessibility/audit.rb
89
+ - lib/accessibility/checker.rb
90
+ - lib/accessibility/rule.rb
91
+ - lib/accessibility/version.rb
92
+ homepage: https://github.com/sitevalidator/accessibility
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Ruby client for the access-lint-server JSON API.
116
+ test_files: []