moved app template
This commit is contained in:
parent
9faa9daaca
commit
5d3e684c6a
11 changed files with 4 additions and 3 deletions
26
lib/couchrest/helper/app-template/_attachments/index.html
Normal file
26
lib/couchrest/helper/app-template/_attachments/index.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Generated CouchApp</title>
|
||||
<link rel="stylesheet" href="screen.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Generated CouchApp</h1>
|
||||
<ul id="view"></ul>
|
||||
</body>
|
||||
<script src="/_utils/script/json2.js"></script>
|
||||
<script src="/_utils/script/jquery.js?1.2.6"></script>
|
||||
<script src="/_utils/script/jquery.couch.js?0.8.0"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$(function() {
|
||||
var dbname = document.location.href.split('/')[3];
|
||||
var design = unescape(document.location.href).split('/')[5];
|
||||
var DB = $.couch.db(dbname);
|
||||
DB.view(design+"/example",{success: function(json) {
|
||||
$("#view").html(json.rows.map(function(row) {
|
||||
return '<li>'+row.key+'</li>';
|
||||
}).join(''));
|
||||
}});
|
||||
});
|
||||
</script>
|
||||
</html>
|
11
lib/couchrest/helper/app-template/foo/bar.txt
Normal file
11
lib/couchrest/helper/app-template/foo/bar.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
Couchapp will create a field on your document corresponding to any directories you make within the application directory, with the text of any files found as key/value pairs.
|
||||
|
||||
Also, any files that end in .json will be treated as json rather than text, and put in the corresponding field. Also note that file.json, file.js, or file.txt will be stored under the "file" key, so don't make collisions in the filesystem unless you want unpredictable results.
|
||||
|
||||
Of course you know that the views directory will be treated specially and -map and -reduce files will be mapped to the map and reduce functions. And the _attachments directory will be treated strangely as well.
|
||||
|
||||
doc.json is a special case, it is treated as json and its keys are applied to the document root; eg it does not result in a "doc" field on your design document. If you need a doc field on the design document, you'll have to define it with a doc.json like so: {"doc":"value for doc field"}
|
||||
|
||||
ps: each design document only has one language key: it will be set based on the file extensions in the views directory. CouchDB defaults to Javascript, so that's what you'll get if you don't define any views. You can override it with the doc.json file, but don't say we didn't warn you.
|
||||
|
||||
Oh yeah it's recommended that you delete this file.
|
17
lib/couchrest/helper/app-template/forms/example-form.js
Normal file
17
lib/couchrest/helper/app-template/forms/example-form.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
function(doc, req) {
|
||||
// !include lib.templates
|
||||
|
||||
// !require lib.helpers.template
|
||||
|
||||
respondWith(req, {
|
||||
html : function() {
|
||||
var html = template(lib.templates.example, doc);
|
||||
return {body:html}
|
||||
},
|
||||
xml : function() {
|
||||
return {
|
||||
body : <xml><node value={doc.title}/></xml>
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
1
lib/couchrest/helper/app-template/lib/helpers/math.js
Normal file
1
lib/couchrest/helper/app-template/lib/helpers/math.js
Normal file
|
@ -0,0 +1 @@
|
|||
function stddev() {};
|
32
lib/couchrest/helper/app-template/lib/helpers/template.js
Normal file
32
lib/couchrest/helper/app-template/lib/helpers/template.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Simple JavaScript Templating
|
||||
// John Resig - http://ejohn.org/ - MIT Licensed
|
||||
var cache = {};
|
||||
|
||||
function template(str, data){
|
||||
// Figure out if we're getting a template, or if we need to
|
||||
// load the template - and be sure to cache the result.
|
||||
var fn = cache[str] ||
|
||||
|
||||
// Generate a reusable function that will serve as a template
|
||||
// generator (and which will be cached).
|
||||
new Function("obj",
|
||||
"var p=[],print=function(){p.push.apply(p,arguments);};" +
|
||||
|
||||
// Introduce the data as local variables using with(){}
|
||||
"with(obj){p.push('" +
|
||||
|
||||
// Convert the template into pure JavaScript
|
||||
str
|
||||
.replace(/[\r\t\n]/g, " ")
|
||||
.replace(/'(?=[^%]*%>)/g,"\t")
|
||||
.split("'").join("\\'")
|
||||
.split("\t").join("'")
|
||||
.replace(/<%=(.+?)%>/g, "',$1,'")
|
||||
.split("<%").join("');")
|
||||
.split("%>").join("p.push('")
|
||||
+ "');}return p.join('');");
|
||||
cache[str] = fn;
|
||||
|
||||
// Provide some basic currying to the user
|
||||
return data ? fn( data ) : fn;
|
||||
};
|
26
lib/couchrest/helper/app-template/lib/templates/example.html
Normal file
26
lib/couchrest/helper/app-template/lib/templates/example.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Generated CouchApp Form Template</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h2><a href="index.html">Back to index</a></h2>
|
||||
</div>
|
||||
<div id="content">
|
||||
<h1><% doc.title %></h1>
|
||||
</div>
|
||||
</body>
|
||||
<script src="/_utils/script/json2.js"></script>
|
||||
<script src="/_utils/script/jquery.js?1.2.6"></script>
|
||||
<script src="/_utils/script/jquery.couch.js?0.8.0"></script>
|
||||
<script src="jquery.couchapp.js"></script>
|
||||
<script src="blog.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$.CouchApp(function(app) {
|
||||
var docid = document.location.pathname.split('/').pop();
|
||||
// hey you could run a query to load more information from views
|
||||
});
|
||||
</script>
|
||||
<script src="showdown.js"></script>
|
||||
</html>
|
9
lib/couchrest/helper/app-template/views/example/map.js
Normal file
9
lib/couchrest/helper/app-template/views/example/map.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
// an example map function, emits the doc id
|
||||
// and the list of keys it contains
|
||||
// !require lib.helpers.math
|
||||
|
||||
function(doc) {
|
||||
var k, keys = []
|
||||
for (k in doc) keys.push(k);
|
||||
emit(doc._id, keys);
|
||||
};
|
10
lib/couchrest/helper/app-template/views/example/reduce.js
Normal file
10
lib/couchrest/helper/app-template/views/example/reduce.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
// example reduce function to count the
|
||||
// number of rows in a given key range.
|
||||
|
||||
function(keys, values, rereduce) {
|
||||
if (rereduce) {
|
||||
return sum(values);
|
||||
} else {
|
||||
return values.length;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue