Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Templates and mixins #53

Open
wants to merge 3 commits into from

4 participants

@forste

Added support for templates and mixins. See Readme for more.

@tj
Owner
tj commented

looks decent I'll go through and review!

@tj tj commented on the diff
Readme.md
@@ -18,6 +18,8 @@ Embedded JavaScript templates.
* Filter support for designer-friendly templates
* Client-side support
* Newline slurping with `<% code -%>` or `<% -%>` or `<%= code -%>` or `<%- code -%>`
+ * Templating with <%+ template.html %> and <%~ argumentName %>
@tj Owner
tj added a note

maybe some others will chime in here, but I would personally rather see these named instead of introducing a bunch more chars to remember. Maybe <% extend template.html %> and <% block name %>

@forste
forste added a note

thought about that as well. for consistency I picked the chars

Chiming in. I personally prefer extend and block as well, more expressive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tj tj commented on the diff
Readme.md
@@ -18,6 +18,8 @@ Embedded JavaScript templates.
* Filter support for designer-friendly templates
* Client-side support
* Newline slurping with `<% code -%>` or `<% -%>` or `<%= code -%>` or `<%- code -%>`
+ * Templating with <%+ template.html %> and <%~ argumentName %>
+ * Mixins with <%# mixin.html %>
@tj Owner
tj added a note

maybe <% include foo.html %> here too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tj tj commented on the diff
lib/ejs.js
((7 lines not shown))
+ * @param {String} str
+ * @param {String} filename
+ * @param {String} lineno
+ * @api private
+ */
+
+function extendTemplate(pathToSuper){
+ //load
+
+}
+
+function insertTemplate(args, i){
+ //insert
+
+
+
@tj Owner
tj added a note

what's all this?

@forste
forste added a note

good question, should not be in here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tj tj commented on the diff
lib/ejs.js
((35 lines not shown))
"var buf = [];"
- , "\nwith (locals) {"
- , "\n buf.push('"
- ];
-
+ , "\nwith (locals) {"
+ , "\n buf.push('"
+ ];
+ }
+
+ //insert mixings
+ var mixinStartSym = '<%#',
@tj Owner
tj added a note

we shouldn't hard-code the <% %> delimiters since devs can change them to {{}} etc

@forste
forste added a note

forgot about changing that, will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tj tj commented on the diff
lib/ejs.js
((60 lines not shown))
+ console.log('mixinsJs=('+mixinsJs+')');
+ }
+
+ mixinsJs = options.settings.views ? path.join(options.settings.views, mixinsJs) : mixinsJs;
+ mixinReplacement = fs.readFileSync(mixinsJs, 'utf8');
+
+ if(options.debug) {
+ console.log('mixinReplacement=(\n'+mixinReplacement+'\n)');
+ }
+
+ strBeforeMixin = str.substring(0,
+ mixinStart
+ );
+ if(options.debug) {
+ console.log('strBeforeMixin=(\n'+strBeforeMixin+'\n)');
+ }
@tj Owner
tj added a note

all the debug stuff can go once we have test cov

@forste
forste added a note

I guess I will leave it for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@forste

let me know if characters [+~#] or strings (which ones) are prefered. I can fix the rest then and re-request

@forste

additionally I thought about allowing compile templates and mixins so that they don't have to be composed every request. compilation would be independent from caching mechanisms

@rummik

@forste From the way things read, strings are the preferred

@TimothyGu TimothyGu referenced this pull request from a commit in TimothyGu/ejs-tj
@TimothyGu TimothyGu Make renderFile async
Fixes #53.
635f588
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 4, 2012
  1. @forste
  2. @forste

    Fixed Readme

    forste authored
  3. @forste

    Fixed readme

    forste authored
This page is out of date. Refresh to see the latest.
View
94 Readme.md
@@ -18,6 +18,8 @@ Embedded JavaScript templates.
* Filter support for designer-friendly templates
* Client-side support
* Newline slurping with `<% code -%>` or `<% -%>` or `<%= code -%>` or `<%- code -%>`
+ * Templating with <%+ template.html %> and <%~ argumentName %>
@tj Owner
tj added a note

maybe some others will chime in here, but I would personally rather see these named instead of introducing a bunch more chars to remember. Maybe <% extend template.html %> and <% block name %>

@forste
forste added a note

thought about that as well. for consistency I picked the chars

Chiming in. I personally prefer extend and block as well, more expressive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ * Mixins with <%# mixin.html %>
@tj Owner
tj added a note

maybe <% include foo.html %> here too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
## Example
@@ -121,6 +123,98 @@ ejs.filters.last = function(obj) {
};
```
+## Templates
+
+Path to templates can be set by setting the setting property like
+```js
+renderFile(path, { settings : { views : 'path/to/views' } }, cb)
+```
+
+
+### Template - template.html
+
+```js
+<html>
+<head>
+ <title>My site </title>
+ <link href="/css/mysite.css" rel="stylesheet">
+</head>
+<body>
+ <%~ body %>
+
+ <hr>
+ <footer>
+ <p>&copy; Brand 2012</p>
+ </footer>
+ <script src="/js/jquery.js"></script>
+
+ <%~ scripts %>
+</body>
+```
+
+### Using template (settings.html)
+
+```js
+<%+ template.html %>
+<%+ body %>
+<p>settings here</p>
+<%+%>
+<%+ scripts %>
+ <script src="/js/settings.js"></script>
+<%+%>
+```
+
+### Output
+
+```js
+<html>
+<head>
+ <title>My site </title>
+ <link href="/css/mysite.css" rel="stylesheet">
+</head>
+<body>
+ <p>settings here</p>
+
+ <hr>
+ <footer>
+ <p>&copy; Brand 2012</p>
+ </footer>
+ <script src="/js/jquery.js"></script>
+ <script src="/js/settings.js"></script>
+</body>
+```
+
+## Mixins
+
+Path to mixins can be set by setting the setting property like
+```js
+renderFile(path, { settings : { views : 'path/to/views' } }, cb)
+```
+
+### Mixin (mixin.html)
+
+```js
+<button id="mixin">
+</button>
+```
+
+### Using mixins
+
+```js
+<div>
+ <%# mixin.html %>
+</div>
+```
+
+### Output
+
+```js
+<div>
+ <button id="mixin">
+ </button>
+</div>
+```
+
## client-side support
include `./ejs.js` or `./ejs.min.js` and `require("ejs").compile(str)`.
View
30 ejs.js
@@ -1,3 +1,4 @@
+exports.test = 'bla';
// CommonJS require()
@@ -31,11 +32,11 @@ require.register = function (path, fn){
require.relative = function (parent) {
return function(p){
if ('.' != p.substr(0, 1)) return require(p);
-
+
var path = parent.split('/')
, segs = p.split('/');
path.pop();
-
+
for (var i = 0; i < segs.length; i++) {
var seg = segs[i];
if ('..' == seg) path.pop();
@@ -70,7 +71,7 @@ exports.version = '0.6.1';
/**
* Filters.
- *
+ *
* @type Object
*/
@@ -78,7 +79,7 @@ var filters = exports.filters = require('./filters');
/**
* Intermediate js cache.
- *
+ *
* @type Object
*/
@@ -139,11 +140,11 @@ function rethrow(err, str, filename, lineno){
// Alter exception message
err.path = filename;
- err.message = (filename || 'ejs') + ':'
- + lineno + '\n'
- + context + '\n\n'
+ err.message = (filename || 'ejs') + ':'
+ + lineno + '\n'
+ + context + '\n\n'
+ err.message;
-
+
throw err;
}
@@ -165,13 +166,13 @@ var parse = exports.parse = function(str, options){
, "\nwith (locals) {"
, "\n buf.push('"
];
-
+
var lineno = 1;
for (var i = 0, len = str.length; i < len; ++i) {
if (str.slice(i, open.length + i) == open) {
i += open.length
-
+
var prefix, postfix, line = '__stack.lineno=' + lineno;
switch (str.substr(i, 1)) {
case '=':
@@ -228,12 +229,12 @@ var parse = exports.parse = function(str, options){
var compile = exports.compile = function(str, options){
options = options || {};
-
+
var input = JSON.stringify(str)
, filename = options.filename
? JSON.stringify(options.filename)
: 'undefined';
-
+
// Adds the fancy stack trace meta info
str = [
'var __stack = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };',
@@ -244,7 +245,7 @@ var compile = exports.compile = function(str, options){
' rethrow(err, __stack.input, __stack.filename, __stack.lineno);',
'}'
].join("\n");
-
+
if (options.debug) console.log(str);
var fn = new Function('locals, filters, escape', str);
return function(locals){
@@ -563,5 +564,6 @@ exports.escape = function(html){
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
-
+
}); // module: utils.js
+
View
203 lib/ejs.js
@@ -1,4 +1,3 @@
-
/*!
* EJS
* Copyright(c) 2012 TJ Holowaychuk <tj@vision-media.ca>
@@ -10,7 +9,9 @@
*/
var utils = require('./utils')
- , fs = require('fs');
+ , util = require('util')
+ , fs = require('fs')
+ , path = require('path');
/**
* Library version.
@@ -20,7 +21,7 @@ exports.version = '0.7.2';
/**
* Filters.
- *
+ *
* @type Object
*/
@@ -28,7 +29,7 @@ var filters = exports.filters = require('./filters');
/**
* Intermediate js cache.
- *
+ *
* @type Object
*/
@@ -63,6 +64,30 @@ function filtered(js) {
};
/**
+ * Description
+ *
+ * @param {Error} err
+ * @param {String} str
+ * @param {String} filename
+ * @param {String} lineno
+ * @api private
+ */
+
+function extendTemplate(pathToSuper){
+ //load
+
+}
+
+function insertTemplate(args, i){
+ //insert
+
+
+
@tj Owner
tj added a note

what's all this?

@forste
forste added a note

good question, should not be in here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+}
+
+
+
+/**
* Re-throw the given `err` in context to the
* `str` of ejs, `filename`, and `lineno`.
*
@@ -89,11 +114,11 @@ function rethrow(err, str, filename, lineno){
// Alter exception message
err.path = filename;
- err.message = (filename || 'ejs') + ':'
- + lineno + '\n'
- + context + '\n\n'
+ err.message = (filename || 'ejs') + ':'
+ + lineno + '\n'
+ + context + '\n\n'
+ err.message;
-
+
throw err;
}
@@ -105,24 +130,126 @@ function rethrow(err, str, filename, lineno){
* @api public
*/
-var parse = exports.parse = function(str, options){
+var parse = exports.parse = function(str, options, templateArgs){
var options = options || {}
, open = options.open || exports.open || '<%'
- , close = options.close || exports.close || '%>';
+ , close = options.close || exports.close || '%>',
+ templateEnd,
+ templateName,
+ templateString,
+ parsedTemplateStr,
+ args,
+ argsFound,
+ argName,
+ argStart,
+ argContentEnd,
+ argContent,
+ argEnd,
+ argJsUntrimmed,
+ argReplacement,
+ argsJs;
+
+ var buf = ["\n buf.push('"];
+
+ if(options.debug) {
+ console.log('templateArgs=('+util.inspect(templateArgs, false, null)+')');
+ }
- var buf = [
+ if(!templateArgs) {
+ //included in another template and must not have trailing and preceding code
+ buf = [
"var buf = [];"
- , "\nwith (locals) {"
- , "\n buf.push('"
- ];
-
+ , "\nwith (locals) {"
+ , "\n buf.push('"
+ ];
+ }
+
+ //insert mixings
+ var mixinStartSym = '<%#',
@tj Owner
tj added a note

we shouldn't hard-code the <% %> delimiters since devs can change them to {{}} etc

@forste
forste added a note

forgot about changing that, will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ strBeforeMixin,
+ strAfterMixin,
+ mixinStart,
+ mixinEnd,
+ mixinsJs,
+ mixinReplacement;
+
+ mixinStart = str.indexOf(mixinStartSym);
+ while(mixinStart !== -1) {
+ mixinEnd = str.indexOf(close, mixinStart);
+ mixinsJs = utils.trim(str.substring(mixinStart+mixinStartSym.length, mixinEnd));
+
+ if(options.debug) {
+ console.log('mixinsJs=('+mixinsJs+')');
+ }
+
+ mixinsJs = options.settings.views ? path.join(options.settings.views, mixinsJs) : mixinsJs;
+ mixinReplacement = fs.readFileSync(mixinsJs, 'utf8');
+
+ if(options.debug) {
+ console.log('mixinReplacement=(\n'+mixinReplacement+'\n)');
+ }
+
+ strBeforeMixin = str.substring(0,
+ mixinStart
+ );
+ if(options.debug) {
+ console.log('strBeforeMixin=(\n'+strBeforeMixin+'\n)');
+ }
@tj Owner
tj added a note

all the debug stuff can go once we have test cov

@forste
forste added a note

I guess I will leave it for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ strAfterMixin = str.substring(mixinEnd+close.length,
+ str.length
+ );
+ if(options.debug) {
+ console.log('strAfterMixin=(\n'+strAfterMixin+'\n)');
+ }
+
+ str = strBeforeMixin + mixinReplacement + strAfterMixin;
+ if(options.debug) {
+ console.log('str with inserted mixin=(\n'+str+'\n)');
+ }
+ mixinStart = str.indexOf(mixinStartSym, mixinStart);
+ }
+
+
+
var lineno = 1;
+
+ var argStartSym = '<%~',
+ strBeforeArg,
+ strAfterArg;
+ //replace args
+ argStart = str.indexOf(argStartSym);
+ while(argStart !== -1) {
+ argEnd = str.indexOf(close, argStart);
+ argsJs = utils.trim(str.substring(argStart+argStartSym.length, argEnd));
+
+ if(options.debug) {
+ console.log('argsJs=('+argsJs+')');
+ }
+
+ argReplacement = templateArgs[argsJs];
+
+ strBeforeArg = str.substring(0,
+ argStart
+ );
+
+ strAfterArg = str.substring(argEnd+close.length,
+ str.length
+ );
+
+ str = strBeforeArg + argReplacement + strAfterArg;
+ argStart = str.indexOf(argStartSym, argEnd);
+ }
+
+ if (options.debug) {
+ console.log('after arg-replacement=(\n'+str+'\n)');
+ }
+
var consumeEOL = false;
for (var i = 0, len = str.length; i < len; ++i) {
if (str.slice(i, open.length + i) == open) {
i += open.length
-
+
var prefix, postfix, line = '__stack.lineno=' + lineno;
switch (str.substr(i, 1)) {
case '=':
@@ -135,6 +262,30 @@ var parse = exports.parse = function(str, options){
postfix = "), '";
++i;
break;
+ case '+':
+ templateEnd = str.indexOf(close, i);
+ templateName = utils.trim(str.substring(i+1, templateEnd));
+ templateName = options.settings.views ? path.join(options.settings.views, templateName) : templateName;
+
+ args = [];
+ argStart = str.indexOf("<%+", i);
+ while(argStart !== -1) {
+ argEnd = str.indexOf(close, argStart);
+ argName = utils.trim(str.substring(argStart+"<%+".length, argEnd));
+ argContentEnd = str.indexOf("<%+", argEnd);
+ argContent = str.substring(argEnd+close.length, argContentEnd);
+ args[argName] = argContent;
+
+ argStart = str.indexOf("<%+", argContentEnd+1);
+ }
+ i = argContentEnd+"<%+".length;
+
+ templateString = fs.readFileSync(templateName, 'utf8');
+ parsedTemplateStr = exports.parse(templateString, options, args);
+
+ prefix = "');"+parsedTemplateStr;
+ postfix = "; buf.push('";
+ break;
default:
prefix = "');" + line + ';';
postfix = "; buf.push('";
@@ -144,12 +295,12 @@ var parse = exports.parse = function(str, options){
, js = str.substring(i, end)
, start = i
, n = 0;
-
+
if ('-' == js[js.length-1]){
js = js.substring(0, js.length - 2);
consumeEOL = true;
}
-
+
while (~(n = js.indexOf("\n", n))) n++, lineno++;
if (js.substr(0, 1) == ':') js = filtered(js);
buf.push(prefix, js, postfix);
@@ -173,7 +324,15 @@ var parse = exports.parse = function(str, options){
}
}
- buf.push("');\n}\nreturn buf.join('');");
+
+ buf.push("')");
+
+ if(!templateArgs) {
+ //not included in another template
+ buf.push(";\n\n}");
+ buf.push("return buf.join('');");
+ }
+
return buf.join('');
};
@@ -188,12 +347,12 @@ var parse = exports.parse = function(str, options){
var compile = exports.compile = function(str, options){
options = options || {};
-
+
var input = JSON.stringify(str)
, filename = options.filename
? JSON.stringify(options.filename)
: 'undefined';
-
+
// Adds the fancy stack trace meta info
str = [
'var __stack = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };',
@@ -204,7 +363,7 @@ var compile = exports.compile = function(str, options){
' rethrow(err, __stack.input, __stack.filename, __stack.lineno);',
'}'
].join("\n");
-
+
if (options.debug) console.log(str);
var fn = new Function('locals, filters, escape', str);
return function(locals){
View
13 lib/utils.js
@@ -20,4 +20,15 @@ exports.escape = function(html){
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
-
+
+/**
+ * Trims the given string of `str`.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+exports.trim = function(str) {
+ return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
+}
View
99 test/ejs.test.js
@@ -4,13 +4,14 @@
*/
var ejs = require('../')
- , assert = require('assert');
+ , assert = require('assert')
+ , fs = require('fs');
module.exports = {
'test .version': function(){
assert.ok(/^\d+\.\d+\.\d+$/.test(ejs.version), 'Test .version format');
},
-
+
'test html': function(){
assert.equal('<p>yay</p>', ejs.render('<p>yay</p>'));
},
@@ -25,39 +26,39 @@ module.exports = {
assert.equal(res, html);
})
},
-
+
'test buffered code': function(){
var html = '<p>tj</p>',
str = '<p><%= name %></p>',
locals = { name: 'tj' };
assert.equal(html, ejs.render(str, { locals: locals }));
},
-
+
'test unbuffered code': function(){
var html = '<p>tj</p>',
str = '<% if (name) { %><p><%= name %></p><% } %>',
locals = { name: 'tj' };
assert.equal(html, ejs.render(str, { locals: locals }));
},
-
+
'test `scope` option': function(){
var html = '<p>tj</p>',
str = '<p><%= this %></p>';
assert.equal(html, ejs.render(str, { scope: 'tj' }));
},
-
+
'test escaping': function(){
assert.equal('&lt;script&gt;', ejs.render('<%= "<script>" %>'));
assert.equal('<script>', ejs.render('<%- "<script>" %>'));
},
-
+
'test newlines': function(){
var html = '\n<p>tj</p>\n<p>tj@sencha.com</p>',
str = '<% if (name) { %>\n<p><%= name %></p>\n<p><%= email %></p><% } %>',
locals = { name: 'tj', email: 'tj@sencha.com' };
assert.equal(html, ejs.render(str, { locals: locals }));
},
-
+
'test single quotes': function(){
var html = '<p>WAHOO</p>',
str = "<p><%= up('wahoo') %></p>",
@@ -89,14 +90,14 @@ module.exports = {
str = "<p>backslash: '\\'</p>";
assert.equal(html, ejs.render(str));
},
-
+
'test double quotes': function(){
var html = '<p>WAHOO</p>',
str = '<p><%= up("wahoo") %></p>',
locals = { up: function(str){ return str.toUpperCase(); }};
assert.equal(html, ejs.render(str, { locals: locals }));
},
-
+
'test multiple double quotes': function() {
var html = '<p>just a "test" wahoo</p>',
str = '<p>just a "test" wahoo</p>';
@@ -112,7 +113,7 @@ module.exports = {
str = '<p><%=bar%></p>';
assert.equal(html, ejs.render(str, { bar: 'foo' }));
},
-
+
'test whitespace': function(){
var html = '<p>foo</p>',
str = '<p><%="foo"%></p>';
@@ -122,7 +123,7 @@ module.exports = {
str = '<p><%=bar%></p>';
assert.equal(html, ejs.render(str, { locals: { bar: 'foo' }}));
},
-
+
'test custom tags': function(){
var html = '<p>foo</p>',
str = '<p>{{= "foo" }}</p>';
@@ -158,7 +159,7 @@ module.exports = {
close: '??>'
}));
},
-
+
'test global custom tags': function(){
var html = '<p>foo</p>',
str = '<p>{{= "foo" }}</p>';
@@ -168,7 +169,7 @@ module.exports = {
delete ejs.open;
delete ejs.close;
},
-
+
'test iteration': function(){
var html = '<p>foo</p>',
str = '<% for (var key in items) { %>'
@@ -179,7 +180,7 @@ module.exports = {
items: ['foo']
}
}));
-
+
var html = '<p>foo</p>',
str = '<% items.forEach(function(item){ %>'
+ '<p><%= item %></p>'
@@ -190,7 +191,7 @@ module.exports = {
}
}));
},
-
+
'test filter support': function(){
var html = 'Zab',
str = '<%=: items | reverse | first | reverse | capitalize %>';
@@ -200,7 +201,7 @@ module.exports = {
}
}));
},
-
+
'test filter argument support': function(){
var html = 'tj, guillermo',
str = '<%=: users | map:"name" | join:", " %>';
@@ -213,7 +214,7 @@ module.exports = {
}
}));
},
-
+
'test sort_by filter': function(){
var html = 'tj',
str = '<%=: users | sort_by:"name" | last | get:"name" %>';
@@ -227,7 +228,7 @@ module.exports = {
}
}));
},
-
+
'test custom filters': function(){
var html = 'Welcome Tj Holowaychuk',
str = '<%=: users | first | greeting %>';
@@ -245,16 +246,16 @@ module.exports = {
}));
},
- 'test useful stack traces': function(){
+ 'test useful stack traces': function(){
var str = [
"A little somethin'",
"somethin'",
- "<% if (name) { %>", // Failing line
+ "<% if (name) { %>", // Failing line
" <p><%= name %></p>",
" <p><%= email %></p>",
"<% } %>"
].join("\n");
-
+
try {
ejs.render(str)
} catch (err) {
@@ -264,20 +265,20 @@ module.exports = {
assert.deepEqual(lineno,3, "Error should been thrown on line 3, was thrown on line "+lineno);
}
},
-
- 'test useful stack traces multiline': function(){
+
+ 'test useful stack traces multiline': function(){
var str = [
"A little somethin'",
"somethin'",
"<% var some = 'pretty';",
" var multiline = 'javascript';",
"%>",
- "<% if (name) { %>", // Failing line
+ "<% if (name) { %>", // Failing line
" <p><%= name %></p>",
" <p><%= email %></p>",
"<% } %>"
].join("\n");
-
+
try {
ejs.render(str)
} catch (err) {
@@ -287,7 +288,7 @@ module.exports = {
assert.deepEqual(lineno, 6, "Error should been thrown on line 3, was thrown on line "+lineno);
}
},
-
+
'test slurp' : function() {
var expected = 'me\nhere',
str = 'me<% %>\nhere';
@@ -300,7 +301,7 @@ module.exports = {
var expected = 'me\nhere',
str = 'me<% -%>\n\nhere';
assert.equal(expected, ejs.render(str));
-
+
var expected = 'me inbetween \nhere',
str = 'me <%= x %> \nhere';
assert.equal(expected, ejs.render(str,{x:'inbetween'}));
@@ -324,6 +325,44 @@ module.exports = {
' Hallo <%= i %>\n' +
'<% } -%>\n';
assert.equal(expected, ejs.render(str));
- }
-
+ },
+ 'test templates': function(){
+ var html = fs.readFileSync(__dirname + '/fixtures/level3_composed.html', 'utf8'),
+ options = {
+ settings : {
+ views : __dirname + '/fixtures/'
+ }
+ };
+
+ ejs.renderFile(__dirname + '/fixtures/level3.html', options, function(err, res){
+ assert.ok(!err);
+ assert.deepEqual(res, html);
+ })
+ },
+ 'test mixins': function(){
+ var html = fs.readFileSync(__dirname + '/fixtures/mixin_base_composed.html', 'utf8'),
+ options = {
+ settings : {
+ views : __dirname + '/fixtures/'
+ }
+ };
+
+ ejs.renderFile(__dirname + '/fixtures/mixin_base.html', options, function(err, res){
+ assert.ok(!err);
+ assert.equal(res, html);
+ })
+ },
+ 'test template with mixin': function(){
+ var html = fs.readFileSync(__dirname + '/fixtures/mixin_template_base_composed.html', 'utf8'),
+ options = {
+ settings : {
+ views : __dirname + '/fixtures/'
+ }
+ };
+
+ ejs.renderFile(__dirname + '/fixtures/mixin_template_base.html', options, function(err, res){
+ assert.ok(!err);
+ assert.equal(res, html);
+ })
+ }
};
View
5 test/fixtures/level1.html
@@ -0,0 +1,5 @@
+<div id="level1">
+ <%~ level1arg1 %>
+ <hr>
+ <%~ level1arg2 %>
+</div>
View
13 test/fixtures/level2.html
@@ -0,0 +1,13 @@
+<div id="level2">
+<%+ level1.html %>
+<%+ level1arg1 %>
+<button id="process-button" type="submit" class="btn">
+ <%~ level2arg1 %>
+</button>
+<%+%>
+<%+ level1arg2 %>
+<span>
+ <%~ level2arg2 %>
+</span>
+<%+%>
+</div>
View
9 test/fixtures/level3.html
@@ -0,0 +1,9 @@
+<div id="level3">
+<%+ level2.html %>
+<%+ level2arg1 %>
+<p>level3 here</p>
+<%+%>
+<%+ level2arg2 %>
+<h3>This comes from level3</h3>
+<%+%>
+</div>
View
23 test/fixtures/level3_composed.html
@@ -0,0 +1,23 @@
+<div id="level3">
+<div id="level2">
+<div id="level1">
+
+<button id="process-button" type="submit" class="btn">
+
+<p>level3 here</p>
+
+</button>
+
+ <hr>
+
+<span>
+
+<h3>This comes from level3</h3>
+
+</span>
+
+</div>
+
+</div>
+
+</div>
View
5 test/fixtures/mixin_base.html
@@ -0,0 +1,5 @@
+<div id="mixin_base">
+ <%# plain_html_mixin_1.html %>
+ <hr>
+ <%# templated_mixin_1.html %>
+</div>
View
23 test/fixtures/mixin_base_composed.html
@@ -0,0 +1,23 @@
+<div id="mixin_base">
+ <div id="plain_html_mixin_1.html">
+</div>
+
+ <hr>
+ <div id="templated_mixin_1.html">
+<div id="level1">
+
+<button>
+ level1arg1
+</button>
+
+ <hr>
+
+<span>
+ level1arg2
+</span>
+
+</div>
+
+</div>
+
+</div>
View
11 test/fixtures/mixin_template_base.html
@@ -0,0 +1,11 @@
+<%+ level1.html %>
+<%+ level1arg1 %>
+<div id="mixin_base">
+ <%# plain_html_mixin_1.html %>
+ <hr>
+</div>
+<%+%>
+<%+ level1arg2 %>
+<p>level1arg2</p>
+<%+%>
+
View
16 test/fixtures/mixin_template_base_composed.html
@@ -0,0 +1,16 @@
+<div id="level1">
+
+<div id="mixin_base">
+ <div id="plain_html_mixin_1.html">
+</div>
+
+ <hr>
+</div>
+
+ <hr>
+
+<p>level1arg2</p>
+
+</div>
+
+
View
2  test/fixtures/plain_html_mixin_1.html
@@ -0,0 +1,2 @@
+<div id="plain_html_mixin_1.html">
+</div>
View
1  test/fixtures/simple.html
@@ -0,0 +1 @@
+<p>simple html for testing </p>
View
13 test/fixtures/templated_mixin_1.html
@@ -0,0 +1,13 @@
+<div id="templated_mixin_1.html">
+<%+ level1.html %>
+<%+ level1arg1 %>
+<button>
+ level1arg1
+</button>
+<%+%>
+<%+ level1arg2 %>
+<span>
+ level1arg2
+</span>
+<%+%>
+</div>
Something went wrong with that request. Please try again.