|
| 1 | +import {processRuleBlocks} from "https://logius-standaarden.github.io/publicatie/respec/plugins/adr.mjs"; |
| 2 | +import { loadRespecWithConfiguration } from "https://logius-standaarden.github.io/publicatie/respec/organisation-config.mjs"; |
| 3 | + |
1 | 4 | async function initializeHighlightJSYaml() {
|
2 | 5 | //this is the function you call in 'preProcess', to load the highlighter
|
3 | 6 | const worker = await new Promise(resolve => {
|
@@ -48,62 +51,7 @@ async function highlightSpectralCode(config, document) {
|
48 | 51 | });
|
49 | 52 | }
|
50 | 53 |
|
51 |
| -function processRuleBlocks(config, document) { |
52 |
| - const functionalRules = []; |
53 |
| - const technicalRules = []; |
54 |
| - for (const rule of document.querySelectorAll('.rule')) { |
55 |
| - if (!rule.id) { |
56 |
| - throw new Error(`Missing id for rule: ${rule.outerHTML}`); |
57 |
| - } |
58 |
| - const ruleId = rule.id; |
59 |
| - |
60 |
| - const ruleLabElement = rule.querySelector('.rulelab'); |
61 |
| - ruleLabElement.innerText = `: ${ruleLabElement.innerText}`; |
62 |
| - const ruleLinkElement = document.createElement('a'); |
63 |
| - ruleLinkElement.href = `#${ruleId}`; |
64 |
| - ruleLinkElement.innerText = ruleId; |
65 |
| - ruleLabElement.prepend(ruleLinkElement); |
66 |
| - |
67 |
| - let flagTitle; |
68 |
| - const flagType = rule.dataset.type; |
69 |
| - if (flagType === 'technical') { |
70 |
| - flagTitle = 'This is a technical design rule and hence should be tested automatically.'; |
71 |
| - technicalRules.push(ruleLabElement); |
72 |
| - |
73 |
| - if (spectralConfiguration.includes(`#${ruleId}`)) { |
74 |
| - const lastDataListItem = rule.querySelector('dt:last-of-type'); |
75 |
| - if (lastDataListItem.textContent !== 'How to test') { |
76 |
| - throw new Error(`Last element should be the "How to test" section. Found ${lastDataListItem.outerHTML}`); |
77 |
| - } |
78 |
| - const howToTest = rule.querySelector('dd:last-of-type'); |
79 |
| - howToTest.innerHTML += `This rule can be automatically checked and an example test is shown in the <a href="#:~:text=${encodeURIComponent(`#${ruleId}`).replaceAll('-', '%2D')}">linter configuration</a>.`; |
80 |
| - } |
81 |
| - } else if (flagType === 'functional') { |
82 |
| - flagTitle = 'This is a functional design rule and hence cannot be tested automatically.'; |
83 |
| - functionalRules.push(ruleLabElement); |
84 |
| - } else { |
85 |
| - throw new Error(`Missing type for rule: ${rule.outerHTML}`); |
86 |
| - } |
87 |
| - |
88 |
| - const flagElement = document.createElement('div'); |
89 |
| - flagElement.title = flagTitle; |
90 |
| - flagElement.innerText = flagType; |
91 |
| - flagElement.classList.add('flag'); |
92 |
| - rule.prepend(flagElement); |
93 |
| - } |
94 |
| - |
95 |
| - for (const [list, elementId] of [[functionalRules, '#functionalList'], [technicalRules, '#technicalList']]) { |
96 |
| - const listElement = document.querySelector(elementId); |
97 |
| - |
98 |
| - for (const ruleLabElement of list) { |
99 |
| - const listItem = document.createElement('li'); |
100 |
| - listItem.innerHTML = ruleLabElement.innerHTML; |
101 |
| - listElement.append(listItem); |
102 |
| - } |
103 |
| - } |
104 |
| -} |
105 |
| - |
106 |
| -globalThis.respecConfig = { |
| 54 | +loadRespecWithConfiguration({ |
107 | 55 | alternateFormats: [ {
|
108 | 56 | "label" : "pdf",
|
109 | 57 | "uri" : "API-Design-Rules.pdf"
|
@@ -159,5 +107,5 @@ globalThis.respecConfig = {
|
159 | 107 | pluralize: true,
|
160 | 108 |
|
161 | 109 | preProcess: [initializeHighlightJSYaml, fetchSpectralConfiguration],
|
162 |
| - postProcess: [highlightSpectralCode, processRuleBlocks], |
163 |
| -}; |
| 110 | + postProcess: [highlightSpectralCode, (config, document, utils) => processRuleBlocks(config, document, utils, spectralConfiguration)], |
| 111 | +}); |
0 commit comments