From ede05b7a0e1f516f07172949e09f4a06060f17b9 Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Tue, 21 Feb 2017 17:34:41 +1100 Subject: [PATCH] refactor(w3c/rfc2119): convert to ES6 --- js/w3c/rfc2119.js | 41 ----------------------------------------- src/w3c/rfc2119.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 41 deletions(-) delete mode 100644 js/w3c/rfc2119.js create mode 100644 src/w3c/rfc2119.js diff --git a/js/w3c/rfc2119.js b/js/w3c/rfc2119.js deleted file mode 100644 index 443ec22cb7..0000000000 --- a/js/w3c/rfc2119.js +++ /dev/null @@ -1,41 +0,0 @@ -// Module w3c/rfc2119 -// update the 2119 terms section with the terms actually used - -define( - ["core/utils"], - function (utils) { - return { - run: function (conf, doc, cb) { - var $confo = $("#respecRFC2119"); - if ($confo.length) { - // do we have a list of used RFC2119 items in - // conf.respecRFC2119 - var used = Object.getOwnPropertyNames(conf.respecRFC2119).sort() ; - if (used && used.length) { - // put in the 2119 clause and reference - var str = "The " ; - var mapper = function(item) { - var ret = ""+item+"" ; - return ret; - }; - - if (used.length > 1) { - str += "key words " + utils.joinAnd(used, mapper) + " are "; - } - else { - str += "key word " + utils.joinAnd(used, mapper) + " is " ; - } - str += $confo[0].innerHTML ; - $confo[0].innerHTML = str ; - } - else { - // there are no terms used - remove the - // clause - $confo.remove() ; - } - } - cb(); - } - }; - } -); diff --git a/src/w3c/rfc2119.js b/src/w3c/rfc2119.js new file mode 100644 index 0000000000..3dd914037d --- /dev/null +++ b/src/w3c/rfc2119.js @@ -0,0 +1,29 @@ +// Module w3c/rfc2119 +// update the 2119 terms section with the terms actually used + +import { joinAnd } from "core/utils"; + +export const name = "w3c/rfc2119"; + +export function run(conf, doc, cb) { + const confo = doc.getElementById("respecRFC2119"); + if (!confo) { + return cb(); + } + // do we have a list of used RFC2119 items in + // conf.respecRFC2119 + const terms = Object.getOwnPropertyNames(conf.respecRFC2119) + + // there are no terms used - remove the clause + if (terms.length === 0) { + confo.remove(); + return cb(); + } + + // put in the 2119 clause and reference + const html = joinAnd(terms.sort(), item => `${item}`); + const plural = terms.length > 1; + const str = `The key word${plural ? "s " : " "} ${html} ${plural ? "are" : "is"} ${confo.innerHTML}`; + confo.innerHTML = str; + cb(); +}