Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
improved sub application modularization and template rendering layout…
Browse files Browse the repository at this point in the history
… system, updated examples due to changes
  • Loading branch information
kadirpekel committed Jul 3, 2011
1 parent 69680ed commit 2db3c3e
Show file tree
Hide file tree
Showing 31 changed files with 165 additions and 82 deletions.
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -32,7 +32,7 @@ mate.context.highlight = (color, txt) ->
mate.get '/greet/:name', ->
# this is context variable
@greet_msg = "Hello, #{@req.params.name}"
@render 'home.eco'
@render 'home'

# Stream it
mate.io.sockets.on 'connection', (socket) ->
Expand All @@ -42,6 +42,17 @@ mate.io.sockets.on 'connection', (socket) ->
mate.listen 3000
```

``` html
<!-- layout.eco -->
<html>
<head>
</head>
<body>
<%- @include @body %>
</body>
</html>
```

``` html
<!-- main.eco -->

Expand Down
4 changes: 4 additions & 0 deletions examples/coffeekup/views/layout.coffeekup
@@ -0,0 +1,4 @@
html ->
head
body ->
include @body
17 changes: 7 additions & 10 deletions examples/coffeekup/views/main.coffeekup
@@ -1,10 +1,7 @@
html ->
head
body ->
h1 "A cup of coffee demonstration"
div ->
include "nested1"
div ->
include "nested2"
div ->
include "nested3"
h1 "A cup of coffee demonstration"
div ->
include "nested1"
div ->
include "nested2"
div ->
include "nested3"
2 changes: 1 addition & 1 deletion examples/connect/app.coffee
Expand Up @@ -4,6 +4,6 @@ mate.logger()
mate.static(__dirname + '/public')

mate.get '/', ->
@render 'main.eco'
@render 'main'

mate.listen 3000
7 changes: 7 additions & 0 deletions examples/connect/layout.eco
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<%- @include @body %>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/helpers/app.coffee
Expand Up @@ -4,6 +4,6 @@ mate.context.highlight = (msg) ->
"<span style=\"background-color:#ff0\">#{msg}</span>"

mate.get '/', ->
@render 'main.eco'
@render 'main'

mate.listen 3000
7 changes: 7 additions & 0 deletions examples/helpers/layout.eco
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<%- @include @body %>
</body>
</html>
7 changes: 1 addition & 6 deletions examples/layout/app.coffee
@@ -1,12 +1,7 @@
mate = require '../../lib/coffeemate'

# build your own layout structure
mate.context.custom_render = (template_name) ->
@content = template_name
@render 'layout.eco'

mate.get '/', ->
@foo = 'bar'
@custom_render 'main.eco'
@render 'main'

mate.listen 3000
2 changes: 1 addition & 1 deletion examples/layout/layout.eco
Expand Up @@ -2,7 +2,7 @@
<head></head>
<body>
<div>This is HEADER</div>
<div><%- @include @content %></div>
<div><%- @include @body %></div>
<div>This is FOOTER</div>
</body>
</html>
6 changes: 2 additions & 4 deletions examples/sandbox/base/index.coffee
@@ -1,5 +1,3 @@
mate = require('../../../lib/coffeemate').newInstance()
mate = require '../../../lib/coffeemate'

mate.get '/', -> @view 'home'

module.exports = mate
mate.get '/', -> @render 'base/index'
10 changes: 0 additions & 10 deletions examples/sandbox/base/views/layout.eco

This file was deleted.

6 changes: 2 additions & 4 deletions examples/sandbox/comments/index.coffee
@@ -1,5 +1,3 @@
mate = require('../../../lib/coffeemate').newInstance()
mate = require '../../../lib/coffeemate'

mate.get '/', -> @view 'list'

module.exports = mate
mate.get '/', -> @render 'comments/index', 'comment_layout'
1 change: 0 additions & 1 deletion examples/sandbox/comments/views/list.eco

This file was deleted.

6 changes: 0 additions & 6 deletions examples/sandbox/extensions.coffee

This file was deleted.

18 changes: 7 additions & 11 deletions examples/sandbox/index.coffee
@@ -1,19 +1,15 @@
mate = require '../../lib/coffeemate'

# use some of connect middlewares
mate.logger()
mate.static("#{__dirname}/public")

# import extensions
require './extensions'
# import configuration
require './settings'

# import sub applications
mate.use '/base', require './base'
mate.use '/posts', require './posts'
mate.use '/comments', require './comments'
mate.sub '/base', -> require './base'
mate.sub '/posts', -> require './posts'
mate.sub '/comments', -> require './comments'

# redirect root
mate.get '/', -> @redirect '/base'

# start the engines
mate.listen 3000
mate.listen 3000
6 changes: 2 additions & 4 deletions examples/sandbox/posts/index.coffee
@@ -1,5 +1,3 @@
mate = require('../../../lib/coffeemate').newInstance()
mate = require '../../../lib/coffeemate'

mate.get '/', -> @view 'list'

module.exports = mate
mate.get '/', -> @render 'posts/index'
2 changes: 2 additions & 0 deletions examples/sandbox/server.js
@@ -0,0 +1,2 @@
require('coffee-script');
module.exports = require('./index.coffee');
8 changes: 8 additions & 0 deletions examples/sandbox/settings.coffee
@@ -0,0 +1,8 @@
mate = require '../../lib/coffeemate'

mate.options.renderDir = 'templates'
mate.options.renderExt = '.html'

# use some of connect middlewares
mate.logger()
mate.static("#{__dirname}/public")
@@ -1,2 +1,2 @@
<h1>Coffeemate Sandbox</h1>
<a href="/posts">posts</a>
<a href="/posts">posts</a>
18 changes: 18 additions & 0 deletions examples/sandbox/templates/comment_layout.html
@@ -0,0 +1,18 @@
<html>
<head>
<style type="text/css">
body {
background-color: #ff0;
}
</style>
</head>
<body>
<div id="header"><img src="coffeescript.png" alt="coffeescript" /></div>
<hr />
<div id="content">
<%- @include @body %>
</div>
<hr />
<div id="footer"><a href="/" title="home">home</a></div>
</body>
</html>
1 change: 1 addition & 0 deletions examples/sandbox/templates/comments/index.html
@@ -0,0 +1 @@
<h1>Comment List</h1>
13 changes: 13 additions & 0 deletions examples/sandbox/templates/layout.html
@@ -0,0 +1,13 @@
<html>
<head>
</head>
<body>
<div id="header"><img src="coffeescript.png" alt="coffeescript" /></div>
<hr />
<div id="content">
<%- @include @body %>
</div>
<hr />
<div id="footer"><a href="/" title="home">home</a></div>
</body>
</html>
7 changes: 7 additions & 0 deletions examples/simple_auth/layout.eco
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<%- @include @body %>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/templating/app.coffee
Expand Up @@ -2,6 +2,6 @@ mate = require '../../lib/coffeemate'

mate.get '/:page?', ->
@foo = 'bar' # this is a context variable
@render 'main.eco'
@render 'main'

mate.listen 3000
7 changes: 7 additions & 0 deletions examples/templating/layout.eco
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<%- @include @body %>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/templating/main.eco
@@ -1,3 +1,3 @@
<h1>this is main template for path: <%= @req.url %></h1>
<div>This is foo: <%= @foo %></div>
<div><%- @include 'nested.eco' %></div>
<div><%- @include 'nested' %></div>
2 changes: 1 addition & 1 deletion examples/templating/nested.eco
@@ -1,3 +1,3 @@
<h2>this is nested template</h2>
<div>This is foo: <%= @foo %></div>
<div><%- @include 'leaf.eco' %></div>
<div><%- @include 'leaf' %></div>
4 changes: 3 additions & 1 deletion examples/websockets/app.coffee
@@ -1,7 +1,9 @@
mate = require '../../lib/coffeemate.coffee'

mate.options.renderLayout = no

mate.get '/', ->
@render 'main.eco'
@render 'main'

mate.io.sockets.on 'connection', (socket, i=0) ->
setInterval (-> socket.emit 'news', "Breaking news #{i++}"), 500
Expand Down

0 comments on commit 2db3c3e

Please sign in to comment.