-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mjml component to process mjml markup
- Loading branch information
1 parent
b795c6b
commit 3ad4e4b
Showing
4 changed files
with
72 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
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
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,30 @@ | ||
/* | ||
* @adonisjs/mail | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import type { PluginFn } from 'edge.js/types' | ||
import debug from '../debug.js' | ||
|
||
/** | ||
* Registers mjml component to convert email markup | ||
* to HTML | ||
*/ | ||
export const mailPluginEdge: PluginFn<undefined> = (edge) => { | ||
debug('detected edge. registering mjml component') | ||
|
||
edge.global('mail', { | ||
async processMjml(markup: string, options: any) { | ||
const mjml = await import('mjml') | ||
return mjml.default(markup, options).html | ||
}, | ||
}) | ||
|
||
edge.registerTemplate('mjml', { | ||
template: `{{{ await mail.processMjml(await $slots.main(), $props.all()) }}}`, | ||
}) | ||
} |
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,36 @@ | ||
/* | ||
* @adonisjs/mail | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import mjml2html from 'mjml' | ||
import { Edge } from 'edge.js' | ||
import { test } from '@japa/runner' | ||
import { mailPluginEdge } from '../../../src/plugins/edge.js' | ||
|
||
test.group('Edge plugin', () => { | ||
test('render mjml markup to HTML', async ({ assert, fs }) => { | ||
const edge = new Edge() | ||
edge.mount(fs.baseUrl) | ||
edge.use(mailPluginEdge) | ||
|
||
const markup = `<mjml> | ||
<mj-body> | ||
<mj-section> | ||
<mj-column> | ||
<mj-text> | ||
Hello World! | ||
</mj-text> | ||
</mj-column> | ||
</mj-section> | ||
</mj-body> | ||
</mjml>` | ||
|
||
const html = await edge.renderRaw(`@mjml() \n ${markup} \n @end`) | ||
assert.equal(html, mjml2html(markup).html) | ||
}) | ||
}) |