M index.html => index.html +97 -1
@@ 18,6 18,27 @@
<h2>Generation Wizard</h2>
<section id=wizard>
<label for=license_sel>License:</label> <select id=license_sel></select><br/>
+ <label for=creator_sel>Creator Type:</label> <select id=creator_sel>
+ <option>creator</option>
+ <option>creators</option>
+ <option selected>creator(s)</option>
+ <option>artist</option>
+ <option>artists</option>
+ <option>artist(s)</option>
+ <option>author</option>
+ <option>authors</option>
+ <option>author(s)</option>
+ </select><br/>
+ <label for=worktype_sel>Work Type:</label> <select id=worktype_sel>
+ <option>software</option>
+ <option>content</option>
+ <option>work</option>
+ </select><br/>
+ <label for=medium_sel>Project Medium:</label> <select id=medium_sel>
+ <option>repository</option>
+ <option>archive</option>
+ <option>website</option>
+ </select><br/>
<input type=checkbox id=include_header checked /> <label for=include_header>Include header?</label><br/>
<div id=license_opts></div>
<textarea readonly id=license_text cols=74 rows=10></textarea>
@@ 69,6 90,7 @@ async function template_changed() {
for (const part of templates[license_sel.value].format) {
if (part.optional) {
const box = document.createElement("input");
+ box.addEventListener("change", params_changed);
box.type = "checkbox";
box.id = part.optional.replace(" ", "-");
box.checked = part.default;
@@ 96,8 118,77 @@ async function params_changed() {
continue;
}
license_text.value += "\n\n";
- license_text.value += part.contents.trim();
+ license_text.value += word_wrap(
+ do_substitution(
+ part.contents.trim()));
}
+ license_text.value = license_text.value.trim();
+}
+
+function do_substitution(text) {
+// console.log(text);
+ let newtext = "";
+ let last_idx = -1;
+ let idx = -1;
+ while ((idx = text.indexOf("$", idx+1)) != -1) {
+ newtext += text.slice(last_idx + 1, idx);
+// console.log(newtext);
+
+ let start = idx+1;
+ idx = text.indexOf("$", idx+1);
+ if (idx == -1) idx = text.length;
+ let end = idx;
+
+ let [key, filter] = text.slice(start, end).split(":", 2);
+
+ let subst = key;
+ switch (key) {
+ case "type":
+ subst = worktype_sel.value;
+ break;
+ case "medium":
+ subst = medium_sel.value;
+ break;
+ case "creator":
+ subst = creator_sel.value;
+ break;
+ case "author_verb":
+ let [single, plural] = filter.split("|", 2);
+ filter = "";
+ if (/s$|\(s\)$/.test(creator_sel.value))
+ subst = plural;
+ else subst = single;
+ }
+
+ if (filter?.includes("caps")) subst = subst.toUpperCase();
+ if (filter?.includes("lower")) subst = subst.toLowerCase();
+
+ newtext += subst;
+
+ last_idx = idx;
+ }
+ return newtext + text.slice(last_idx+1);
+}
+
+function word_wrap(text, cols = 72) {
+// console.log(text);
+ let [firstword, ...words] = text.split(/[ \n\r\t]+/g)
+ .filter(x => x)
+ .map(s =>
+ s.match(RegExp(`.{1,${cols}}`, 'g'))).flat();
+ let newtext = firstword;
+ let count = firstword.length+1;
+// console.log(words, firstword);
+ for (const word of words) {
+ count += word.length + 1;
+ if (count >= cols) {
+ newtext += "\n" + word;
+ count = word.length + 1;
+ } else {
+ newtext += ' ' + word;
+ }
+ }
+ return newtext;
}
for (const template in templates) {
@@ 107,8 198,13 @@ for (const template in templates) {
}
license_sel.addEventListener("change", template_changed);
include_header.addEventListener("change", params_changed);
+creator_sel.addEventListener("change", params_changed);
+worktype_sel.addEventListener("change", params_changed);
+medium_sel.addEventListener("change", params_changed);
template_changed();
})()</script>
+<script>
+</script>
</body>
M templates/PD/main.txt => templates/PD/main.txt +4 -3
@@ 1,3 1,4 @@
-This $medium:lower is dedicated entirely to the public domain. The
-$creator:lower waives all intellectual property rights to the work as
-much as is possible in any relevant jurisdictions.
+This $medium:lower$ is dedicated entirely to the public domain. The
+$creator:lower$ $author_verb:waives|waive$ all intellectual property
+rights to the work as much as is possible in any relevant
+jurisdictions.
M templates/liability.txt => templates/liability.txt +3 -3
@@ 1,7 1,7 @@
-THE $type:caps IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS $type:caps INCLUDING ALL IMPLIED WARRANTIES
+THE $type:caps$ IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS $type:caps$ INCLUDING ALL IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
-OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS $type:caps.
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS $type:caps$.