Add wcag en 2.2 import
Some checks failed
/ Run tests (push) Failing after 15s
/ Run system tests (push) Failing after 14s
/ Build, push and deploy image (push) Has been skipped

This commit is contained in:
david 2024-10-27 23:42:06 +01:00
parent 79da447d45
commit f21f75ad62
2 changed files with 67 additions and 7 deletions

View file

@ -12,13 +12,6 @@ class ChecklistEntry < ApplicationRecord
self.position ||= (checklist.checklist_entries.pluck(:position).max || 0) + 1
end
def normalize_positions
checklist.checklist_entries.where.not(id:).find_by(position:)&.update_attribute(:position, position_was)
# checklist.checklist_entries.order(:position).each_with_index do |entry, index|
# entry.update_column(:position, index + 1) if entry.position != index + 1
# end
end
def update_positions
if position_was
checklist.checklist_entries.where("position > ?", position_was).update_all("position = position - 1")

View file

@ -1,5 +1,64 @@
# frozen_string_literal: true
URL = "https://outline-rocks.github.io/wcag/translations/WCAG21-de/"
WCAG_22_EN_URL ="https://www.w3.org/TR/WCAG22/"
def import_wcag22en
puts "import_wcag22en"
doc = Nokogiri::HTML5(URI.open(WCAG_22_EN_URL))
standard = Standard.find_by(name_de: "WCAG 2.2")
doc.css("section.principle").each do |principle_node|
_principle_id = principle_node.attributes["id"].value
principle_title = principle_node.css("h2").first.content.scan(/([a-zA-Z]+)/)
puts principle_title
principle = Principle.find_by!(name_en: principle_title)
principle_node.css("section.guideline").each do |guideline_node|
# puts guideline_node.attr("id")
# puts guideline_node.css("h3").size
# next unless guideline_node.css("h3").first
puts "> guideline"
# debugger
# guideline_title = guideline_node.css("h3 bdi").first&.content
# guideline_text = guideline_node.css("p").first
# guideline_number = guideline_title.scan(/Guideline \d+\.(\d+).*/).first.last
# guideline = principle.guidelines.find_or_create_by(number: guideline_number)
# guideline.title = guideline_title.scan(/Richtlinie \d+\.\d+(.*)/).first.last
# guideline.text = guideline_text
# guideline.save!
guideline_node.css("section.guideline").each do |sc|
sc_title = sc.css("h4").first.content.scan(/Success Criterion \d+\.\d+\.\d+ (.*)/).first.last
sc_number = sc.css("h4").first.content.scan(/Success Criterion (\d+\.\d+\.\d+).*/).first.last
puts sc_number
sc_level = sc.css("p").first&.content&.scan(/\(Level (A+)\)/)&.first&.last
sc_url = sc.css("a.self-link").first.attr("href")
sc_conformity_notice = sc.css("div.note p").to_a.map{"<p>#{_1.content}</p>"}.join("\n")
text = "<div>#{sc.css('p').to_a[1..].map{"<p>#{_1.content}</p>"}.join}"
text += "<p>#{sc.css('dl').first&.to_s}</p>" if sc.css("dl").first
# _sc_number = sc_title.scan(/Erfolgskriterium \d+\.\d+\.(\d+).*/).first.last
check = Check.find_or_initialize_by(external_number: sc_number)
check.name_de = sc_title
check.principle = principle
check.standards << standard unless check.standards.include?(standard)
check.applicable_to_app = check.applicable_to_web = true
check.external_number = sc_number
check.external_url = "#{WCAG_22_EN_URL}#{sc_url}"
check.conformity_level = sc_level&.to_sym
check.conformity_notice_de = sc_conformity_notice
check.criterion_de = "#{text}</div>".gsub('href="#', %(href="#{WCAG_22_EN_URL}#))
check.save!
end
end
end
@output
end
def import_wcag21de
doc = Nokogiri::HTML5(URI.open(URL))
@ -63,4 +122,12 @@ namespace :import do
# raise ActiveRecord::Rollback
end
end
desc "Import WCAG2.2 in english"
task wcag22en: :environment do
Check.transaction do
import_wcag22en
# raise ActiveRecord::Rollback
end
end
end