change it to !include

This commit is contained in:
Chris Anderson 2009-01-02 01:59:33 -08:00
parent d6088be47f
commit 7644217add
8 changed files with 43 additions and 14 deletions

View file

@ -81,11 +81,11 @@ module CouchRest
(for project global libs). These libraries are only inserted into views which
include the text
//include-lib
// !include lib
or
#include-lib
# !include lib
Couchview is a result of scratching my own itch. I'd be happy to make it more
general, so please contact me at jchris@grabb.it if you'd like to see anything

View file

@ -171,7 +171,7 @@ module CouchRest
def apply_lib(funcs, lib)
funcs.each do |k,v|
next unless v.is_a?(String)
funcs[k] = v.sub(/(\/\/|#)\ ?include-lib/,lib)
funcs[k] = v.sub(/(\/\/|#)\ ?!include lib/,lib)
end
end

View file

@ -1,8 +1,11 @@
function(doc, req) {
// include-lib
// !include lib.templates
// !require lib.helpers.template
respondWith(req, {
html : function() {
var html = template(lib["example.html"], doc);
var html = template(lib.templates.example, doc);
return {body:html}
},
xml : function() {

View file

@ -1,3 +0,0 @@
function aHelperFunction() {
return "help";
};

View 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;
};

View file

@ -2,7 +2,7 @@
// and the list of keys it contains
function(doc) {
// include-lib
// !include lib
var k, keys = []
for (k in doc) keys.push(k);
emit(doc._id, keys);

View file

@ -34,7 +34,7 @@ describe "couchapp" do
end
it "should create a forms and libs" do
Dir["#{@fixdir}/my-app/forms/*"].select{|x|x =~ /example-form.js/}.length.should == 1
Dir["#{@fixdir}/my-app/lib/templates/*"].select{|x|x =~ /example-template.html/}.length.should == 1
Dir["#{@fixdir}/my-app/lib/templates/*"].select{|x|x =~ /example.html/}.length.should == 1
end
end
@ -55,10 +55,7 @@ describe "couchapp" do
@doc['views']['example']['map'].should match(/function/)
end
it "should create the view libs" do
@doc['views']['example']['map'].should match(/aHelperFunction/)
end
it "should create specific view libs" do
@doc['views']['example']['map'].should match(/aHelperFunction/)
@doc['views']['example']['map'].should match(/Resig/)
end
it "should create view for all the views" do
`mkdir -p #{@fixdir}/my-app/views/more`