Skip to content

Commit

Permalink
Fixed issue mde#119
Browse files Browse the repository at this point in the history
  • Loading branch information
dgofman authored and BananaAcid committed Apr 17, 2016
1 parent 154a96c commit a67445d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ Template.prototype = {
, d = this.opts.delimiter;

if (matches && matches.length) {
this.source = ' ; __lines = ' + JSON.stringify(this.templateText) + '\n';
this.source += ' ; __filename = "' + this.opts.filename.replace(/\\/g, '/') + '"\n';
matches.forEach(function (line, index) {
var opening
, closing
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"scripts": {
"test": "mocha",
"sample": "npm install express && node test/sample/index.js",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha",
"doc": "rimraf out && jsdoc -c jsdoc.json lib/* docs/jsdoc/*",
"devdoc": "rimraf out && jsdoc -p -c jsdoc.json lib/* docs/jsdoc/*"
Expand Down
2 changes: 2 additions & 0 deletions test/sample/body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- Execute an exception -->
<p><%= this_variable_is_not_defined %></p>
3 changes: 3 additions & 0 deletions test/sample/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<head>
<title><%= header %></title>
</head>
20 changes: 20 additions & 0 deletions test/sample/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html>
<head>
<% include header.html %>
</head>
<body>
<!--
Without fix result should be confusing
ReferenceError: ./ejs/test/sample/index.html:2
1| <html>
>> 2| <head>
3| <% include header.html %>
4| </head>
5| <body>
this_variable_is_not_defined is not defined
-->
<% include body.html %>
</body>
</html>
11 changes: 11 additions & 0 deletions test/sample/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var express = require('express'),
ejs = require('../../lib/ejs.js');
var app = express();
app.engine('.html', ejs.__express);
app.set('view engine', 'ejs');
app.get('/', function(req, res) {
res.render(__dirname + '/index.html', {header: 'Hello EJS'});
});
var server = app.listen(3000, function () {
console.log('Example app listening at http://localhost:3000');
});

0 comments on commit a67445d

Please sign in to comment.