#!/usr/bin/env ruby # Compares the Feldkatalog table in the Manifest chapter (public docs site, # separate repo - bildungselemente/website, content-ableger/ableger/docs/ # basis/manifest/index.md) against admin/config.template.yml (via # lib/feldkatalog.rb) and warns about drift in field names or the # Pflicht column. See ableger/website#2: that table already drifted once # (kategorie/lernchancen/material) unnoticed. # # Manual, local check for now (not wired into CI/cron - the doc lives in a # different repo's build) - a first step toward Regel 9 ("die Regeln sind # maschinell prüfbar") for this specific table. Doesn't (and can't) check # the free-text "Bedeutung" column or field order, only Feld/Pflicht. # # Usage: ruby scripts/pruefe-manifest-doku.rb /pfad/zu/manifest/index.md require_relative 'lib/feldkatalog' doc_path = ARGV[0] or abort 'Usage: pruefe-manifest-doku.rb ' text = File.read(doc_path, encoding: 'UTF-8') # The doc has one table per collection, in this order, each row # "| `feld` | Typ | ja/nein | Bedeutung |" - a heading line containing # "**Variante** (`varianten/" marks the switch from the methoden- to the # varianten-table (matching on the path prefix too, so this doesn't # misfire on the unrelated "Methode vs. Variante" comparison table earlier # in the same document, Teil C "Zwei Ebenen", which also mentions # "**Variante**"). collections = %w[methoden varianten] aktuell = 0 doc_pflicht = { 'methoden' => {}, 'varianten' => {} } text.each_line do |zeile| aktuell = 1 if zeile.include?('**Variante** (`varianten/') next unless (m = zeile.match(/\A\|\s*`(?\w+)`\s*\|[^|]*\|\s*(?ja|nein)\s*\|/)) doc_pflicht[collections[aktuell]][m[:feld]] = m[:pflicht] == 'ja' end fehler = [] collections.each do |collection| code_felder = Feldkatalog.felder(collection).to_h { |f| [f[:name], f[:required]] } doc_felder = doc_pflicht[collection] (code_felder.keys - doc_felder.keys).each { |f| fehler << "#{collection}: `#{f}` fehlt in der Doku-Tabelle" } (doc_felder.keys - code_felder.keys).each { |f| fehler << "#{collection}: `#{f}` in der Doku-Tabelle, aber nicht in config.template.yml" } (code_felder.keys & doc_felder.keys).each do |f| next if code_felder[f] == doc_felder[f] fehler << "#{collection}: `#{f}` Pflicht=#{code_felder[f] ? 'ja' : 'nein'} im Code, aber " \ "Pflicht=#{doc_felder[f] ? 'ja' : 'nein'} in der Doku-Tabelle" end end if fehler.empty? puts 'pruefe-manifest-doku: keine Abweichungen gefunden.' else puts 'pruefe-manifest-doku: Abweichungen gefunden:' fehler.each { |f| puts " - #{f}" } exit 1 end