Skip to content

Commit

Permalink
Removed requirement for style.css and text.ejs, closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Sep 12, 2012
1 parent bca597e commit 897c58b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
53 changes: 53 additions & 0 deletions .jshintrc
@@ -0,0 +1,53 @@

<!-- saved from url=(0120)https://raw.github.com/niftylettuce/teelaunch/master/.jshintrc?login=niftylettuce&token=f8f1993df0837b0f393b0825e7f95fe1 -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{
"predef": [
"jasmine",
"spyOn",
"it",
"console",
"describe",
"expect",
"beforeEach",
"waits",
"waitsFor",
"runs",
"alert",
"confirm",
"Modernizr",
"impress",
"exports",
"self"
],

"node" : true,
"es5" : true,
"browser" : true,
"jquery": true,

"boss" : false,
"curly": false,
"debug": false,
"devel": false,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": true,
"laxcomma": true,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"sub": true,
"strict": false,
"white": false,
"indent": 2,
"asi": true
}
</pre></body></html>
11 changes: 6 additions & 5 deletions Readme.md
@@ -1,9 +1,10 @@

# node-email-templates <sup>0.0.2</sup>
# node-email-templates <sup>0.0.3</sup>

Node.js module for rendering beautiful emails with [ejs][1] templates and email-friendly inline CSS using [juice][2].

**NEW**: Added support for custom EJS options such as opening and closing tags (instead of `<%` and `%>`). See documentation below for more information.
**New in v0.0.3**:
* Removed requirement for `style.css` and `text.ejs` files with compatibility in `node` v0.6.x to v0.8.x (utilizes `path.exists` vs. `fs.exists` respectively).

## Email Templates

Expand Down Expand Up @@ -32,9 +33,9 @@ npm install email-templates-windows
2. Create a folder called `templates` inside your root directory (or elsewhere).
3. For each of your templates, respectively name and create a folder inside the `templates` folder.
4. Add the following files inside the template's folder:
* `html.ejs` - html + [ejs][1] version of your email template
* `text.ejs` - text + [ejs][1] version of your email template
* `style.css` - stylesheet for the template, which will render `html.ejs` with inline CSS (optional)
* `html.ejs` - html + [ejs][1] version of your email template (**required**)
* `text.ejs` - text + [ejs][1] version of your email template (**optional**)
* `style.css` - stylesheet for the template, which will render `html.ejs` with inline CSS (**optional**)
5. Utilize one of the examples below for your respective email module and start sending beautiful emails!


Expand Down
20 changes: 17 additions & 3 deletions lib/main.js
Expand Up @@ -113,12 +113,12 @@ var EmailTemplate = function(templateDirectory, defaults, done) {
that.text = path.join(templatePath, 'text.ejs');
that.stylesheet = path.join(templatePath, 'style.css');

async.map([that.text, that.stylesheet], fs.stat, function(err, results) {
async.map([that.text, that.stylesheet], checkExists, function(err, results) {

if (err) return callback(err);

if (!results[0].isFile()) that.text = false;
if (!results[1].isFile()) that.stylesheet = false;
that.text = results[0];
that.stylesheet = results[1];

if (that.text && that.stylesheet) {
async.map([that.text, that.stylesheet], fs.readFile, function(err, results) {
Expand Down Expand Up @@ -149,10 +149,24 @@ var EmailTemplate = function(templateDirectory, defaults, done) {
}

});


});
});
});
});

function checkExists(item, callback) {
function cb(exists) {
return callback(null, exists)
}
// node >= v0.8.x
if (fs.exists) return fs.exists(item, cb)
// other versions of node fallback to path.exists
return path.exists(item, cb)
}


});
};

Expand Down
6 changes: 5 additions & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "email-templates"
, "description": "Node.js module for rendering beautiful emails with ejs templates and email-friendly inline CSS using juice."
, "version": "0.0.2"
, "version": "0.0.3"
, "author": "Nick Baugh <niftylettuce@gmail.com>"
, "contributors": [
{ "name": "Nick Baugh", "email": "niftylettuce@gmail.com" }
Expand All @@ -22,4 +22,8 @@
, "async": "0.1.22"
, "underscore": "1.3.3"
}
, "devDependencies": {
"nodemailer": "0.3.27"
, "postmark": "0.1.6"
}
}

5 comments on commit 897c58b

@davidandrewcope
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I upgrade to 0.0.3, and put the style.css or text.ejs back in I get an exception:
fs.js:330
binding.open(pathModule._makeLong(path),
^
TypeError: path must be a string

I think this change may have broken it. I'm on node v0.8.3.

Thanks

@niftylettuce
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rolling back

@niftylettuce
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be all fixed, try version 0.0.4 for simplicity

@niftylettuce
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidandrewcope i had forgot to put in a conditional check, should be OK now in version 0.0.4, lmk if otherwise

@davidandrewcope
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, working now. Thanks!

Please sign in to comment.