Fix import from wcag2.1de
This commit is contained in:
parent
903282ef5e
commit
a304cb0d56
4 changed files with 66 additions and 51 deletions
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddUniqIndexToChecksStandards < ActiveRecord::Migration[7.2]
|
||||||
|
def change
|
||||||
|
add_index :checks_standards, [:check_id, :standard_id], unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
3
db/schema.rb
generated
3
db/schema.rb
generated
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.2].define(version: 2024_10_25_215341) do
|
ActiveRecord::Schema[7.2].define(version: 2024_10_26_170258) do
|
||||||
create_table "account_remember_keys", force: :cascade do |t|
|
create_table "account_remember_keys", force: :cascade do |t|
|
||||||
t.string "key", null: false
|
t.string "key", null: false
|
||||||
t.datetime "deadline", null: false
|
t.datetime "deadline", null: false
|
||||||
|
|
@ -116,6 +116,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_25_215341) do
|
||||||
create_table "checks_standards", id: false, force: :cascade do |t|
|
create_table "checks_standards", id: false, force: :cascade do |t|
|
||||||
t.integer "check_id", null: false
|
t.integer "check_id", null: false
|
||||||
t.integer "standard_id", null: false
|
t.integer "standard_id", null: false
|
||||||
|
t.index ["check_id", "standard_id"], name: "index_checks_standards_on_check_id_and_standard_id", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "elements", force: :cascade do |t|
|
create_table "elements", force: :cascade do |t|
|
||||||
|
|
|
||||||
|
|
@ -1,56 +1,65 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
URL = "https://outline-rocks.github.io/wcag/translations/WCAG21-de/"
|
||||||
|
|
||||||
|
def import_wcag21de
|
||||||
|
doc = Nokogiri::HTML5(URI.open(URL))
|
||||||
|
|
||||||
|
standard = Standard.find_by(name_de: "WCAG 2.1")
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
principle_node.css("section").each do |guideline_node|
|
||||||
|
next unless guideline_node.css("h3").first
|
||||||
|
|
||||||
|
guideline_title = guideline_node.css("h3").first.content
|
||||||
|
guideline_text = guideline_node.css("p").first
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# guideline.save!
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
# _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 = "#{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!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@output
|
||||||
|
end
|
||||||
|
|
||||||
namespace :import do
|
namespace :import do
|
||||||
desc "Import WCAG2.1 in german"
|
desc "Import WCAG2.1 in german"
|
||||||
task wcag21de: :environment do
|
task wcag21de: :environment do
|
||||||
URL = "https://outline-rocks.github.io/wcag/translations/WCAG21-de/"
|
Check.transaction do
|
||||||
|
import_wcag21de
|
||||||
doc = Nokogiri::HTML5(URI.open(URL))
|
# raise ActiveRecord::Rollback
|
||||||
|
|
||||||
# standard = Standard.find_or_create_by(url: URL)
|
|
||||||
# standard.name = 'WCAG 2.1'
|
|
||||||
# standard.description = doc.css('#abstract p').map(&:to_s).join
|
|
||||||
# standard.save!
|
|
||||||
|
|
||||||
doc.css("section.principle").each do |principle_node|
|
|
||||||
_principle_id = principle_node.attributes["id"].value
|
|
||||||
_principle_title = principle_node.css("h2").first.content
|
|
||||||
# principle = standard.principles.find_or_create_by(code: principle_id)
|
|
||||||
# principle.name = principle_title.scan(/\d+\. (.*)/).first.last
|
|
||||||
# principle.number = principle_title.scan(/(\d+)\..*/).first.last
|
|
||||||
# principle.save!
|
|
||||||
|
|
||||||
principle_node.css("section").each do |guideline_node|
|
|
||||||
next unless guideline_node.css("h3").first
|
|
||||||
|
|
||||||
guideline_title = guideline_node.css("h3").first.content
|
|
||||||
guideline_text = guideline_node.css("p").first
|
|
||||||
|
|
||||||
_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
|
|
||||||
|
|
||||||
# guideline.save!
|
|
||||||
|
|
||||||
guideline_node.css("section").each do |sc|
|
|
||||||
sc_title = 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_hints = sc.css('div p').map { ReverseMarkdown.convert(_1.to_s) }
|
|
||||||
|
|
||||||
# _sc_number = sc_title.scan(/Erfolgskriterium \d+\.\d+\.(\d+).*/).first.last
|
|
||||||
|
|
||||||
success_criterion = Check.find_or_create_by(name: sc_title)
|
|
||||||
success_criterion.name = sc_title
|
|
||||||
text = "<div>#{guideline_text}<br>#{sc.css('p')[1]}"
|
|
||||||
text += "<p>#{sc.css('dl').first&.to_s}</p>" if sc.css("dl").first
|
|
||||||
|
|
||||||
success_criterion.success_criterion_html = "#{text}</div>".gsub('href="#', %(href="#{URL}#))
|
|
||||||
success_criterion.level = sc_level
|
|
||||||
success_criterion.save!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@output
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class ChecksTest < ApplicationSystemTestCase
|
||||||
select "AAA", from: "Konformitätsstufe"
|
select "AAA", from: "Konformitätsstufe"
|
||||||
fill_in "Name", with: @check.name
|
fill_in "Name", with: @check.name
|
||||||
fill_in "Nummer", with: @check.number
|
fill_in "Nummer", with: @check.number
|
||||||
fill_in_rich_text_area "Kriterium/Grundlage (de)", with: @check.criterion_de
|
fill_in_rich_text_area "Kriterium/Grundlage", with: @check.criterion_de
|
||||||
click_on "Check erstellen"
|
click_on "Check erstellen"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ class ChecksTest < ApplicationSystemTestCase
|
||||||
select "AAA", from: "Konformitätsstufe"
|
select "AAA", from: "Konformitätsstufe"
|
||||||
fill_in "Name", with: @check.name
|
fill_in "Name", with: @check.name
|
||||||
fill_in "Nummer", with: @check.number
|
fill_in "Nummer", with: @check.number
|
||||||
fill_in_rich_text_area "Kriterium/Grundlage (de)", with: @check.criterion_de
|
fill_in_rich_text_area "Kriterium/Grundlage", with: @check.criterion_de
|
||||||
click_on "Check aktualisieren"
|
click_on "Check aktualisieren"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue