forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.66k stars 339 forks source link

custom path format for template files #377

Closed ehsanonline closed 4 years ago

ehsanonline commented 4 years ago

I like to have all of my files and templates in root folder, instead of template folder, and organize them like this:

.
├── app.js
└── emails
    ├── mars.html.pug
    ├── mars.text.pug
    └── earth.html.pug

So I add a path key to view option, that is a path format for templates structure. It's a string that could contain:

All of them will be replaced automatically. For the example above, the path is <template>.<type>. The default path is <template><sep><type>.

codecov-io commented 4 years ago

Codecov Report

Merging #377 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #377   +/-   ##
=======================================
  Coverage   89.38%   89.38%           
=======================================
  Files           1        1           
  Lines         113      113           
=======================================
  Hits          101      101           
  Misses         12       12
Impacted Files Coverage Δ
src/index.js 89.38% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 065c5fb...fce7c03. Read the comment docs.

niftylettuce commented 4 years ago

Can you please change this PR so that it is a function instead of a String? The function would accept three arguments, type, template, locals and return a String.

niftylettuce commented 4 years ago

e.g. const str = this.config.getPath(type, template, locals) and

getPath = function(type, template) { return `${template}/${type}`; }
niftylettuce commented 4 years ago

I've released this feature in v6.1.0. See the README for config.getPath function. Just pass your custom function and it should work.

I've also fixed it by default to use path.sep from Node's internal path package, so it should work better cross platform (e.g. instead of ${a}/${b} it is now path.join(a, b).

npm install email-templates@latest`

or with yarn

yarn add email-templates@latest