use crate::engine::rules::techniques::Techniques;
use crate::engine::rules::wcag_base::{Guideline, IssueType, Principle};
use accessibility_scraper::ElementRef;
#[derive(Default, Debug)]
pub struct Validation {
pub valid: bool,
pub id: &'static str,
pub elements: Vec<String>,
pub message: String,
}
impl Validation {
pub fn new(valid: bool, id: &'static str, elements: Vec<String>, message: String) -> Self {
Self {
valid,
id,
elements,
message,
}
}
pub fn new_issue(valid: bool, id: &'static str) -> Self {
Self {
valid,
id,
..Default::default()
}
}
pub fn new_custom_issue(valid: bool, id: &'static str, message: String) -> Self {
Self {
valid,
id,
message,
..Default::default()
}
}
}
#[derive(Debug, Clone)]
pub enum Technique {
Single(Techniques),
Multi(Vec<Techniques>),
}
impl Technique {
pub fn into_str(&self) -> String {
match self {
Technique::Multi(tech) => tech
.iter()
.map(|x| x.as_str())
.collect::<Vec<_>>()
.join(",")
.into(),
Technique::Single(tech) => tech.as_str().into(),
}
}
}
impl From<Techniques> for Technique {
fn from(t: Techniques) -> Self {
Technique::Single(t)
}
}
impl From<Vec<Techniques>> for Technique {
fn from(t: Vec<Techniques>) -> Self {
Technique::Multi(t)
}
}
pub enum RuleValidation {
Single(Validation),
Multi(Vec<Validation>),
}
impl From<Validation> for RuleValidation {
fn from(t: Validation) -> Self {
RuleValidation::Single(t)
}
}
impl From<Vec<Validation>> for RuleValidation {
fn from(t: Vec<Validation>) -> Self {
RuleValidation::Multi(t)
}
}
type ValidateFn =
fn(&Vec<(ElementRef<'_>, Option<taffy::NodeId>)>, &crate::Auditor<'_>) -> RuleValidation;
#[derive(Debug)]
pub struct Rule {
pub rule_id: Technique,
pub issue_type: IssueType,
pub validate: ValidateFn,
pub principle: Principle,
pub guideline: Guideline,
pub success_criteria: &'static str,
}
impl Rule {
pub fn new(
rule_id: Technique,
issue_type: IssueType,
principle: Principle,
guideline: Guideline,
success_criteria: &'static str,
validate: ValidateFn,
) -> Rule {
Rule {
rule_id,
issue_type,
guideline,
principle,
success_criteria,
validate,
}
}
}