initial commit

This commit is contained in:
maxogden 2011-03-08 19:48:57 -08:00
commit 5e2a36bda5
16 changed files with 818 additions and 0 deletions

7
.couchappignore Normal file
View File

@ -0,0 +1,7 @@
[
// filenames matching these regexps will not be pushed to the database
// uncomment to activate; separate entries with ","
// ".*~$"
// ".*\\.swp$"
// ".*\\.bak$"
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -0,0 +1,116 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CouchDB Data Import/Export</title>
<link rel="stylesheet" href="style/reset.css" media="screen">
<link rel="stylesheet" href="style/demo.css" media="screen">
<link rel="stylesheet" href="style/css3buttons.css" media="screen">
<script type="text/javascript" src="script/jquery-1.5.min.js"></script>
<script type="text/javascript" src="script/jquery.mustache.js"></script>
<script type="text/javascript">
$(function() {
var name,
baseURL = "_rewrite/",
vhost = false;
if (document.location.pathname.indexOf("_design") == -1) {
// in a vhost
vhost = true;
baseURL = "";
}
/** uses $.mustache to render a template out to a target DOM
* template == camelcase ID (minus the word Template) of the DOM object containg your mustache template
* target == ID of the DOM node you wish to render the template into
* data == data object to pass into the mustache template when rendering
*/
function render(template, target, data) {
if (!data) var data = {};
$( "#" + target ).html( $.mustache( $.trim( $( "#" + template + "Template" ).text() ), data ) );
}
function gotDb(dbInfo) {
render('db', 'stats', dbInfo);
var data = {
"db_name": dbInfo.db_name,
"host": window.location.host
}
if(vhost) data.db_name = 'db';
render('url', 'url', data);
}
$.getJSON(baseURL + 'db', gotDb);
$('.csv').click(function(e) {
function gotHeaders(headers) {
window.location.href = baseURL + 'csv?headers=' + headers;
}
$.get(baseURL + 'headers', gotHeaders);
e.preventDefault();
})
})
</script>
</head>
<body>
<div class="container">
<header>
<h1 id="title">CouchDB Data Import/Export</h1>
</header>
<div id="main">
<section class="odd">
<h3>DB Stats</h3>
<p class="notice" id="stats"></p>
<article class="example">
<p>
<h3>Actions</h3>
</p>
<p>
<a href="javascript:void(false)" class="button csv"><span class="downarrow icon"></span>Download DB as CSV</a>
</p>
</article>
<h3>Uploading</h3>
<p>You can bulk upload an array of JSON objects representing your documents to a remote server via HTTP POST. Make sure that they are formatted one document per line:</p>
<p>
<pre><code> {
"docs": [
{"name": "barry", "type": "human"},
{"name": "carl", "type": "human"},
{"name": "ethel", "type": "robot"}
]
}</code></pre>
</p>
<p>POST to the this URL:</p>
<pre class="code" id="url"></pre>
</section>
</div>
<footer>
<a href='https://github.com/maxogden/removalist'>Fork this project on Github</a>. The <a href="http://github.com/michenriksen/css3buttons">pretty CSS3 Buttons</a> were created by <a href="http://michaelhenriksen.dk" title="Website of Michael Henriksen">Michael Henriksen</a>
</footer>
</div>
<script type='text/mustache' id="dbTemplate">
name: {{db_name}}, # docs: {{doc_count}}, disk size: {{disk_size}}
</script>
<script type='text/mustache' id="urlTemplate">
http://{{host}}/{{db_name}}/_bulk_docs
</script>
</body>
</html>

16
_attachments/script/jquery-1.5.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,346 @@
/*
Shameless port of a shameless port
@defunkt => @janl => @aq
See http://github.com/defunkt/mustache for more info.
*/
;(function($) {
/*
mustache.js Logic-less templates in JavaScript
See http://mustache.github.com/ for more info.
*/
var Mustache = function() {
var Renderer = function() {};
Renderer.prototype = {
otag: "{{",
ctag: "}}",
pragmas: {},
buffer: [],
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
},
context: {},
render: function(template, context, partials, in_recursion) {
// reset buffer & set context
if(!in_recursion) {
this.context = context;
this.buffer = []; // TODO: make this non-lazy
}
// fail fast
if(!this.includes("", template)) {
if(in_recursion) {
return template;
} else {
this.send(template);
return;
}
}
template = this.render_pragmas(template);
var html = this.render_section(template, context, partials);
if(in_recursion) {
return this.render_tags(html, context, partials, in_recursion);
}
this.render_tags(html, context, partials, in_recursion);
},
/*
Sends parsed lines
*/
send: function(line) {
if(line != "") {
this.buffer.push(line);
}
},
/*
Looks for %PRAGMAS
*/
render_pragmas: function(template) {
// no pragmas
if(!this.includes("%", template)) {
return template;
}
var that = this;
var regex = new RegExp(this.otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" +
this.ctag);
return template.replace(regex, function(match, pragma, options) {
if(!that.pragmas_implemented[pragma]) {
throw({message:
"This implementation of mustache doesn't understand the '" +
pragma + "' pragma"});
}
that.pragmas[pragma] = {};
if(options) {
var opts = options.split("=");
that.pragmas[pragma][opts[0]] = opts[1];
}
return "";
// ignore unknown pragmas silently
});
},
/*
Tries to find a partial in the curent scope and render it
*/
render_partial: function(name, context, partials) {
name = this.trim(name);
if(!partials || partials[name] === undefined) {
throw({message: "unknown_partial '" + name + "'"});
}
if(typeof(context[name]) != "object") {
return this.render(partials[name], context, partials, true);
}
return this.render(partials[name], context[name], partials, true);
},
/*
Renders inverted (^) and normal (#) sections
*/
render_section: function(template, context, partials) {
if(!this.includes("#", template) && !this.includes("^", template)) {
return template;
}
var that = this;
// CSW - Added "+?" so it finds the tighest bound, not the widest
var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
"\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag +
"\\s*", "mg");
// for each {{#foo}}{{/foo}} section do...
return template.replace(regex, function(match, type, name, content) {
var value = that.find(name, context);
if(type == "^") { // inverted section
if(!value || that.is_array(value) && value.length === 0) {
// false or empty list, render it
return that.render(content, context, partials, true);
} else {
return "";
}
} else if(type == "#") { // normal section
if(that.is_array(value)) { // Enumerable, Let's loop!
return that.map(value, function(row) {
return that.render(content, that.create_context(row),
partials, true);
}).join("");
} else if(that.is_object(value)) { // Object, Use it as subcontext!
return that.render(content, that.create_context(value),
partials, true);
} else if(typeof value === "function") {
// higher order section
return value.call(context, content, function(text) {
return that.render(text, context, partials, true);
});
} else if(value) { // boolean section
return that.render(content, context, partials, true);
} else {
return "";
}
}
});
},
/*
Replace {{foo}} and friends with values from our view
*/
render_tags: function(template, context, partials, in_recursion) {
// tit for tat
var that = this;
var new_regex = function() {
return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" +
that.ctag + "+", "g");
};
var regex = new_regex();
var tag_replace_callback = function(match, operator, name) {
switch(operator) {
case "!": // ignore comments
return "";
case "=": // set new delimiters, rebuild the replace regexp
that.set_delimiters(name);
regex = new_regex();
return "";
case ">": // render partial
return that.render_partial(name, context, partials);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}
};
var lines = template.split("\n");
for(var i = 0; i < lines.length; i++) {
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
if(!in_recursion) {
this.send(lines[i]);
}
}
if(in_recursion) {
return lines.join("\n");
}
},
set_delimiters: function(delimiters) {
var dels = delimiters.split(" ");
this.otag = this.escape_regex(dels[0]);
this.ctag = this.escape_regex(dels[1]);
},
escape_regex: function(text) {
// thank you Simon Willison
if(!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
},
/*
find `name` in current `context`. That is find me a value
from the view object
*/
find: function(name, context) {
name = this.trim(name);
// Checks whether a value is thruthy or false or 0
function is_kinda_truthy(bool) {
return bool === false || bool === 0 || bool;
}
var value;
if(is_kinda_truthy(context[name])) {
value = context[name];
} else if(is_kinda_truthy(this.context[name])) {
value = this.context[name];
}
if(typeof value === "function") {
return value.apply(context);
}
if(value !== undefined) {
return value;
}
// silently ignore unkown variables
return "";
},
// Utility methods
/* includes tag */
includes: function(needle, haystack) {
return haystack.indexOf(this.otag + needle) != -1;
},
/*
Does away with nasty characters
*/
escape: function(s) {
s = String(s === null ? "" : s);
return s.replace(/&(?!\w+;)|["<>\\]/g, function(s) {
switch(s) {
case "&": return "&amp;";
case "\\": return "\\\\";
case '"': return '\"';
case "<": return "&lt;";
case ">": return "&gt;";
default: return s;
}
});
},
// by @langalex, support for arrays of strings
create_context: function(_context) {
if(this.is_object(_context)) {
return _context;
} else {
var iterator = ".";
if(this.pragmas["IMPLICIT-ITERATOR"]) {
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
}
var ctx = {};
ctx[iterator] = _context;
return ctx;
}
},
is_object: function(a) {
return a && typeof a == "object";
},
is_array: function(a) {
return Object.prototype.toString.call(a) === '[object Array]';
},
/*
Gets rid of leading and trailing whitespace
*/
trim: function(s) {
return s.replace(/^\s*|\s*$/g, "");
},
/*
Why, why, why? Because IE. Cry, cry cry.
*/
map: function(array, fn) {
if (typeof array.map == "function") {
return array.map(fn);
} else {
var r = [];
var l = array.length;
for(var i = 0; i < l; i++) {
r.push(fn(array[i]));
}
return r;
}
}
};
return({
name: "mustache.js",
version: "0.3.1-dev",
/*
Turns a template and view into HTML
*/
to_html: function(template, view, partials, send_fun) {
var renderer = new Renderer();
if(send_fun) {
renderer.send = send_fun;
}
renderer.render(template, view, partials);
if(!send_fun) {
return renderer.buffer.join("\n");
}
},
escape : function(text) {
return new Renderer().escape(text);
}
});
}();
$.mustache = function(template, view, partials) {
return Mustache.to_html(template, view, partials);
};
$.mustache.escape = function(text) {
return Mustache.escape(text);
};
})(jQuery);

View File

@ -0,0 +1,79 @@
a.button { display: inline-block; padding: 3px 5px 3px 5px; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 12px; color: #3C3C3D; text-shadow: 1px 1px 0 #FFFFFF; background: #ECECEC url('../images/css3buttons_backgrounds.png') 0 0 no-repeat; white-space: nowrap; overflow: visible; cursor: pointer; text-decoration: none; border: 1px solid #CACACA; -webkit-border-radius: 2px; -moz-border-radius: 2px; -webkit-background-clip: padding-box; border-radius: 2px; outline: none; position: relative; zoom: 1; *display: inline; }
a.button.primary { font-weight: bold }
a.button:hover { color: #FFFFFF; border-color: #388AD4; text-decoration: none; text-shadow: -1px -1px 0 rgba(0,0,0,0.3); background-position: 0 -40px; background-color: #2D7DC5; }
a.button:active,
a.button.active { background-position: 0 -81px; border-color: #347BBA; background-color: #0F5EA2; color: #FFFFFF; text-shadow: none; }
a.button:active { top: 1px }
a.button.negative:hover { color: #FFFFFF; background-position: 0 -121px; background-color: #D84743; border-color: #911D1B; }
a.button.negative:active,
a.button.negative.active { background-position: 0 -161px; background-color: #A5211E; border-color: #911D1B; }
a.button.pill { -webkit-border-radius: 19px; -moz-border-radius: 19px; border-radius: 19px; padding: 2px 10px 2px 10px; }
a.button.left { -webkit-border-bottom-right-radius: 0px; -webkit-border-top-right-radius: 0px; -moz-border-radius-bottomright: 0px; -moz-border-radius-topright: 0px; border-bottom-right-radius: 0px; border-top-right-radius: 0px; margin-right: 0px; }
a.button.middle { margin-right: 0px; margin-left: 0px; -webkit-border-radius: 0px; -moz-border-radius: 0px; border-radius: 0px; border-right: none; border-left: none; }
a.button.right { -webkit-border-bottom-left-radius: 0px; -webkit-border-top-left-radius: 0px; -moz-border-radius-bottomleft: 0px; -moz-border-radius-topleft: 0px; border-top-left-radius: 0px; border-bottom-left-radius: 0px; margin-left: 0px; }
a.button.left:active,
a.button.middle:active,
a.button.right:active { top: 0px }
a.button.big { font-size: 16px; padding-left: 17px; padding-right: 17px; }
a.button span.icon { display: inline-block; width: 14px; height: 12px; margin: auto 7px auto auto; position: relative; top: 2px; background-image: url('../images/css3buttons_icons.png'); background-repeat: no-repeat; }
a.big.button span.icon { top: 0px }
a.button span.icon.book { background-position: 0 0 }
a.button:hover span.icon.book { background-position: 0 -15px }
a.button span.icon.calendar { background-position: 0 -30px }
a.button:hover span.icon.calendar { background-position: 0 -45px }
a.button span.icon.chat { background-position: 0 -60px }
a.button:hover span.icon.chat { background-position: 0 -75px }
a.button span.icon.check { background-position: 0 -90px }
a.button:hover span.icon.check { background-position: 0 -103px }
a.button span.icon.clock { background-position: 0 -116px }
a.button:hover span.icon.clock { background-position: 0 -131px }
a.button span.icon.cog { background-position: 0 -146px }
a.button:hover span.icon.cog { background-position: 0 -161px }
a.button span.icon.comment { background-position: 0 -176px }
a.button:hover span.icon.comment { background-position: 0 -190px }
a.button span.icon.cross { background-position: 0 -204px }
a.button:hover span.icon.cross { background-position: 0 -219px }
a.button span.icon.downarrow { background-position: 0 -234px }
a.button:hover span.icon.downarrow { background-position: 0 -249px }
a.button span.icon.fork { background-position: 0 -264px }
a.button:hover span.icon.fork { background-position: 0 -279px }
a.button span.icon.heart { background-position: 0 -294px }
a.button:hover span.icon.heart { background-position: 0 -308px }
a.button span.icon.home { background-position: 0 -322px }
a.button:hover span.icon.home { background-position: 0 -337px }
a.button span.icon.key { background-position: 0 -352px }
a.button:hover span.icon.key { background-position: 0 -367px }
a.button span.icon.leftarrow { background-position: 0 -382px }
a.button:hover span.icon.leftarrow { background-position: 0 -397px }
a.button span.icon.lock { background-position: 0 -412px }
a.button:hover span.icon.lock { background-position: 0 -427px }
a.button span.icon.loop { background-position: 0 -442px }
a.button:hover span.icon.loop { background-position: 0 -457px }
a.button span.icon.magnifier { background-position: 0 -472px }
a.button:hover span.icon.magnifier { background-position: 0 -487px }
a.button span.icon.mail { background-position: 0 -502px }
a.button:hover span.icon.mail { background-position: 0 -514px }
a.button span.icon.move { background-position: 0 -526px }
a.button:hover span.icon.move { background-position: 0 -541px }
a.button span.icon.pen { background-position: 0 -556px }
a.button:hover span.icon.pen { background-position: 0 -571px }
a.button span.icon.pin { background-position: 0 -586px }
a.button:hover span.icon.pin { background-position: 0 -601px }
a.button span.icon.plus { background-position: 0 -616px }
a.button:hover span.icon.plus { background-position: 0 -631px }
a.button span.icon.reload { background-position: 0 -646px }
a.button:hover span.icon.reload { background-position: 0 -660px }
a.button span.icon.rightarrow { background-position: 0 -674px }
a.button:hover span.icon.rightarrow { background-position: 0 -689px }
a.button span.icon.rss { background-position: 0 -704px }
a.button:hover span.icon.rss { background-position: 0 -719px }
a.button span.icon.tag { background-position: 0 -734px }
a.button:hover span.icon.tag { background-position: 0 -749px }
a.button span.icon.trash { background-position: 0 -764px }
a.button:hover span.icon.trash { background-position: 0 -779px }
a.button span.icon.unlock { background-position: 0 -794px }
a.button:hover span.icon.unlock { background-position: 0 -809px }
a.button span.icon.uparrow { background-position: 0 -824px }
a.button:hover span.icon.uparrow { background-position: 0 -839px }
a.button span.icon.user { background-position: 0 -854px }
a.button:hover span.icon.user { background-position: 0 -869px }

View File

@ -0,0 +1,30 @@
/**
* This is styling for the demo page and is not necessary to include in your projects
*/
body { font-family: Helvetica, Arial, sans-serif; line-height: 1.5em; font-size: 14px; color: #444; background-color: #D5E9F6; }
h1#title { font-size: 37px; margin-bottom: 50px; color: #666; }
h2 { font-size: 21px; margin-bottom: 20px; }
h3 { font-size: 16px }
p { margin-bottom: 20px }
section { margin-bottom: 20px; padding: 10px; }
section.even { background-color: #EEE; -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; }
article.example { margin: 20px 0px 20px 0px; padding: 10px 0px 10px 0px; border-top: 1px dotted #CCCCCC; border-bottom: 1px dotted #CCCCCC; }
footer { font-size: 11px; color: #666; text-align: center; margin-top: 20px; }
footer a { color: #666 }
a { color: #980905 }
em { font-style: italic }
ul,
ol { margin: 20px auto 20px auto; padding-left: 30px; }
table { margin: 20px auto 20px auto }
th { font-weight: bold }
th,
td { padding: 5px }
blockquote { margin: 20px 0px 20px 0px }
.container { margin: 50px auto 100px auto; width: 750px; }
#main { padding: 10px; background-color: #FFFFFF; -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; }
code,
blockquote,
.code { font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif }
.code { color: #d1d1d1; background-color: #3F3F3F; margin: 0px 0px 20px 0px; padding: 5px; font-size: 13px; -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; }
.notice { background-color: #FFF9D8; margin-top: 20px; padding: 10px; -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; }
.ribbon { position: absolute; top: 0; right: 0; border: 0; }

View File

@ -0,0 +1,67 @@
/* --------------------------------------------------------------
reset.css
* Resets default browser CSS.
-------------------------------------------------------------- */
html {
margin:0;
padding:0;
border:0;
}
body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, code,
del, dfn, em, img, q, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, dialog, figure, footer, header,
hgroup, nav, section {
margin: 0;
padding: 0;
border: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
/* This helps to make newer HTML5 elements behave like DIVs in older browers */
article, aside, dialog, figure, footer, header,
hgroup, nav, section {
display:block;
}
/* Line-height should always be unitless! */
body {
line-height: 1.5;
background: white;
}
/* Tables still need 'cellspacing="0"' in the markup. */
table {
border-collapse: separate;
border-spacing: 0;
}
/* float:none prevents the span-x classes from breaking table-cell display */
caption, th, td {
text-align: left;
font-weight: normal;
float:none !important;
}
table, th, td {
vertical-align: middle;
}
/* Remove possible quote marks (") from <q>, <blockquote>. */
blockquote:before, blockquote:after, q:before, q:after { content: ''; }
blockquote, q { quotes: "" ""; }
/* Remove annoying border on linked images. */
a img { border: none; }
/* Remember to define your own focus styles! */
:focus { outline: 0; }

33
lists/csv.js Normal file
View File

@ -0,0 +1,33 @@
/**
* Generates a CSV from all the rows in the view.
*
* Takes in a url encoded array of headers as an argument. You can
* generate this by querying /_list/urlencode/headers. Pass it in
* as the headers get parameter, e.g.: ?headers=%5B%22_id%22%2C%22_rev%5D
*
* @author Max Ogden
*/
function(head, req) {
if ('headers' in req.query) {
var headers = eval(unescape(req.query.headers.split(',')));
var row, sep = '\n', headerSent = false, startedOutput = false;
start({"headers":{"Content-Type" : "text/x-csv"}});
send(headers.join(',') + "\n");
while (row = getRow()) {
for (var header in headers) {
if (row.value[headers[header]]) {
if (startedOutput) send(",");
send("\"" + row.value[headers[header]] + "\"");
} else {
if (startedOutput) send(",");
}
startedOutput = true;
}
startedOutput = false;
send('\n');
}
} else {
send("You must pass in the urlencoded headers you wish to build the CSV from. Query /_list/urlencode/headers");
}
};

20
lists/urlencode.js Normal file
View File

@ -0,0 +1,20 @@
/**
* Returns the urlencoded version of the view value
*
* @author Max Ogden
*/
function(head, req) {
// Send the same Content-Type as CouchDB would
if (req.headers.Accept.indexOf('application/json')!=-1)
start({"headers":{"Content-Type" : "application/json"}});
else
start({"headers":{"Content-Type" : "text/plain"}});
if ('callback' in req.query) send(req.query['callback'] + "(");
while (row = getRow()) {
send(escape(JSON.stringify(row.value)));
}
if ('callback' in req.query) send(")");
};

25
readme.md Normal file
View File

@ -0,0 +1,25 @@
# Removalist
A [CouchApp](http://couchapp.org) that lets you export and import data into CouchDB.
## Features
* CSV export your entire database for integration with [Google Refine](http://code.google.com/p/google-refine/)
## Installation
### Quick install
* [Get a couch](http://couchone.com/get), make a database and put some data into it.
* Copy these utilities to the new db:
curl -X POST http://user:pass@YOURCOUCH/\_replicate -d '{"source":"http://max.couchone.com/apps","target":"YOURDB", "doc\_ids":["_design/removalist"]}' -H "Content-type: application/json"
### In-depth install
You'll have to get yourself a couch. The easiest way is from [the instructions on this page](http://couchone.com/get). Once it's going, open up `http://YOURCOUCH/_utils` and create a new database to store your data.
You can either replicate the couchapp from my couch [max.couchone.com/apps/_design/removalist](http://max.couchone.com/apps/_design/removalist) (quickest option) or, if you want to hack on the removalist source code first, you'll need to install the [CouchApp command line utility](http://couchapp.org/page/installing) and check out this repo.
If you want to hack on removalist, once you have the couchapp utility working, <code>git clone</code> this repo and go into this folder and execute <code>couchapp init</code>. To upload removalist into your couch just run <code>couchapp push http://YOURCOUCH/DATABASENAME</code>. Otherwise see the Quick install section above.
![screenshot](http://i.imgur.com/ts6T6.png)

38
rewrites.json Normal file
View File

@ -0,0 +1,38 @@
[
{
"to": "style/*",
"from": "style/*"
},
{
"to": "script/*",
"from": "script/*"
},
{
"to": "pages/*",
"from": "pages/*"
},
{
"to": "images/*",
"from": "images/*"
},
{
"to": "pages/index.html",
"from": ""
},
{
"to": "_list/csv/all",
"from": "*.csv"
},
{
"to": "_list/urlencode/headers",
"from": "headers"
},
{
"to": "../..",
"from": "db"
},
{
"to": "../../*",
"from": "db/*"
}
]

7
views/all/map.js Normal file
View File

@ -0,0 +1,7 @@
/**
* A simple map function mocking _all, but allows usage with lists etc.
*
*/
function(doc) {
emit(doc.id, doc);
}

12
views/headers/map.js Normal file
View File

@ -0,0 +1,12 @@
/**
* Returns an array of all of the keys in the document.
*
* @author Max Ogden
*/
function(doc) {
var keys = [];
for (var key in doc) {
keys.push(key);
}
emit(doc, keys);
}

22
views/headers/reduce.js Normal file
View File

@ -0,0 +1,22 @@
/**
* Reduces the passed in view headers to a list of unique object key attributes
*
* @author Max Ogden
*/
function(keys, values, rereduce) {
function include(arr, obj) {
return (arr.indexOf(obj) != -1);
}
var headers = [];
for (var doc in values) {
for (var header in values[doc]) {
if(!include(headers, values[doc][header])) {
headers.push(values[doc][header]);
}
}
}
return headers;
}