2024-09-05 22:54:38 +02:00
|
|
|
# frozen_string_literal: true
|
2024-10-26 19:13:20 +02:00
|
|
|
URL = "https://outline-rocks.github.io/wcag/translations/WCAG21-de/"
|
2024-09-05 22:54:38 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
def import_wcag21de
|
|
|
|
|
doc = Nokogiri::HTML5(URI.open(URL))
|
2024-07-19 02:29:18 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
standard = Standard.find_by(name_de: "WCAG 2.1")
|
2024-07-19 02:29:18 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
doc.css("section.principle").each do |principle_node|
|
|
|
|
|
_principle_id = principle_node.attributes["id"].value
|
|
|
|
|
principle_title = principle_node.css("h2").first.content.scan(/[\d\.]+ ([a-zA-ZöäüÖÄÜ]+)/)
|
|
|
|
|
puts principle_title
|
|
|
|
|
principle = Principle.find_by!(name_de: principle_title)
|
2024-07-19 02:29:18 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
principle_node.css("section").each do |guideline_node|
|
|
|
|
|
next unless guideline_node.css("h3").first
|
2024-07-19 02:29:18 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
guideline_title = guideline_node.css("h3").first.content
|
|
|
|
|
guideline_text = guideline_node.css("p").first
|
2024-07-19 02:29:18 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
guideline_number = guideline_title.scan(/Richtlinie \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
|
2024-07-19 02:29:18 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
# guideline.save!
|
2024-07-19 02:29:18 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
guideline_node.css("section").each do |sc|
|
|
|
|
|
sc_title = sc.css("h4").first.content.scan(/Erfolgskriterium \d+\.\d+\.\d+(.*)/).first.last
|
|
|
|
|
sc_number = sc.css("h4").first.content.scan(/Erfolgskriterium (\d+\.\d+\.\d+).*/).first.last
|
|
|
|
|
sc_level = sc.css("p").first.content.scan(/\(Stufe (A+)\)/).first.last
|
|
|
|
|
sc_url = sc.css("h4 a.self-link").first.attr("href")
|
|
|
|
|
sc_conformity_notice = sc.css("div.note p").first&.content
|
|
|
|
|
text = "<div>#{guideline_text}<br>#{sc.css('p')[1]}"
|
|
|
|
|
text += "<p>#{sc.css('dl').first&.to_s}</p>" if sc.css("dl").first
|
2024-07-19 02:29:18 +02:00
|
|
|
|
|
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
# _sc_number = sc_title.scan(/Erfolgskriterium \d+\.\d+\.(\d+).*/).first.last
|
2024-07-19 02:29:18 +02:00
|
|
|
|
2024-10-26 19:13:20 +02:00
|
|
|
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 = "#{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="#{URL}#))
|
|
|
|
|
check.save!
|
2024-07-19 02:29:18 +02:00
|
|
|
end
|
|
|
|
|
end
|
2024-10-26 19:13:20 +02:00
|
|
|
end
|
|
|
|
|
@output
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
namespace :import do
|
|
|
|
|
desc "Import WCAG2.1 in german"
|
|
|
|
|
task wcag21de: :environment do
|
|
|
|
|
Check.transaction do
|
|
|
|
|
import_wcag21de
|
|
|
|
|
# raise ActiveRecord::Rollback
|
|
|
|
|
end
|
2024-07-19 02:29:18 +02:00
|
|
|
end
|
|
|
|
|
end
|