waibu 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import buildLocals from '../../lib/build-locals.js'
2
+
3
+ async function sendMail (tpl, { to, cc, bcc, from, subject, data = {}, conn, options = {} }) {
4
+ if (!this.app.masohiMail) return
5
+ const { get, isString } = this.app.bajo.lib._
6
+ const { generateId } = this.app.bajo
7
+ const { render } = this.app.bajoTemplate
8
+ if (isString(tpl)) tpl = [tpl]
9
+ const locals = await buildLocals.call(this, { tpl, params: data, opts: options })
10
+ const opts = {
11
+ lang: get(options, 'req.lang'),
12
+ groupId: get(options, 'req.id', generateId())
13
+ }
14
+ const message = await render(tpl[0], locals, opts)
15
+ if (tpl[1]) opts.messageText = await render(tpl[1], locals, opts)
16
+ await this.app.masohi.send({ to, cc, bcc, from, subject, message, conn, options: opts })
17
+ }
18
+
19
+ export default sendMail
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <head lang="<%= _meta.lang %>">
3
+ <meta charset="UTF-8">
4
+ <title><%= page.fullTitle %></title>
5
+ <style type="text/css">
6
+ </style>
7
+ </head>
8
+ <body>
9
+ <% if (arguments[0].firstName && arguments[0].lastName) { %>
10
+ <p>Dear <%= firstName %> <%= lastName %>,</p>
11
+ <% } %>
12
+ <!-- body -->
13
+ <p>Sincerely,</p>
14
+
15
+ <p><%= _meta.site.title %></p>
16
+ </body>
17
+ </html>
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html lang="<%= _meta.lang %>">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title><%= page.fullTitle %></title>
6
+ <style type="text/css">
7
+ </style>
8
+ </head>
9
+ <body>
10
+ <% if (arguments[0].firstName && arguments[0].lastName) { %>
11
+ <p>Yth <%= firstName %> <%= lastName %>,</p>
12
+ <% } %>
13
+ <!-- body -->
14
+ <p>Hormat kami,</p>
15
+
16
+ <p><%= _meta.site.title %></p>
17
+ </body>
18
+ </html>
@@ -0,0 +1,46 @@
1
+ function buildHomesMenu () {
2
+ const { get, find, orderBy } = this.app.bajo.lib._
3
+ const routes = []
4
+ for (const ns of this.app.bajo.pluginNames) {
5
+ const href = get(this, `app.${ns}.config.waibuMpa.home`)
6
+ if (!href) continue
7
+ const item = { href, ns, title: get(this, `app.${ns}.config.waibu.title`, this.app[ns].title) }
8
+ if (!find(routes, { href })) routes.push(item)
9
+ }
10
+ return orderBy(routes, ['title'])
11
+ }
12
+
13
+ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
14
+ const { runHook } = this.app.bajo
15
+ const { set, merge, pick, get, isEmpty, find } = this.app.bajo.lib._
16
+ const { req, reply } = opts
17
+
18
+ const appTitle = this.app.waibuMpa ? this.app.waibuMpa.getAppTitle(req.ns) : undefined
19
+ params.page = merge(params.page ?? {}, { ns: req.ns, appTitle })
20
+ set(params, 'menu.homes', buildHomesMenu.call(this))
21
+
22
+ const { site, user, lang, darkMode } = req
23
+ const theme = pick(find(this.themes, { name: req.theme }) ?? {}, ['name', 'framework'])
24
+ const iconset = pick(find(this.iconsets, { name: req.iconset }) ?? {}, ['name'])
25
+ const routeOpts = get(req, 'routeOptions.config', {})
26
+ const _meta = { theme, iconset, site, user, lang, darkMode, routeOpts }
27
+ _meta.site = _meta.site ?? {}
28
+ merge(_meta, pick(req, ['url', 'params', 'query']))
29
+ _meta.env = this.app.bajo.config.env
30
+ _meta.url = _meta.url.split('?')[0].split('#')[0]
31
+ _meta.route = get(req, 'routeOptions.url')
32
+ _meta.template = tpl
33
+ _meta.hostHeader = req.headers.host
34
+ _meta.statusCode = 200
35
+ if (params.error) {
36
+ if (params.error.statusCode) _meta.statusCode = params.error.statusCode
37
+ _meta.errorMessage = params.error.message
38
+ }
39
+ if (reply && req.session && req.flash && !opts.partial) _meta.flash = reply.flash()
40
+ const merged = merge({}, params, { _meta })
41
+ await runHook(`${this.name}:afterBuildLocals`, merged, req)
42
+ if (!isEmpty(routeOpts.ns)) await runHook(`${this.name}.${routeOpts.ns}:afterBuildLocals`, merged, req)
43
+ return merged
44
+ }
45
+
46
+ export default buildLocals
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {