Skip to content

Commit

Permalink
Added documentation for inject util
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Sisley authored and Justin Sisley committed Aug 8, 2016
1 parent a32a2b2 commit 26de362
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,39 @@ npm run email-send

This is the preferred way of using __mjml-utils__, since you can configure it on a per-project basis, and you won't have to remember any command line arguments other than the simple NPM script alias.

## Module Usage

__mjml-utils__ also has a built in helper method called `inject`. An example of its usage is below:

```javascript
const mjmlUtils = require('mjml-utils');
const pathToHtmlEmailTemplate = path.join(__dirname, '../emails/welcome.html');

mjmlUtils.inject(pathToHtmlEmailTemplate, {
name: 'bob',
profileURL: 'https://app.com/bob',
})
.then(finalTemplate => {
// finalTemplate is an HTML string containing the template with all occurrences
// of `{name}` replaced with "bob", and all occurrences of `{profileURL}`
// replaced with "https://app.com/bob".
});
```

The above JavaScript assumes a template called `welcome.html` exists at the specified path, and that it's contents are something like the following example:

```html
<html>
<body>
<h1>Welcome {name}</h1>

<p><a href="{profileURL}">Click here</a> to view your profile.</p>
</body>
</html>
```

This means your raw MJML template should contain the necessary template strings that you intend to replace with dynamic values.

## Versioning

To keep better organization of releases this project follows the [Semantic Versioning 2.0.0](http://semver.org/) guidelines.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mjml-utils",
"version": "0.5.0",
"version": "0.5.1",
"author": "Justin Sisley <[email protected]>",
"description": "The utility belt for MJML developers",
"repository": "https://github.com/justinsisley/mjml-utils",
Expand Down

0 comments on commit 26de362

Please sign in to comment.