Permalink
Browse files

added specs for alternate templating support

  • Loading branch information...
1 parent 4881984 commit b85b2df48741f66f19bf97dd2020c8309fc27342 @dantebronto committed Jan 23, 2011
View
@@ -17,17 +17,20 @@ Picard.get('/db', comments) // simulate a database result
Picard.get('/async', function(env){
- var local = require('http').createClient(9900, 'localhost')
- var request = local.request('GET', '/db', {'host': 'localhost'})
- var body = []
+ var local = require('http').createClient(9900, 'localhost'),
+ request = local.request('GET', '/db'),
+ body = []
- request.addListener('response', function (response) {
- response.addListener('data', function (chunk) {
- body.push(chunk)
- })
- response.addListener('end', function(){
- env.onScreen({ body: body.join('') }) // will be comments from above
- })
+ request.on('response', function (response) {
+
+ response.
+ on('data', function (chunk) {
+ body.push(chunk)
+ }).
+ on('end', function(){
+ env.onScreen({ body: body.join('') }) // will be comments from above
+ })
+
}).end()
})
@@ -0,0 +1,15 @@
+var Picard = require('../../lib/picard').start()
+var _ = require('underscore') // assumes underscore.js is require-able
+
+Picard.template.ext = 'html.ejs' // default is 'haml'
+Picard.template.compile = _.template // template compilation function, see underscore.js docs: http://documentcloud.github.com/underscore/#template
+
+Picard.get('/alternate_template', function(){
+ return {
+ layout: 'application',
+ template: 'custom',
+ name: 'Jean-Luc Picard',
+ people: ['Riker', 'Crusher', 'Data'],
+ _: _ // allow use of underscore in views
+ }
+})
@@ -0,0 +1,3 @@
+<h1>This is the layout!</h1>
+
+<%= yield() %>
@@ -0,0 +1,7 @@
+<p>Hello: <%= name %></p>
+
+<ul>
+ <% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>
+</ul>
+
+<%= partial('my_partial', { rank: "Cap'n" }) %>
@@ -0,0 +1 @@
+This is partial content, <%= rank %>
View
@@ -59,4 +59,5 @@ runSpecsFor('haml', function(){
runSpecsFor('misc', function(){
runSpecsFor('routing', function(){
runSpecsFor('async', function(){
-})})})})})})})
+runSpecsFor('templating', function(){
+})})})})})})})})
@@ -1,4 +1,5 @@
describe('cookies', function(){
+
it('should read from a set cookie', function(){
testReq('GET', '/cookie', function(_, headers, body){
expect(headers['set-cookie']).toMatch('hobby=literature')
@@ -16,4 +17,5 @@ describe('cookies', function(){
})
asyncSpecWait()
})
+
})
@@ -0,0 +1,37 @@
+describe('alternate templating engines', function(){
+
+ it('should allow rendering layouts', function(){
+ testReq('GET', '/alternate_template', function(_, _, body){
+ expect(body).toMatch('<h1>This is the layout!</h1>')
+ asyncSpecDone()
+ })
+ asyncSpecWait()
+ })
+
+ it('should allow normal view scope merging', function(){
+ testReq('GET', '/alternate_template', function(_, _, body){
+ expect(body).toMatch('<p>Hello: Jean-Luc Picard</p>')
+ asyncSpecDone()
+ })
+ asyncSpecWait()
+ })
+
+ it('should allow partials with scope', function(){
+ testReq('GET', '/alternate_template', function(_, _, body){
+ expect(body).toMatch("This is partial content, Cap'n")
+ asyncSpecDone()
+ })
+ asyncSpecWait()
+ })
+
+ it('should allow functions from underscore', function(){
+ testReq('GET', '/alternate_template', function(_, _, body){
+ expect(body).toMatch("Riker")
+ expect(body).toMatch("Crusher")
+ expect(body).toMatch("Data")
+ asyncSpecDone()
+ })
+ asyncSpecWait()
+ })
+
+})

0 comments on commit b85b2df

Please sign in to comment.