You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@community.apache.org by hu...@apache.org on 2019/08/03 02:05:43 UTC
svn commit: r1864291 - in /comdev/reporter.apache.org/trunk/site/wizard/js:
source/generators.js source/unified.js source/whimsy-flow.js wizard.js
Author: humbedooh
Date: Sat Aug 3 02:05:43 2019
New Revision: 1864291
URL: http://svn.apache.org/viewvc?rev=1864291&view=rev
Log:
Use whimsy's flow class for reflowing, but stick with the original for overflow detection (it's more reliable as it's less invasive for testing for overflow)
Added:
comdev/reporter.apache.org/trunk/site/wizard/js/source/whimsy-flow.js
Modified:
comdev/reporter.apache.org/trunk/site/wizard/js/source/generators.js
comdev/reporter.apache.org/trunk/site/wizard/js/source/unified.js
comdev/reporter.apache.org/trunk/site/wizard/js/wizard.js
Modified: comdev/reporter.apache.org/trunk/site/wizard/js/source/generators.js
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/site/wizard/js/source/generators.js?rev=1864291&r1=1864290&r2=1864291&view=diff
==============================================================================
--- comdev/reporter.apache.org/trunk/site/wizard/js/source/generators.js (original)
+++ comdev/reporter.apache.org/trunk/site/wizard/js/source/generators.js Sat Aug 3 02:05:43 2019
@@ -255,7 +255,7 @@ function reflow(txt, chars) {
for (var i = 0; i < words.length; i++) {
let word = words[i];
x += word.length;
- if (x >= chars) {
+ if (x > chars) {
output += (x == 0 ? "" : "\n") + word;
x = word.length;
} else if (word[word.length-1] == '\n') {
Modified: comdev/reporter.apache.org/trunk/site/wizard/js/source/unified.js
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/site/wizard/js/source/unified.js?rev=1864291&r1=1864290&r2=1864291&view=diff
==============================================================================
--- comdev/reporter.apache.org/trunk/site/wizard/js/source/unified.js (original)
+++ comdev/reporter.apache.org/trunk/site/wizard/js/source/unified.js Sat Aug 3 02:05:43 2019
@@ -31,7 +31,7 @@ function UnifiedEditor_highlight_section
reflower.innerHTML = "SECTION IS OVERFLOWING 80 CHARACTERS!";
let btn = new HTML('button', {class: 'btn btn-success btn-sm'}, "Reflow section");
btn.addEventListener('click', () => {
- this.object.value = this.object.value.replace(additional_text, reflow(additional_text));
+ this.object.value = this.object.value.replace(additional_text, Flow.text(additional_text));
$(this.object).prop( {
'selectionStart': x,
'selectionEnd': y}
Added: comdev/reporter.apache.org/trunk/site/wizard/js/source/whimsy-flow.js
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/site/wizard/js/source/whimsy-flow.js?rev=1864291&view=auto
==============================================================================
--- comdev/reporter.apache.org/trunk/site/wizard/js/source/whimsy-flow.js (added)
+++ comdev/reporter.apache.org/trunk/site/wizard/js/source/whimsy-flow.js Sat Aug 3 02:05:43 2019
@@ -0,0 +1,74 @@
+// borrowed from https://whimsy.apache.org/board/agenda/app.js
+
+class Flow {
+ // reflow comment
+ static comment(comment, initials, indent=" ") {
+ let lines = comment.split("\n");
+ let len = 71 - indent.length;
+
+ for (let i = 0; i < lines.length; i++) {
+ lines[i] = ((i == 0 ? initials + ": " : `${indent} `)) + lines[i].replace(
+ new RegExp(`(.{1,${len}})( +|$\\n?)|(.{1,${len}})`, "g"),
+ `$1$3\n${indent}`
+ ).trim()
+ };
+
+ return lines.join("\n")
+ };
+
+ // reflow text. Indent is a string containing the amount of spaces that are
+ // to be added to each line. The Incubator has special punctuation rules that
+ // prohibit the joining of lines where the first line ends in either a colon
+ // or a question mark.
+ static text(text, indent="", puncrules=false) {
+ // remove trailing spaces on lines
+ text = text.replace(/[ \r\t]+\n/g, "\n");
+
+ // split into lines
+ let lines = text.split("\n");
+
+ // join consecutive lines, making exception for lines that start with a
+ // hash (#) and <markers> like <private>, ")".
+ for (let i = lines.length - 1; i >= 1; i--) {
+ if (/^$|^#|\w>$/m.test(lines[i - 1])) continue;
+ if (puncrules && /[:?]$/m.test(lines[i - 1])) continue;
+
+ if (/^\s*\w/m.test(lines[i]) && !/^\s*\d+\./m.test(lines[i])) {
+ lines.splice(i - 1, 2, lines[i - 1] + lines[i].replace(/^\s*/m, " "))
+ }
+ };
+
+ // reflow each line
+ let len = 78 - indent.length;
+
+ for (let i = 0; i < lines.length; i++) {
+ let line = lines[i];
+ if (line.length <= len) continue;
+ let prefix = /^\d+\.\s+|^\W*/m.exec(line)[0];
+
+ if (prefix.length == 0) {
+ // not indented -> split
+ lines[i] = line.replace(
+ new RegExp(`(.{1,${len}})( +|$\\n?)`, "g"),
+ "$1\n"
+ ).replace(/[\n\r]+$/m, "")
+ } else {
+ // ensure line can be split after column 40
+ let lastspace = /^.*\s\S/m.exec(line);
+
+ if (lastspace && lastspace[0].length - 1 > 40) {
+ // preserve indentation.
+ let n = len - prefix.length;
+ indent = prefix.replace(/\S/g, " ");
+
+ lines[i] = prefix + line.slice(prefix.length).replace(
+ new RegExp(`(.{1,${n}})( +|$\\n?)`, "g"),
+ indent + "$1\n"
+ ).replace(indent, "").replace(/[\n\r]+$/m, "")
+ }
+ }
+ };
+
+ return lines.join("\n")
+ }
+};
\ No newline at end of file
Modified: comdev/reporter.apache.org/trunk/site/wizard/js/wizard.js
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/site/wizard/js/wizard.js?rev=1864291&r1=1864290&r2=1864291&view=diff
==============================================================================
--- comdev/reporter.apache.org/trunk/site/wizard/js/wizard.js (original)
+++ comdev/reporter.apache.org/trunk/site/wizard/js/wizard.js Sat Aug 3 02:05:43 2019
@@ -1424,7 +1424,7 @@ function reflow(txt, chars) {
for (var i = 0; i < words.length; i++) {
let word = words[i];
x += word.length;
- if (x >= chars) {
+ if (x > chars) {
output += (x == 0 ? "" : "\n") + word;
x = word.length;
} else if (word[word.length-1] == '\n') {
@@ -1931,7 +1931,7 @@ function UnifiedEditor_highlight_section
reflower.innerHTML = "SECTION IS OVERFLOWING 80 CHARACTERS!";
let btn = new HTML('button', {class: 'btn btn-success btn-sm'}, "Reflow section");
btn.addEventListener('click', () => {
- this.object.value = this.object.value.replace(additional_text, reflow(additional_text));
+ this.object.value = this.object.value.replace(additional_text, Flow.text(additional_text));
$(this.object).prop( {
'selectionStart': x,
'selectionEnd': y}
@@ -2183,3 +2183,83 @@ function UnifiedEditor(div, layout) {
this.object.addEventListener('mouseup', () => { this.find_section(); });
}
+
+
+/******************************************
+ Fetched from source/whimsy-flow.js
+******************************************/
+
+// borrowed from https://whimsy.apache.org/board/agenda/app.js
+
+class Flow {
+ // reflow comment
+ static comment(comment, initials, indent=" ") {
+ let lines = comment.split("\n");
+ let len = 71 - indent.length;
+
+ for (let i = 0; i < lines.length; i++) {
+ lines[i] = ((i == 0 ? initials + ": " : `${indent} `)) + lines[i].replace(
+ new RegExp(`(.{1,${len}})( +|$\\n?)|(.{1,${len}})`, "g"),
+ `$1$3\n${indent}`
+ ).trim()
+ };
+
+ return lines.join("\n")
+ };
+
+ // reflow text. Indent is a string containing the amount of spaces that are
+ // to be added to each line. The Incubator has special punctuation rules that
+ // prohibit the joining of lines where the first line ends in either a colon
+ // or a question mark.
+ static text(text, indent="", puncrules=false) {
+ // remove trailing spaces on lines
+ text = text.replace(/[ \r\t]+\n/g, "\n");
+
+ // split into lines
+ let lines = text.split("\n");
+
+ // join consecutive lines, making exception for lines that start with a
+ // hash (#) and <markers> like <private>, ")".
+ for (let i = lines.length - 1; i >= 1; i--) {
+ if (/^$|^#|\w>$/m.test(lines[i - 1])) continue;
+ if (puncrules && /[:?]$/m.test(lines[i - 1])) continue;
+
+ if (/^\s*\w/m.test(lines[i]) && !/^\s*\d+\./m.test(lines[i])) {
+ lines.splice(i - 1, 2, lines[i - 1] + lines[i].replace(/^\s*/m, " "))
+ }
+ };
+
+ // reflow each line
+ let len = 78 - indent.length;
+
+ for (let i = 0; i < lines.length; i++) {
+ let line = lines[i];
+ if (line.length <= len) continue;
+ let prefix = /^\d+\.\s+|^\W*/m.exec(line)[0];
+
+ if (prefix.length == 0) {
+ // not indented -> split
+ lines[i] = line.replace(
+ new RegExp(`(.{1,${len}})( +|$\\n?)`, "g"),
+ "$1\n"
+ ).replace(/[\n\r]+$/m, "")
+ } else {
+ // ensure line can be split after column 40
+ let lastspace = /^.*\s\S/m.exec(line);
+
+ if (lastspace && lastspace[0].length - 1 > 40) {
+ // preserve indentation.
+ let n = len - prefix.length;
+ indent = prefix.replace(/\S/g, " ");
+
+ lines[i] = prefix + line.slice(prefix.length).replace(
+ new RegExp(`(.{1,${n}})( +|$\\n?)`, "g"),
+ indent + "$1\n"
+ ).replace(indent, "").replace(/[\n\r]+$/m, "")
+ }
+ }
+ };
+
+ return lines.join("\n")
+ }
+};
\ No newline at end of file