access_lint 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6888daa724299ad8681eb1c902ab0c38b3286094
4
- data.tar.gz: fa5edfcfbd39d1e5f66fdec961610c6e23599e40
3
+ metadata.gz: c24905f58182a273d81c472cb6039096550665b5
4
+ data.tar.gz: 64e9ae9282bf3b4a81094952d7a089c3204cbe00
5
5
  SHA512:
6
- metadata.gz: 9d5b4368da29009d9705a0c721278ec8f9bf4fc98f59e26d684ca462c709445b6c557c310c4b00506716f39657844d5e58f32ba0c22e1eea0d804b9a28e700ae
7
- data.tar.gz: d2811c4a2fa89d60ba646e776c831d440901ef67636c7f2aed788819c8f4911d7ebe4f99b01c46cfbb58414b481cc74499996d3fafc19f2a8662e38e55d6136c
6
+ metadata.gz: d92d4c4aaa4e064ca6e246d97bf17748f4a78d6530c2f8e71d37e5c464b42d8a9aef3bc0df1c27f58a883a6c5cb15040894c4dd20f7151353f8652ecefb7c417
7
+ data.tar.gz: 9356133444a1c5ab3eed241a6823f1f411fd72d35b29224ba677cb38135d211632474828f2d2f9fa89e5d05d1415e252f33036eb06831da58529eeeabe4146f2
data/README.md CHANGED
@@ -1,44 +1,61 @@
1
1
  # AccessLint
2
- Command line runner for Google Accessibility Developer Tools.
3
2
 
4
- ## Installation
3
+ Run accessibility audits on web pages from the command line.
5
4
 
6
- Install phantomjs:
5
+ ## About
7
6
 
8
- $ brew install phantomjs
7
+ AccessLint uses the [Accessibility Developer Tools](https://github.com/GoogleChrome/accessibility-developer-tools) javascript library to make assertions on the DOM via PhantomJS.
9
8
 
10
- Add this line to your application's Gemfile:
9
+ ## Installation
11
10
 
12
- gem 'access_lint'
11
+ $ brew install phantomjs
13
12
 
14
- And then execute:
13
+ $ gem install access_lint
15
14
 
16
- $ bundle
15
+ $ access_lint audit <url-or-filename>
17
16
 
18
- ## Usage
17
+ ## Command Line Usage
19
18
 
20
- $ bundle exec access_lint <url-or-filename>
19
+ Running the `audit` command will return an array of stringified JSON objects to stdout:
21
20
 
22
- ### Example
21
+ $ access_lint audit TARGET # TARGET can be a url or a path to a file
23
22
 
24
- $ bundle exec access_lint http://github.com
25
- > *** Begin accessibility audit results ***
26
- An accessibility audit found
27
- Warnings:
28
- Warning: AX_FOCUS_01 (These elements are focusable but either invisible or obscured by another element) failed on the following element:
29
- body > .container > .site-footer > A
30
- See https://code.google.com/p/accessibility-developer-tools/wiki/AuditRules#AX_FOCUS_01:_These_elements_are_focusable_but_either_invisible_o for more information.
23
+ The JSON structure looks like:
31
24
 
32
- Warning: AX_COLOR_01 (Text elements should have a reasonable contrast ratio) failed on the following elements (1 - 5 of 15):
33
- #site-container > .marketing-section.marketing-benefits > .container > .row > .one-third.column:nth-of-type(3) > P > A
34
- #site-container > .marketing-section.marketing-desktop > .container > .marketing-header > .show-mac.show-linux > .text-muted
35
- #site-container > .marketing-section.marketing-desktop > .container > .marketing-header > .show-mac.show-linux > .text-muted > A
36
- body > .container > .site-footer > .site-footer-links.right > LI > A
37
- body > .container > .site-footer > .site-footer-links.right > LI:nth-of-type(2) > A
38
- See https://code.google.com/p/accessibility-developer-tools/wiki/AuditRules#AX_COLOR_01:_Text_elements_should_have_a_reasonable_contrast_rat for more information.
25
+ [
26
+ {
27
+ "element_names": ["<p class=\"foo\">relevant element</p>"], # array of string values for applicable DOM nodes
28
+ "elements": [DOM node], # array of failing nodes as DOM objects.
29
+ "severity": "WARNING", # string for the severity of the failure.
30
+ "status": "PASS", # 'PASS', 'FAIL', or 'NA'
31
+ "title": "Some description" # string description of the failure.
32
+ }
33
+ ]
39
34
 
35
+ ### Example
40
36
 
41
- *** End accessibility audit results ***
37
+ $ access_lint audit http://ckundo.com
38
+
39
+ [{"element_names": ["<span class=\"blogger-gear\"></span>"], "elements": [DOM node], "severity"=>"Warning", "status"=>"FAIL", "title"=>"Meaningful images should not be used in element backgrounds"}, ...]
40
+
41
+ ## Rules
42
+
43
+ For full descriptions of the audit rules, visit the [Accessibility Developer Tools project wiki](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules)
44
+
45
+ * Audio elements should have controls
46
+ * ARIA state and property values must be valid
47
+ * Elements with ARIA roles must use a valid, non-abstract ARIA role
48
+ * Controls and media elements should have labels
49
+ * These elements are focusable but either invisible or obscured by another element
50
+ * Images should have an alt attribute
51
+ * The purpose of each link should be clear from the link text
52
+ * Text elements should have a reasonable contrast ratio
53
+ * role=main should only appear on significant elements
54
+ * Meaningful images should not be used in element backgrounds
55
+ * aria-labelledby attributes should refer to an element which exists in the DOM
56
+ * The web page should have a title that describes topic or purpose
57
+ * Elements with ARIA roles must have all required attributes for that role
58
+ * Video elements should use <track> elements to provide captions
42
59
 
43
60
  ## Contributing
44
61
 
data/lib/access_lint.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  require "access_lint/version"
2
2
 
3
3
  module AccessLint
4
- autoload :Audit, 'access_lint/audit'
4
+ autoload :Audit, 'access_lint/runner'
5
+ autoload :Runner, 'access_lint/audit'
6
+
7
+ class Error < StandardError; end
8
+ class AuditError < Error; end
9
+ class ParserError < Error; end
5
10
  end
@@ -3,17 +3,34 @@ require 'json'
3
3
 
4
4
  module AccessLint
5
5
  class Audit
6
- RUNNER_PATH = File.expand_path("../../../vendor/access-lint/bin/auditor.js", __FILE__)
6
+ attr_reader :target
7
7
 
8
8
  def initialize(target)
9
9
  @target = target
10
10
  end
11
11
 
12
12
  def run
13
- result = `phantomjs #{RUNNER_PATH} #{@target}`
14
- if !result.nil?
15
- JSON.parse(result)
16
- end
13
+ perform_audit
14
+ end
15
+
16
+ def runner
17
+ @runner ||= Runner.new(@target)
18
+ end
19
+
20
+ private
21
+
22
+ def perform_audit
23
+ runner.run
24
+ @output = runner.output
25
+ parse_output
26
+ end
27
+
28
+ def parse_output
29
+ raw_results = JSON.parse(@output)
30
+ raw_results.map { |result| result.delete('elements') }
31
+ @results = raw_results.group_by { |result| result['status'] }
32
+ rescue Exception => e
33
+ raise AccessLint::ParserError.new(e.message)
17
34
  end
18
35
  end
19
36
  end
@@ -0,0 +1,31 @@
1
+ module AccessLint
2
+ class Runner
3
+ RUNNER_PATH = File.expand_path("../../../vendor/access-lint/bin/auditor.js", __FILE__)
4
+ attr_reader :output
5
+
6
+ def initialize(target)
7
+ @target = target
8
+ end
9
+
10
+ def run
11
+ @output = `phantomjs #{RUNNER_PATH} #{@target}`
12
+ return if audit_success?
13
+
14
+ if !phantomjs_installed?
15
+ raise AccessLint::RunnerError.new("Please install PhantomJS. Visit http://phantomjs.org/ for instructions.")
16
+ else
17
+ raise AccessLint::RunnerError.new("PhantomJS exited without success: #{@output}")
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def audit_success?
24
+ $?.success?
25
+ end
26
+
27
+ def phantomjs_installed?
28
+ $?.exitstatus != 127
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module AccessLint
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,14 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  module AccessLint
4
4
  describe Audit do
5
- let(:target) { double(:target) }
6
5
 
7
6
  describe '#run' do
8
- let(:audit) { Audit.new(target) }
7
+ it 'return a parsed set of results' do
8
+ target = double
9
+ output = JSON.generate([{status: 'passing', foo: 'bar'}])
9
10
 
10
- it 'runs phantomjs' do
11
- audit.should_receive(:`).with(/^phantomjs.*/)
12
- audit.run
11
+ audit = Audit.new(target)
12
+ audit.stub(:runner) { double(:runner, output: output, run: double) }
13
+
14
+ expect(audit.run).to eq "passing"=>[{"status"=>"passing", "foo"=>"bar"}]
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ module AccessLint
4
+ describe Runner do
5
+ it 'runs phantomjs' do
6
+ target = double
7
+ runner = Runner.new(target)
8
+
9
+ expect(runner).to receive(:`).with(/^phantomjs.*/)
10
+ runner.run
11
+ end
12
+ end
13
+ end
@@ -10,6 +10,10 @@ page.onResourceTimeout = function(e) {
10
10
  phantom.exit(1);
11
11
  };
12
12
 
13
+ page.onError = function(message) {
14
+ // suppress errors
15
+ };
16
+
13
17
  if (system.args.length !== 2) {
14
18
  console.log('Usage: phantomjs auditor.js URL');
15
19
  phantom.exit();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: access_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Cundiff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-23 00:00:00.000000000 Z
11
+ date: 2014-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -86,9 +86,11 @@ files:
86
86
  - lib/access_lint.rb
87
87
  - lib/access_lint/audit.rb
88
88
  - lib/access_lint/cli.rb
89
+ - lib/access_lint/runner.rb
89
90
  - lib/access_lint/version.rb
90
91
  - spec/access_lint/audit_spec.rb
91
92
  - spec/access_lint/cli_spec.rb
93
+ - spec/access_lint/runner_spec.rb
92
94
  - spec/spec_helper.rb
93
95
  - vendor/access-lint/README.md
94
96
  - vendor/access-lint/bin/auditor.js
@@ -122,4 +124,5 @@ summary: AccessLint runs Google Accessibility Developer Tools assertions on a pa
122
124
  test_files:
123
125
  - spec/access_lint/audit_spec.rb
124
126
  - spec/access_lint/cli_spec.rb
127
+ - spec/access_lint/runner_spec.rb
125
128
  - spec/spec_helper.rb