Skip to content

Commit 4f7b5bb

Browse files
committed
feat(methods): exporting lib, each template will be a method
1 parent 7a8896a commit 4f7b5bb

File tree

5 files changed

+22
-30
lines changed

5 files changed

+22
-30
lines changed

src/i18n/en_us.json

-3
This file was deleted.

src/index.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* https://github.com/ecomclub/transactional-mails
3+
* @author E-Com Club <ti@e-com.club>
4+
* @license MIT
5+
*/
6+
7+
'use strict'
8+
9+
// template render function
10+
const render = require('./lib/render')
11+
12+
const welcome = function () {
13+
return render.apply(this, [ 'welcome', ...arguments ])
14+
}
15+
16+
module.exports = {
17+
welcome
18+
}

src/main.js src/lib/render.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const ejs = require('ejs')
1010
// https://github.com/sass/node-sass
1111
const sass = require('node-sass')
1212

13-
module.exports = (template = 'index', data = {}, lang = 'en_us', themeColor = '#6c757d') => {
13+
module.exports = (template, data = {}, lang = 'en_us', themeColor = '#6c757d') => {
1414
return new Promise((resolve, reject) => {
1515
// setup dictionary object first
16-
const i18n = path.join(__dirname, `i18n/${lang}.json`)
16+
const i18n = path.join(process.cwd(), `i18n/${lang}.json`)
1717
fs.readFile(i18n, 'utf8', (err, contents) => {
1818
if (err) {
1919
return reject(err)
@@ -27,7 +27,7 @@ module.exports = (template = 'index', data = {}, lang = 'en_us', themeColor = '#
2727
}
2828

2929
// render Sass to CSS with theme color
30-
const scss = path.join(__dirname, `scss/${template}.scss`)
30+
const scss = path.join(process.cwd(), `scss/${template}.scss`)
3131
fs.readFile(scss, 'utf8', (err, contents) => {
3232
if (err) {
3333
return reject(err)
@@ -47,7 +47,7 @@ module.exports = (template = 'index', data = {}, lang = 'en_us', themeColor = '#
4747
data.themeColor = themeColor
4848

4949
// render EJS file to HTML
50-
const view = path.join(__dirname, `views/${template}.ejs`)
50+
const view = path.join(process.cwd(), `views/${template}.ejs`)
5151
ejs.renderFile(view, data, null, (err, html) => {
5252
if (err) {
5353
reject(err)

src/scss/index.scss

-3
This file was deleted.

src/views/index.ejs

-20
This file was deleted.

0 commit comments

Comments
 (0)