Skip to content

Commit

Permalink
Synchronous template loading. Performance optimization. Renaming 'par…
Browse files Browse the repository at this point in the history
…tial' to 'include'. Improving embedded CoffeeScript support.
  • Loading branch information
baryshev committed Sep 23, 2012
1 parent 0e82766 commit 91dbddb
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 299 deletions.
25 changes: 10 additions & 15 deletions README.md
Expand Up @@ -21,7 +21,7 @@ CoffeeScript template engine. Backward compatible with [eco](https://github.com/
```js
var ECT = require('ect');

var renderer = ECT({ root : __dirname + '/view', cache : true, ext : '.ect' });
var renderer = ECT({ root : __dirname + '/view', ext : '.ect' });

renderer.render('page', { title: 'Hello, World!' }, function(error, html) {
console.log(error);
Expand All @@ -37,7 +37,7 @@ var ECT = require('ect');
var renderer = ECT({ root : {
layout: '<html><head><title><%- title %></title></head><body><% content %></body></html>',
page: '<% extend "layout" %><p>Page content</p>'
}, cache : true
}
});

renderer.render('page', { title: 'Hello, World!' }, function(error, html) {
Expand Down Expand Up @@ -66,17 +66,17 @@ You can [play with demo](http://ectjs.com) to check all features.

```
<% for article in @articles : %>
<% partial 'article', { article: article } %>
<% include 'article', article %>
<% end %>
```

or

```
<% if @user?.authenticated : %>
<% partial 'partials/user' %>
<% include 'partials/user' %>
<% else : %>
<% partial 'partials/auth' %>
<% include 'partials/auth' %>
<% end %>
```

Expand All @@ -85,11 +85,6 @@ or
```
<% extend 'layout' %>
```
or

```
<% extend 'layout', { customVar: 'Hello, World!' } %>
```

Use

Expand All @@ -103,13 +98,13 @@ in parent template to define the insertion point.
### Partials

```
<% partial 'partial' %>
<% include 'partial' %>
```

or
You can redefine data context of partial

```
<% partial 'partial', { customVar: 'Hello, World!' } %>
<% include 'partial', { customVar: 'Hello, World!' } %>
```

### Blocks
Expand All @@ -135,7 +130,7 @@ Blocks supports more than one level of inheritance and may be redefined.

- `root` Templates root folder or JavaScript object containing templates
- `ext` Extension of templates, defaulting to '' (not used for JavaScript objects as root)
- `cache` Compiled functions are cached, defaulting to false
- `cache` Compiled functions are cached, defaulting to true
- `watch` Automatic reloading of changed templates, defaulting to false (useful for debugging with enabled cache, not supported for client-side)
- `open` Open tag, defaulting to '<%'
- `close` Closing tag, defaulting to '%>'
Expand All @@ -145,7 +140,7 @@ Blocks supports more than one level of inheritance and may be redefined.
Basically, include [coffee-script.js](https://github.com/jashkenas/coffee-script/blob/master/extras/coffee-script.js) and [ect.min.js](https://github.com/baryshev/ect/tree/master/ect.min.js) to a page and ect ready to use.

```js
var renderer = ECT({ root : 'view', cache : true });
var renderer = ECT({ root : 'view' });

renderer.render('page', { title: 'Hello, World!' }, function(error, html) {
console.log(error);
Expand Down
8 changes: 4 additions & 4 deletions ect.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/example.js
@@ -1,6 +1,6 @@
var ECT = require('./../index');

var renderer = ECT({ root : __dirname + '/view', cache : true, ext : '.html' });
var renderer = ECT({ root : __dirname + '/view', ext : '.html' });

renderer.render('page', { title: 'Hello, World!' }, function(error, html) {
console.log(error);
Expand Down
4 changes: 2 additions & 2 deletions examples/view/layout.html
Expand Up @@ -4,10 +4,10 @@
<title><%- @title %></title>
</head>
<body>
<header><% partial 'header' %></header>
<header><% include 'header' %></header>
<section><% content %></section>
<section><% content 'side1' %></section>
<section><% content 'side2' %></section>
<footer><% partial 'footer' %></footer>
<footer><% include 'footer' %></footer>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/view/sublayout.html
@@ -1,6 +1,6 @@
<% extend 'layout' %>
<div>
<% content %>
<% content() %>
</div>
<% block 'side1' : %>
side1 content
Expand Down

0 comments on commit 91dbddb

Please sign in to comment.