Skip to content

Commit 43d4e2c

Browse files
committed
feat: enable access to vue email config inside code
1 parent c718ea2 commit 43d4e2c

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

playground/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const tokens = await codeToThemedTokens('<div class="foo">bar</div>', {
2525
<Suspense>
2626
<ECodeBlock style="padding: 20px;" :code="code" lang="typescript" theme="dracula" show-line-numbers :highlighted-lines="[4, 5]" />
2727
</Suspense>
28-
<ECodeInline>@vue-email/nuxt</ECodeInline>
28+
<!-- <ECodeInline>@vue-email/nuxt</ECodeInline> -->
2929
<iframe :srcdoc="email" />
3030
</template>
3131

playground/src/components/Test.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ const tokens = await codeToThemedTokens('<div class="foo">bar</div>', {
5454
<EText class="text-black text-[14px] leading-[24px]">
5555
Hello {{ username }},
5656
</EText>
57+
<EText class="text-black text-[14px] leading-[24px]">
58+
{{ $vueEmail }}
59+
</EText>
5760
<EText class="text-black text-[14px] leading-[24px]">
5861
<strong>bukinoshita</strong> (
5962
<ELink :href="`mailto:${invitedByEmail}`" class="text-blue-600 no-underline">

src/composables/render.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { renderToString } from 'vue/server-renderer'
44
import pretty from 'pretty'
55
import { cleanup, htmlToText } from '../utils'
66
import type { I18n } from '../types'
7+
import { config } from '../config'
78

89
export interface Options {
910
pretty?: boolean
@@ -70,6 +71,8 @@ export async function useRender(
7071
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7172
const app = createApp({ render: () => h(component) }, params?.props)
7273

74+
app.config.globalProperties.$vueEmail = config
75+
7376
await useI18n(app, params)
7477

7578
const markup = await renderToString(app)

src/plugin/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import { config } from '../config'
77

88
export const VueEmailPlugin: Plugin = {
99
install(app, options: VueEmailPluginOptions = {}) {
10-
if (options)
10+
if (options) {
1111
deepmerge<VueEmailPluginOptions>(config, options)
12+
app.config.globalProperties.$vueEmail = options
13+
}
1214

1315
Object.entries(components).forEach(([name, component]) => {
1416
app.component(name, component)

src/types/compiler.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ export interface I18n {
2424
}
2525

2626
export type DeepRequired<T> = Required<{ [P in keyof T]: DeepRequired<T[P]> }>
27+
28+
declare module 'vue' {
29+
interface ComponentCustomProperties {
30+
$vueEmail: VueEmailPluginOptions
31+
}
32+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy