Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Corrected `eco` example (#52)

  • Loading branch information...
commit aff203ee7b89425f317be457dc8ffdbc0131e81e 1 parent da09f5b
@shimaore shimaore authored
Showing with 51 additions and 0 deletions.
  1. +2 −0  docs/crashcourse.md
  2. +49 −0 tests/documentation.coffee
View
2  docs/crashcourse.md
@@ -140,6 +140,8 @@ Another is that you can define inline views that `@render` "sees" as if they wer
Note that zappa comes with a default templating engine, [CoffeeCup](https://github.com/gradus/coffeecup), and you don't have to setup anything to use it. You can also easily use other engines by specifying the file extension or the `'view engine'` setting; it's just express. Well, express + inline views support:
+ @use 'partials'
+ @app.engine 'eco', require('consolidate').eco
@set 'view engine': 'eco'
@get '/': -> @render index: {foo: 'bar', title: 'Eco template'}
View
49 tests/documentation.coffee
@@ -125,3 +125,52 @@ port = 16000
t.equal 2, res.body, 'sears'
# at line 122 of crashcourse.md
+
+ crashcourse_13: (t) ->
+ t.expect 1
+ t.wait 3000
+
+ zapp = zappa port++, ->
+ @use 'partials'
+ @app.engine 'eco', require('consolidate').eco
+ @set 'view engine': 'eco'
+
+ @get '/': -> @render index: {foo: 'bar', title: 'Eco template'}
+ @get '/jade': -> @render 'index.jade': {foo: 'bar', title: 'Jade template'}
+
+ @view index: '''
+ <h1><%= @title %></h1>
+ <p><%= @foo %></p>
+ '''
+
+ @view layout: '''
+ <!DOCTYPE html>
+ <html>
+ <head><title><%= @title %></title></head>
+ <body><%- @body %></body>
+ </html>
+ '''
+
+ @view 'index.jade': '''
+ h1= title
+ p= foo
+ '''
+
+ @view 'layout.jade': '''
+ !!! 5
+ html
+ head
+ title= title
+ body!= body
+ '''
+
+ c = t.client(zapp.server)
+ c.get '/', (err,res) ->
+ t.equal 1, res.body, '''
+ <!DOCTYPE html>
+ <html>
+ <head><title>Eco template</title></head>
+ <body><h1>Eco template</h1>
+ <p>bar</p></body>
+ </html>
+ '''
Please sign in to comment.
Something went wrong with that request. Please try again.