-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
164 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
// accessibility rules todo: | ||
/// rules or techniques | ||
pub mod ids; | ||
/// the rule to follow | ||
pub mod rule; | ||
/// wcag audit | ||
pub mod wcag; | ||
/// the base of the wcag set | ||
pub mod wcag_base; | ||
/// rules to map to | ||
pub mod wcag_rule_map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::engine::rules::ids::Techniques; | ||
use crate::engine::rules::wcag_base::{Criteria, Guideline, Principle}; | ||
use crate::ElementRef; | ||
|
||
/// the rule validation method that should be performed. | ||
pub struct Rule { | ||
/// the message id of the rule to point to the locale | ||
pub rule_id: Techniques, | ||
/// the type of rule | ||
pub criteria: Criteria, | ||
/// validate a test returns (valid, rule, selectors) | ||
pub validate: fn( | ||
&String, | ||
&Vec<ElementRef<'_>>, | ||
css: &cssparser::Parser<'_, '_>, | ||
) -> (bool, &'static str, Vec<&'static str>), | ||
/// the principle type | ||
pub principle: Principle, | ||
/// the guideline to follow | ||
pub guideline: Guideline, | ||
} | ||
|
||
impl Rule { | ||
/// a new rule type | ||
pub fn new( | ||
rule_id: Techniques, | ||
criteria: Criteria, | ||
principle: Principle, | ||
guideline: Guideline, | ||
validate: fn( | ||
&String, | ||
&Vec<ElementRef<'_>>, | ||
&cssparser::Parser<'_, '_>, | ||
) -> (bool, &'static str, Vec<&'static str>), | ||
) -> Rule { | ||
Rule { | ||
rule_id, | ||
criteria, | ||
guideline, | ||
principle, | ||
validate, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/// the success criteria to use | ||
#[derive(Debug)] | ||
pub enum Criteria { | ||
/// a hard error that should be fixed | ||
Error, | ||
/// a warning that may be an issue | ||
Warning, | ||
/// a generic notice to help accessibility needs | ||
Notice, | ||
} | ||
|
||
impl Criteria { | ||
/// get rule id to string | ||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
Criteria::Error => "error", | ||
Criteria::Warning => "warning", | ||
Criteria::Notice => "notice", | ||
} | ||
} | ||
} | ||
|
||
/// wcag principle to follow | ||
pub enum Principle { | ||
/// Provide text alternatives for any non-text content so that it can be changed into other forms people need, such as large print, braille, speech, symbols or simpler language. | ||
Perceivable, | ||
/// Make all functionality available from a keyboard. | ||
Operable, | ||
/// Make text content readable and understandable. | ||
Understandable, | ||
/// Maximize compatibility with current and future user agents, including assistive technologies. | ||
Robust, | ||
} | ||
|
||
impl Principle { | ||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
Principle::Perceivable => "Principle1", | ||
Principle::Operable => "Principle2", | ||
Principle::Understandable => "Principle3", | ||
Principle::Robust => "Principle4", | ||
} | ||
} | ||
} | ||
|
||
/// wcag principle to follow | ||
pub enum Guideline { | ||
/// Provide ways to help users navigate, find content, and determine where they are. | ||
Navigable, | ||
/// Make Web pages appear and operate in predictable ways. | ||
Predictable, | ||
} | ||
|
||
impl Guideline { | ||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
Guideline::Navigable => "Guideline2_4", | ||
Guideline::Predictable => "Guideline3_2", | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::engine::rules::ids::Techniques; | ||
use crate::engine::rules::rule::Rule; | ||
use crate::engine::rules::wcag_base::{Criteria, Guideline, Principle}; | ||
use scraper::Selector; | ||
use std::collections::BTreeMap; | ||
|
||
// todo: validate each element and add a shape that can prevent repitiion | ||
lazy_static! { | ||
/// a list of rules that should be applied for WCAG1 | ||
pub static ref RULES_A: BTreeMap<&'static str, Vec<Rule>> = | ||
vec![ | ||
// empty titles | ||
("title", Vec::from([ | ||
Rule::new(Techniques::H25, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes, _css_parser| { | ||
(!nodes.is_empty(), "1.NoTitleEl", Default::default()) | ||
}), | ||
Rule::new(Techniques::H25, Criteria::Error, Principle::Understandable, Guideline::Predictable, |_rule, nodes, _css_parser| { | ||
(nodes.is_empty() || nodes[0].html().is_empty(), "2", Default::default()) | ||
}), | ||
])), | ||
// missing label | ||
("form", Vec::from([ | ||
Rule::new(Techniques::H32, Criteria::Error, Principle::Operable, Guideline::Predictable, |_rule, nodes, _css_parser| { | ||
// check the first element for now | ||
let mut valid = false; | ||
|
||
for ele in nodes { | ||
// todo: static selectors | ||
let selector = unsafe { Selector::parse("button[type=submit]").unwrap_unchecked() }; | ||
valid = match ele.select(&selector).next() { | ||
Some(_) => true, | ||
_ => false | ||
}; | ||
} | ||
|
||
(valid, "2", Default::default()) | ||
}), | ||
])) | ||
] | ||
.into_iter() | ||
.collect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters