Permalink
Browse files

First commit

  • Loading branch information...
baryshev committed Sep 8, 2012
0 parents commit a80af3ae93821b9d668cef09c4210e684f3bd545
Showing with 1,002 additions and 0 deletions.
  1. +3 −0 .npmignore
  2. +22 −0 LICENSE
  3. +175 −0 README.md
  4. +24 −0 cent.min.js
  5. +8 −0 examples/example.js
  6. +1 −0 examples/view/footer.html
  7. +1 −0 examples/view/header.html
  8. +13 −0 examples/view/layout.html
  9. +10 −0 examples/view/page.html
  10. +7 −0 examples/view/sublayout.html
  11. +1 −0 index.js
  12. +721 −0 lib/cent.js
  13. +16 −0 package.json
@@ -0,0 +1,3 @@
+.git*
+examples/
+cent.min.js
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2012 Vadim M. Baryshev <vadimbaryshev@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
175 README.md
@@ -0,0 +1,175 @@
+# Cent
+
+CoffeeScript template engine. Backward compatible with [eco](https://github.com/sstephenson/eco).
+
+## Installation
+
+ npm install cent
+
+## Features
+
+ * Caching templates
+ * Automatic reloading of changed templates
+ * CoffeeScript code in templates
+ * Supports tag customization
+ * Node.JS and client-side support
+ * Powerful but simple syntax
+ * Inheritance, partials, blocks
+
+## Usage
+
+```js
+var Cent = require('cent');
+
+var renderer = Cent({ root : __dirname + '/view', useCache : true, ext : '.html' });
+
+renderer.render('page', { title: 'Hello, World!' }, function(error, html) {
+ console.log(error);
+ console.log(html);
+});
+```
+
+You may use JavaScript object as root.
+
+```js
+var Cent = require('cent');
+
+var renderer = Cent({ root : {
+ layout: '<html><head><title><%= title %></title></head><body><%*%></body></html>',
+ page: '<%! layout %><p>Page content</p>'
+ }, useCache : true
+ });
+
+renderer.render('page', { title: 'Hello, World!' }, function(error, html) {
+ console.log(error);
+ console.log(html);
+});
+```
+
+See full example in [examples](https://github.com/baryshev/cent/tree/master/examples) folder.
+
+## Syntax
+
+### Output
+
+```
+<%= someVar %>
+```
+
+### CoffeeScript code
+
+```
+<% for article in articles : %>
+ <%@ article { article: article } %>
+<% end %>
+```
+
+or
+
+```
+<% if user?.authenticated : %>
+ <%@ partials/user %>
+<% else : %>
+ <%@ partials/auth %>
+<% end %>
+```
+
+### Inheritance
+
+```
+<%! layout %>
+```
+or
+
+```
+<%! layout { customVar: 'Hello, World!' } %>
+```
+
+Use
+
+
+```
+<%*%>
+```
+
+in parent template to define the insertion point.
+
+### Partials
+
+```
+<%@ partial %>
+```
+
+or
+
+```
+<%@ partial { customVar: 'Hello, World!' } %>
+```
+
+### Blocks
+
+```
+<%[ blockName %>
+ <p>This is block content</p>
+<%]%>
+```
+
+Use
+
+
+```
+<%* blockName %>
+```
+
+in parent template to define the insertion point.
+
+Blocks supports more than one level of inheritance and may be redefined.
+
+## Options
+
+ - `root` Templates root folder or JavaScript object containing templates
+ - `ext` Extension of templates, defaulting to '' (not used for JavaScript objects as root)
+ - `useCache` Compiled functions are cached, defaulting to false
+ - `watchForChanges` Automatic reloading of changed templates, defaulting to false (useful for debugging with enabled useCache, not supported for client-side)
+ - `open` Open tag, defaulting to '<%'
+ - `close` Closing tag, defaulting to '%>'
+
+## Client-side support
+
+Basically, include [coffee-script.js](https://github.com/jashkenas/coffee-script/blob/master/extras/coffee-script.js) and [cent.min.js](https://github.com/baryshev/cent/tree/master/cent.min.js) to a page and Cent ready to use.
+
+```js
+var renderer = Cent({ root : '/view', useCache : true });
+
+renderer.render('page', { title: 'Hello, World!' }, function(error, html) {
+ console.log(error);
+ console.log(html);
+});
+```
+
+NOTE: root folder must be on the same domain to avoid cross-domain restrictions.
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2012 Vadim M. Baryshev &lt;vadimbaryshev@gmail.com&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,8 @@
+var Cent = require('./../index');
+
+var renderer = Cent({ root : __dirname + '/view', useCache : true, ext : '.html' });
+
+renderer.render('page', { title: 'Hello, World!' }, function(error, html) {
+ console.log(error);
+ console.log(html);
+});
@@ -0,0 +1 @@
+<p>Footer content</p>
@@ -0,0 +1 @@
+<h1>Page title</h1>
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%- @title %></title>
+ </head>
+ <body>
+ <header><%@ header %></header>
+ <section><%*%></section>
+ <section><%* side1 %></section>
+ <section><%* side2 %></section>
+ <footer><%@ footer %></footer>
+ </body>
+</html>
@@ -0,0 +1,10 @@
+<%! sublayout %>
+<p>
+Page content
+</p>
+<%[ side1 %>
+redefined side1 content
+<%]%>
+<%[ side2 %>
+side2 content
+<%]%>
@@ -0,0 +1,7 @@
+<%! layout %>
+<div>
+<%*%>
+</div>
+<%[ side1 %>
+side1 content
+<%]%>
@@ -0,0 +1 @@
+module.exports = require('./lib/cent');
Oops, something went wrong.

0 comments on commit a80af3a

Please sign in to comment.