-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added emailManager, which convertTemplate into string. Added that tem…
…plates can use tailwindcss #55
- Loading branch information
1 parent
f3f7222
commit 63f4741
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
module.exports = { | ||
content: ['./src/emailTemplates/**/*.html'], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ejs from "ejs" | ||
import path from "path" | ||
import juice from "juice" | ||
import tailwindcss from "tailwindcss" | ||
|
||
/** | ||
* Load and convert an HTML template. | ||
* @param {string} templateName - The name of the template to load. This should be the name of an HTML file in the emailTemplates directory, without the .html extension. | ||
* @param {Object} data - The data to insert into the template. This should be an object where the keys are the names of placeholders in the template and the values are the values to replace the placeholders with. | ||
* @param {Boolean} useTailwindcss - Indicates whether the template uses Tailwind CSS for styling. If true, the function will apply Tailwind CSS styles to the template. If false, it will apply vanila css styles. | ||
* @returns {Promise<string>} The converted HTML template. | ||
*/ | ||
|
||
export function convertTemplate(templateName, data, useTailwindcss = true){ | ||
return new Promise((resolve, reject) => { | ||
const templatePath = path.resolve(__dirname, `../emailTemplates/${templateName}.html`); | ||
ejs.renderFile(templatePath, data, {}, (err, str) => { | ||
if(err){ | ||
reject(err); | ||
}else{ | ||
if(useTailwindcss){ | ||
// Apply Tailwind CSS styles | ||
const css = tailwindcss(path.resolve(__dirname, "../emailTemplates/style/tailwind.config.js")); | ||
const inlineHtml = juice.inlineContent(str,css); | ||
resolve(inlineHtml); | ||
}else{ | ||
const css = path.resolve(__dirname, `../emailTemplates/${templateName}/style.css`); | ||
const inlineHtml = juice.inlineContent(str,css); | ||
resolve(inlineHtml); | ||
} | ||
} | ||
}); | ||
}) | ||
} |