Skip to content

Commit 0ef1998

Browse files
authored
refactor(w3c/headers): pass additional* as option arguments (#2014)
* refactor: pass additionalContent as options * childNodes
1 parent 274c808 commit 0ef1998

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

src/w3c/headers.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,6 @@ export function run(conf) {
630630
);
631631
}
632632

633-
if (conf.isTagFinding && !conf.additionalContent) {
634-
pub(
635-
"warn",
636-
"ReSpec does not support automated SotD generation for TAG findings, " +
637-
"please add the prerequisite content in the 'sotd' section"
638-
);
639-
}
640633
// Requested by https://github.com/w3c/respec/issues/504
641634
// Makes a record of a few auto-generated things.
642635
pub("amend-user-config", {
@@ -645,25 +638,36 @@ export function run(conf) {
645638
});
646639
}
647640

641+
/**
642+
* @param {*} conf
643+
* @param {HTMLElement} sotd
644+
*/
648645
function populateSoTD(conf, sotd) {
649646
const sotdClone = sotd.cloneNode(true);
650-
const additionalNodes = document.createDocumentFragment();
651-
const additionalContent = document.createElement("temp");
647+
const additionalContent = document.createDocumentFragment();
652648
// we collect everything until we hit a section,
653649
// that becomes the custom content.
654650
while (sotdClone.hasChildNodes()) {
655651
if (
656652
sotdClone.firstChild.nodeType !== Node.ELEMENT_NODE ||
657653
sotdClone.firstChild.localName !== "section"
658654
) {
659-
additionalNodes.appendChild(sotdClone.firstChild);
655+
additionalContent.appendChild(sotdClone.firstChild);
660656
continue;
661657
}
662658
break;
663659
}
664-
additionalContent.appendChild(additionalNodes);
665-
conf.additionalContent = additionalContent.innerHTML;
666-
// Whatever sections are left, we throw at the end.
667-
conf.additionalSections = sotdClone.innerHTML;
668-
return (conf.isCGBG ? cgbgSotdTmpl : sotdTmpl)(conf);
660+
if (conf.isTagFinding && !additionalContent.hasChildNodes()) {
661+
pub(
662+
"warn",
663+
"ReSpec does not support automated SotD generation for TAG findings, " +
664+
"please add the prerequisite content in the 'sotd' section"
665+
);
666+
}
667+
const template = conf.isCGBG ? cgbgSotdTmpl : sotdTmpl;
668+
return template(conf, {
669+
additionalContent,
670+
// Whatever sections are left, we throw at the end.
671+
additionalSections: sotdClone.childNodes,
672+
});
669673
}

src/w3c/templates/cgbg-sotd.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import hyperHTML from "hyperhtml";
22

3-
export default conf => {
3+
export default (conf, opts) => {
44
const html = hyperHTML;
55
return html`
66
<h2>${conf.l10n.sotd}</h2>
@@ -62,7 +62,7 @@ export default conf => {
6262
>W3C Community and Business Groups</a
6363
>.
6464
</p>
65-
${!conf.sotdAfterWGinfo ? [conf.additionalContent] : ""}
65+
${!conf.sotdAfterWGinfo ? opts.additionalContent : ""}
6666
${
6767
conf.wgPublicList
6868
? html`
@@ -102,7 +102,7 @@ export default conf => {
102102
`
103103
: ""
104104
}
105-
${conf.sotdAfterWGinfo ? [conf.additionalContent] : ""}
106-
${[conf.additionalSections]}
105+
${conf.sotdAfterWGinfo ? opts.additionalContent : ""}
106+
${opts.additionalSections}
107107
`;
108108
};

src/w3c/templates/sotd.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import hyperHTML from "hyperhtml";
22

3-
export default conf => {
3+
export default (conf, opts) => {
44
const html = hyperHTML;
55
return html`
66
<h2>${conf.l10n.sotd}</h2>
@@ -44,12 +44,12 @@ export default conf => {
4444
official standing of any kind and does not represent the support
4545
or consensus of any standards organization.
4646
</p>
47-
${[conf.additionalContent]}
47+
${opts.additionalContent}
4848
`
4949
: html`
5050
${
5151
conf.isTagFinding
52-
? [conf.additionalContent]
52+
? opts.additionalContent
5353
: html`
5454
${
5555
conf.isNoTrack
@@ -61,14 +61,14 @@ export default conf => {
6161
and does not represent consensus of the W3C
6262
Membership.
6363
</p>
64-
${[conf.additionalContent]}
64+
${opts.additionalContent}
6565
`
6666
: html`
6767
<p><em>${[conf.l10n.status_at_publication]}</em></p>
6868
${
6969
conf.isSubmission
7070
? html`
71-
${[conf.additionalContent]}
71+
${opts.additionalContent}
7272
${
7373
conf.isMemberSubmission
7474
? html`
@@ -199,7 +199,7 @@ export default conf => {
199199
: html`
200200
${
201201
!conf.sotdAfterWGinfo
202-
? [conf.additionalContent]
202+
? opts.additionalContent
203203
: ""
204204
}
205205
${
@@ -434,7 +434,7 @@ export default conf => {
434434
}
435435
${
436436
conf.sotdAfterWGinfo
437-
? [conf.additionalContent]
437+
? opts.additionalContent
438438
: ""
439439
}
440440
${
@@ -589,6 +589,6 @@ export default conf => {
589589
}
590590
`
591591
}
592-
${[conf.additionalSections]}
592+
${opts.additionalSections}
593593
`;
594594
};

0 commit comments

Comments
 (0)