You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by cm...@apache.org on 2009/01/12 22:06:48 UTC
svn commit: r733897 - in /couchdb/trunk/share: ./ www/ www/script/ www/style/
Author: cmlenz
Date: Mon Jan 12 13:06:35 2009
New Revision: 733897
URL: http://svn.apache.org/viewvc?rev=733897&view=rev
Log:
Add syntax highlighting of JSON code in Futon.
Added:
couchdb/trunk/share/www/script/futon.format.js
- copied, changed from r733182, couchdb/trunk/share/www/script/pprint.js
Removed:
couchdb/trunk/share/www/script/pprint.js
Modified:
couchdb/trunk/share/Makefile.am
couchdb/trunk/share/www/config.html
couchdb/trunk/share/www/couch_tests.html
couchdb/trunk/share/www/database.html
couchdb/trunk/share/www/document.html
couchdb/trunk/share/www/index.html
couchdb/trunk/share/www/replicator.html
couchdb/trunk/share/www/script/browse.js
couchdb/trunk/share/www/script/futon.js
couchdb/trunk/share/www/script/jquery.cookies.js
couchdb/trunk/share/www/script/jquery.couch.js
couchdb/trunk/share/www/style/layout.css
Modified: couchdb/trunk/share/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/Makefile.am?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/Makefile.am (original)
+++ couchdb/trunk/share/Makefile.am Mon Jan 12 13:06:35 2009
@@ -59,6 +59,7 @@
www/script/couch_tests.js \
www/script/couch_test_runner.js \
www/script/futon.js \
+ www/script/futon.format.js \
www/script/jquery.js \
www/script/jquery.cookies.js \
www/script/jquery.couch.js \
@@ -67,5 +68,4 @@
www/script/jquery.resizer.js \
www/script/jquery.suggest.js \
www/script/json2.js \
- www/script/pprint.js \
www/style/layout.css
Modified: couchdb/trunk/share/www/config.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/config.html?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/config.html (original)
+++ couchdb/trunk/share/www/config.html Mon Jan 12 13:06:35 2009
@@ -23,7 +23,6 @@
<script src="script/jquery.cookies.js?0.9.0"></script>
<script src="script/jquery.couch.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
- <script src="script/pprint.js?0.9.0"></script>
<script>
$(document).ready(function() {
$(document.body).addClass("loading");
Modified: couchdb/trunk/share/www/couch_tests.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/couch_tests.html?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/couch_tests.html [utf-8] (original)
+++ couchdb/trunk/share/www/couch_tests.html [utf-8] Mon Jan 12 13:06:35 2009
@@ -24,7 +24,6 @@
<script src="script/jquery.couch.js?0.9.0"></script>
<script src="script/couch.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
- <script src="script/pprint.js?0.9.0"></script>
<script src="script/couch_test_runner.js"></script>
<script>
$(function() {
Modified: couchdb/trunk/share/www/database.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/database.html?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/database.html [utf-8] (original)
+++ couchdb/trunk/share/www/database.html [utf-8] Mon Jan 12 13:06:35 2009
@@ -27,7 +27,7 @@
<script src="script/jquery.suggest.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/browse.js?0.9.0"></script>
- <script src="script/pprint.js?0.9.0"></script>
+ <script src="script/futon.format.js?0.9.0"></script>
<script>
var page = new CouchDatabasePage();
Modified: couchdb/trunk/share/www/document.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/document.html?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/document.html [utf-8] (original)
+++ couchdb/trunk/share/www/document.html [utf-8] Mon Jan 12 13:06:35 2009
@@ -27,7 +27,7 @@
<script src="script/jquery.resizer.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/browse.js?0.9.0"></script>
- <script src="script/pprint.js?0.9.0"></script>
+ <script src="script/futon.format.js?0.9.0"></script>
<script>
var page = new CouchDocumentPage();
@@ -59,7 +59,7 @@
$("#fields thead th:first").text("Source").attr("colspan", 2).next().hide();
$("#fields tbody.content").hide();
$("#fields tbody.source").find("td").each(function() {
- $(this).html($("<code></code>").text(prettyPrintJSON(page.doc)));
+ $(this).html($("<pre></pre>").html($.futon.formatJSON(page.doc, {html: true})));
}).end().show();
});
Modified: couchdb/trunk/share/www/index.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/index.html?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/index.html [utf-8] (original)
+++ couchdb/trunk/share/www/index.html [utf-8] Mon Jan 12 13:06:35 2009
@@ -25,7 +25,7 @@
<script src="script/jquery.dialog.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/browse.js?0.9.0"></script>
- <script src="script/pprint.js?0.9.0"></script>
+ <script src="script/futon.format.js?0.9.0"></script>
<script>
var page = new CouchIndexPage();
$(document).ready(function() {
Modified: couchdb/trunk/share/www/replicator.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/replicator.html?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/replicator.html [utf-8] (original)
+++ couchdb/trunk/share/www/replicator.html [utf-8] Mon Jan 12 13:06:35 2009
@@ -23,7 +23,6 @@
<script src="script/jquery.cookies.js?0.9.0"></script>
<script src="script/jquery.couch.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
- <script src="script/pprint.js?0.9.0"></script>
<script>
$(document).ready(function() {
$("fieldset input[type=radio]").click(function() {
Modified: couchdb/trunk/share/www/script/browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/browse.js?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/browse.js [utf-8] Mon Jan 12 13:06:35 2009
@@ -59,7 +59,7 @@
$.couch.db(dbName).info({
success: function(info) {
$("#databases tbody.content tr:eq(" + idx + ")")
- .find("td.size").text(prettyPrintSize(info.disk_size)).end()
+ .find("td.size").text($.futon.formatSize(info.disk_size)).end()
.find("td.count").text(info.doc_count).end()
.find("td.seq").text(info.update_seq);
if (idx == dbsOnPage.length - 1) {
@@ -457,22 +457,28 @@
for (var i = 0; i < resp.rows.length; i++) {
var row = resp.rows[i];
var tr = $("<tr></tr>");
- var key = row.key;
+ var key = "null";
+ if (row.key !== null) {
+ key = $.futon.formatJSON(row.key, {indent: 0, linesep: ""});
+ }
if (row.id) {
$("<td class='key'><a href='document.html?" + encodeURIComponent(db.name) +
"/" + encodeDocId(row.id) + "'><strong></strong><br>" +
"<span class='docid'>ID: " + row.id + "</span></a></td>")
- .find("strong").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end()
+ .find("strong").text(key).end()
.appendTo(tr);
} else {
$("<td class='key'><strong></strong></td>")
- .find("strong").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end()
+ .find("strong").text(key).end()
.appendTo(tr);
}
- var value = row.value;
- $("<td class='value'></td>").text(
- value !== null ? prettyPrintJSON(value, 0, "") : "null"
- ).appendTo(tr).dblclick(function() {
+ var value = "null";
+ if (row.value !== null) {
+ value = $.futon.formatJSON(row.value, {
+ html: true, indent: 0, linesep: "", quoteKeys: false
+ });
+ }
+ $("<td class='value'><div></div></td>").find("div").html(value).end().appendTo(tr).dblclick(function() {
location.href = this.previousSibling.firstChild.href;
});
tr.appendTo("#documents tbody.content");
@@ -736,7 +742,7 @@
_initValue(value);
}
}
- $("#fields tbody tr").removeClass("odd").filter(":odd").addClass("odd");
+ $("#fields tbody.content tr").removeClass("odd").filter(":odd").addClass("odd");
return row;
}
@@ -838,7 +844,7 @@
cancelChange();
}).appendTo(tools);
tools.appendTo(td);
- input.val(prettyPrintJSON(value)).appendTo(td);
+ input.val($.futon.formatJSON(value)).appendTo(td);
input.each(function() { this.focus(); this.select(); });
if (needsTextarea) input.makeResizable({vertical: true});
}
@@ -849,7 +855,7 @@
delete doc[fieldName];
row.remove();
page.isDirty = true;
- $("#fields tbody tr").removeClass("odd").filter(":odd").addClass("odd");
+ $("#fields tbody.content tr").removeClass("odd").filter(":odd").addClass("odd");
}).prependTo(row.find("th"));
}
}
@@ -894,7 +900,7 @@
$("<a href='' title='Download file' target='_top'></a>").text(name)
.attr("href", attachmentHref)
.wrapInner("<tt></tt>").appendTo(li);
- $("<span>()</span>").text("" + prettyPrintSize(attachment.length) +
+ $("<span>()</span>").text("" + $.futon.formatSize(attachment.length) +
", " + attachment.content_type).addClass("info").appendTo(li);
if (name == "tests.js") {
li.find('span.info').append(', <a href="/_utils/couch_tests.html?'
Copied: couchdb/trunk/share/www/script/futon.format.js (from r733182, couchdb/trunk/share/www/script/pprint.js)
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.format.js?p2=couchdb/trunk/share/www/script/futon.format.js&p1=couchdb/trunk/share/www/script/pprint.js&r1=733182&r2=733897&rev=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/pprint.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.format.js [utf-8] Mon Jan 12 13:06:35 2009
@@ -10,65 +10,109 @@
// License for the specific language governing permissions and limitations under
// the License.
-// JSON pretty printing
+(function($) {
+ $.futon = $.futon || {};
+ $.extend($.futon, {
-function prettyPrintJSON(val, indent, linesep, depth) {
- indent = indent != null ? indent : 4;
- linesep = linesep != null ? linesep : "\n";
- depth = depth != null ? depth : 1;
- var propsep = linesep.length ? "," + linesep : ", ";
- var tab = [];
- for (var i = 0; i < indent * depth; i++) tab.push("");
- tab = tab.join(" ");
- switch (typeof val) {
- case "boolean":
- case "number":
- case "string":
- return JSON.stringify(val);
- case "object": {
- if (val === null) return "null";
- if (val.constructor == Date) return JSON.stringify(val);
- var buf = [];
- if (val.constructor == Array) {
- buf.push("[");
- for (var index = 0; index < val.length; index++) {
- buf.push(index > 0 ? propsep : linesep);
- buf.push(
- tab, prettyPrintJSON(val[index], indent, linesep, depth + 1)
- );
- }
- if (index >= 0) buf.push(linesep, tab.substr(indent));
- buf.push("]");
- } else {
- buf.push("{");
- var index = 0;
- for (var key in val) {
- if (!val.hasOwnProperty(key)) continue;
- buf.push(index > 0 ? propsep : linesep);
- buf.push(
- tab, JSON.stringify(key), ": ",
- prettyPrintJSON(val[key], indent, linesep, depth + 1)
- );
- index++;
+ // JSON pretty printing
+ formatJSON: function(val, options) {
+ options = options || {};
+ if (options.indent === undefined) {
+ options.indent = 4;
+ }
+ options.indent = options.indent !== undefined ? options.indent : 4;
+ options.linesep = options.linesep !== undefined ? options.linesep : "\n";
+ options.quoteKeys = options.quoteKeys !== undefined ? options.quoteKeys : true;
+ var itemsep = options.linesep.length ? "," + options.linesep : ", ";
+
+ function escape(string) {
+ return string.replace(/&/g, "&")
+ .replace(/</g, "<")
+ .replace(/>/g, ">");
+ }
+
+ function format(val, depth) {
+ var tab = [];
+ for (var i = 0; i < options.indent * depth; i++) tab.push("");
+ tab = tab.join(" ");
+
+ var type = typeof val;
+ switch (type) {
+ case "boolean":
+ case "number":
+ case "string":
+ var retval = JSON.stringify(val);
+ if (options.html) {
+ retval = "<code class='" + type + "'>" + escape(retval) + "</code>";
+ }
+ return retval;
+
+ case "object": {
+ if (val === null) {
+ if (options.html) {
+ return "<code class='null'>null</code>";
+ }
+ return "null";
+ }
+ if (val.constructor == Date) {
+ return JSON.stringify(val);
+ }
+
+ var buf = [];
+
+ if (val.constructor == Array) {
+ buf.push("[");
+ for (var index = 0; index < val.length; index++) {
+ buf.push(index > 0 ? itemsep : options.linesep);
+ buf.push(tab, format(val[index], depth + 1));
+ }
+ if (index >= 0) buf.push(options.linesep, tab.substr(options.indent));
+ buf.push("]");
+
+ } else {
+ buf.push("{");
+ var index = 0;
+ for (var key in val) {
+ if (!val.hasOwnProperty(key)) continue;
+ buf.push(index > 0 ? itemsep : options.linesep);
+ var keyDisplay = options.quoteKeys ? JSON.stringify(key) : key;
+ if (options.html) {
+ if (options.quoteKeys) {
+ keyDisplay = keyDisplay.substr(1, keyDisplay.length - 2);
+ }
+ keyDisplay = "<code class='key'>" + escape(keyDisplay) + "</code>";
+ if (options.quoteKeys) {
+ keyDisplay = '"' + keyDisplay + '"';
+ }
+ }
+ buf.push(tab, keyDisplay,
+ ": ", format(val[key], depth + 1));
+ index++;
+ }
+ if (index >= 0) buf.push(options.linesep, tab.substr(options.indent));
+ buf.push("}");
+ }
+
+ return buf.join("");
+ }
}
- if (index >= 0) buf.push(linesep, tab.substr(indent));
- buf.push("}");
}
- return buf.join("");
- }
- }
-}
-// File size pretty printing
+ return format(val, 1);
+ },
+
+ // File size pretty printing
+ formatSize: function(size) {
+ var jump = 512;
+ if (size < jump) return size + " bytes";
+ var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
+ var i = 0;
+ while (size >= jump && i < units.length) {
+ i += 1;
+ size /= 1024
+ }
+ return size.toFixed(1) + ' ' + units[i - 1];
+ }
-function prettyPrintSize(size) {
- var jump = 512;
- if (size < jump) return size + " bytes";
- var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
- var i = 0;
- while (size >= jump && i < units.length) {
- i += 1;
- size /= 1024
- }
- return size.toFixed(1) + ' ' + units[i - 1];
-}
+ });
+})(jQuery);
Modified: couchdb/trunk/share/www/script/futon.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.js?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.js (original)
+++ couchdb/trunk/share/www/script/futon.js Mon Jan 12 13:06:35 2009
@@ -103,7 +103,7 @@
}
$.futon = $.futon || {};
- $.fn.extend($.futon, {
+ $.extend($.futon, {
navigation: new Navigation()
});
Modified: couchdb/trunk/share/www/script/jquery.cookies.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.cookies.js?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.cookies.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.cookies.js [utf-8] Mon Jan 12 13:06:35 2009
@@ -12,7 +12,7 @@
(function($) {
$.cookies = $.cookies || {}
- $.fn.extend($.cookies, {
+ $.extend($.cookies, {
/* Return the value of a cookie. */
get: function(name, defaultValue) {
Modified: couchdb/trunk/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.couch.js?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.couch.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.couch.js [utf-8] Mon Jan 12 13:06:35 2009
@@ -12,7 +12,7 @@
(function($) {
$.couch = $.couch || {};
- $.fn.extend($.couch, {
+ $.extend($.couch, {
allDbs: function(options) {
options = options || {};
Modified: couchdb/trunk/share/www/style/layout.css
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/style/layout.css?rev=733897&r1=733896&r2=733897&view=diff
==============================================================================
--- couchdb/trunk/share/www/style/layout.css (original)
+++ couchdb/trunk/share/www/style/layout.css Mon Jan 12 13:06:35 2009
@@ -43,7 +43,11 @@
hr { border: 1px solid #999; border-width: 1px 0 0; }
dl dt { font-weight: bold; }
-code, tt { font-family: "DejaVu Sans Mono",Monaco,monospace; }
+code, tt, pre { font-family: "DejaVu Sans Mono",Monaco,monospace; }
+code.key { color: #333; font-weight: bold; }
+code.string { color: #393; }
+code.number, code.boolean { color: #339; }
+code.null { color: #666; }
button { font-size: 100%; -webkit-appearance: square-button; }
input, select, textarea { background: #fff; border: 1px solid;
@@ -321,7 +325,7 @@
/* Documents table */
#documents thead th { width: 50%; }
-#documents tbody.content td { color: #666;
+#documents tbody.content td { color: #999;
font: normal 11px "DejaVu Sans Mono",Monaco,monospace;
}
#documents tbody.content td.key { color: #333; }
@@ -355,19 +359,15 @@
background-image: url(../image/delete-mini.png);
}
#fields tbody.content th b { display: block; padding: 2px; }
-#fields tbody.content td { padding-left: 14px; padding-right: 48px; }
-#fields tbody.content td code { color: #999; display: block; font-size: 11px;
- padding: 2px;
-}
-#fields tbody.content td code.string { color: #393; }
-#fields tbody.content td code.number, #fields tbody.content td code.boolean {
- color: #339;
+#fields tbody.content td { color: #999; padding-left: 14px;
+ padding-right: 48px;
}
+#fields tbody.content td code { display: block; font-size: 11px; padding: 2px; }
#fields tbody.content td dl { margin: 0; padding: 0; }
#fields tbody.content td dt {
background: transparent url(../image/toggle-collapse.gif) 0 3px no-repeat;
- clear: left; cursor: pointer; line-height: 1em; margin-left: -12px;
- padding-left: 14px;
+ clear: left; color: #333; cursor: pointer; line-height: 1em;
+ margin-left: -12px; padding-left: 14px;
}
#fields tbody.content td dd { line-height: 1em; margin: 0;
padding: 0 0 0 1em;
@@ -431,8 +431,8 @@
#fields tbody.content td ul.attachments li button.delete {
background-image: url(../image/delete-mini.png);
}
-#fields tbody.source td code { display: block; overflow: auto;
- white-space: pre-wrap; width: 100%;
+#fields tbody.source td pre { color: #999; font-size: 11px; line-height: 1.6em;
+ margin: 0; overflow: auto; white-space: pre-wrap; width: 100%;
}
/* Test suite */