bajo-template 1.2.5 → 2.0.1
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.
- package/.github/FUNDING.yml +13 -0
- package/.github/workflows/repo-lockdown.yml +24 -0
- package/.jsdoc.conf.json +42 -0
- package/README.md +49 -1
- package/docs/BajoTemplate.html +3 -0
- package/docs/data/search.json +1 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +3 -0
- package/docs/index.html +3 -0
- package/docs/index.js.html +375 -0
- package/docs/scripts/core.js +726 -0
- package/docs/scripts/core.min.js +23 -0
- package/docs/scripts/resize.js +90 -0
- package/docs/scripts/search.js +265 -0
- package/docs/scripts/search.min.js +6 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/scripts/third-party/hljs-original.js +5171 -0
- package/docs/scripts/third-party/hljs.js +1 -0
- package/docs/scripts/third-party/popper.js +5 -0
- package/docs/scripts/third-party/tippy.js +1 -0
- package/docs/scripts/third-party/tocbot.js +672 -0
- package/docs/scripts/third-party/tocbot.min.js +1 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +23 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/styles/clean-jsdoc-theme.min.css +1 -0
- package/index.js +42 -28
- package/lib/resolve-resource.js +8 -8
- package/package.json +34 -29
- package/wiki/CONFIG.md +3 -0
- package/wiki/CONTRIBUTING.md +5 -0
- /package/{bajo → extend/bajo}/intl/en-US.json +0 -0
- /package/{bajo → extend/bajo}/intl/id.json +0 -0
- /package/{bajoTemplate → extend/bajoTemplate}/layout/default.html +0 -0
- /package/{bajoTemplate → extend/bajoTemplate}/layout/email.html +0 -0
- /package/{bajoTemplate → extend/bajoTemplate}/layout/email.id.html +0 -0
- /package/{bajoTemplate → extend/bajoTemplate}/partial/script-block.html +0 -0
- /package/{bajoTemplate → extend/bajoTemplate}/partial/style-block.html +0 -0
package/index.js
CHANGED
|
@@ -2,13 +2,25 @@ import resolveResource, { filecheck } from './lib/resolve-resource.js'
|
|
|
2
2
|
import crypto from 'crypto'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Plugin factory
|
|
7
|
+
*
|
|
8
|
+
* @param {string} pkgName - NPM package name
|
|
9
|
+
* @returns {class}
|
|
10
|
+
*/
|
|
5
11
|
async function factory (pkgName) {
|
|
6
12
|
const me = this
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
/**
|
|
15
|
+
* BajoTemplate class
|
|
16
|
+
*
|
|
17
|
+
* @class
|
|
18
|
+
*/
|
|
19
|
+
class BajoTemplate extends this.app.pluginClass.base {
|
|
20
|
+
static alias = 'tpl'
|
|
21
|
+
|
|
9
22
|
constructor () {
|
|
10
23
|
super(pkgName, me.app)
|
|
11
|
-
this.alias = 'tpl'
|
|
12
24
|
this.config = {
|
|
13
25
|
layout: {
|
|
14
26
|
fallback: true
|
|
@@ -22,12 +34,12 @@ async function factory (pkgName) {
|
|
|
22
34
|
}
|
|
23
35
|
|
|
24
36
|
buildCompileImports = (lang) => {
|
|
25
|
-
const _ = this.lib._
|
|
37
|
+
const _ = this.app.lib._
|
|
26
38
|
return {
|
|
27
39
|
_,
|
|
28
40
|
_t: (text, ...args) => {
|
|
29
41
|
const params = [...args, { lang }]
|
|
30
|
-
return this.
|
|
42
|
+
return this.t(text, ...params)
|
|
31
43
|
},
|
|
32
44
|
_format: (val, type, opts = {}) => {
|
|
33
45
|
opts.lang = opts.lang ?? lang
|
|
@@ -41,8 +53,8 @@ async function factory (pkgName) {
|
|
|
41
53
|
if (!this.app.waibu) return input
|
|
42
54
|
return this.app.waibu.routePath(input, opts)
|
|
43
55
|
},
|
|
44
|
-
_titleize: this.lib.aneka.titleize,
|
|
45
|
-
_hasPlugin: name => this.app.
|
|
56
|
+
_titleize: this.app.lib.aneka.titleize,
|
|
57
|
+
_hasPlugin: name => this.app.getAllNs().includes(name),
|
|
46
58
|
_jsonStringify: this.app.waibuMpa.jsonStringify,
|
|
47
59
|
_parseMarkdown: content => {
|
|
48
60
|
if (!this.app.bajoMarkdown) return content
|
|
@@ -58,7 +70,7 @@ async function factory (pkgName) {
|
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
_clearLoopDetector = () => {
|
|
61
|
-
const { omit } = this.lib._
|
|
73
|
+
const { omit } = this.app.lib._
|
|
62
74
|
const now = Date.now()
|
|
63
75
|
const omitted = []
|
|
64
76
|
for (const groupId in this.loopDetector) {
|
|
@@ -69,7 +81,7 @@ async function factory (pkgName) {
|
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
_detectLoop = (tpl, file, opts) => {
|
|
72
|
-
const { last } = this.lib._
|
|
84
|
+
const { last } = this.app.lib._
|
|
73
85
|
if (opts.groupId) {
|
|
74
86
|
if (this.loopDetector[opts.groupId]) {
|
|
75
87
|
if (last(this.loopDetector[opts.groupId].file) === file && path.basename(file)[0] !== '~') {
|
|
@@ -87,8 +99,8 @@ async function factory (pkgName) {
|
|
|
87
99
|
|
|
88
100
|
_render = async (tpl, locals = {}, opts = {}) => {
|
|
89
101
|
this._clearLoopDetector()
|
|
90
|
-
const { trim, isEmpty, last } = this.lib._
|
|
91
|
-
const { fs } = this.lib
|
|
102
|
+
const { trim, isEmpty, last } = this.app.lib._
|
|
103
|
+
const { fs } = this.app.lib
|
|
92
104
|
const { breakNsPath } = this.app.bajo
|
|
93
105
|
|
|
94
106
|
let resp
|
|
@@ -122,8 +134,8 @@ async function factory (pkgName) {
|
|
|
122
134
|
}
|
|
123
135
|
|
|
124
136
|
_handleInclude = async (content, locals = {}, opts = {}) => {
|
|
125
|
-
const { isEmpty, omit, template, merge } = this.lib._
|
|
126
|
-
const { extractText } = this.lib.aneka
|
|
137
|
+
const { isEmpty, omit, template, merge } = this.app.lib._
|
|
138
|
+
const { extractText } = this.app.lib.aneka
|
|
127
139
|
const { breakNsPath } = this.app.bajo
|
|
128
140
|
const start = '<!-- include '
|
|
129
141
|
const end = ' -->'
|
|
@@ -158,7 +170,7 @@ async function factory (pkgName) {
|
|
|
158
170
|
}
|
|
159
171
|
|
|
160
172
|
_renderString = async (content, locals = {}, opts = {}) => {
|
|
161
|
-
const { merge, without, isString, omit, kebabCase } = this.lib._
|
|
173
|
+
const { merge, without, isString, omit, kebabCase } = this.app.lib._
|
|
162
174
|
if (opts.ext === '.md' && this.app.bajoMarkdown) {
|
|
163
175
|
content = await this.compile(content, locals, { lang: opts.lang, ttl: -1 }) // markdown can't process template tags, hence preprocess here
|
|
164
176
|
content = this.app.bajoMarkdown.parse(content)
|
|
@@ -193,7 +205,7 @@ async function factory (pkgName) {
|
|
|
193
205
|
}
|
|
194
206
|
if (layoutFm.title && !locals.page.title) locals.page.title = layoutFm.title
|
|
195
207
|
content = layoutContent.replace('<!-- body -->', content)
|
|
196
|
-
const appTitle = this.
|
|
208
|
+
const appTitle = this.t(locals.page.appTitle, { lang: opts.lang })
|
|
197
209
|
const fullTitle = locals.page.title ? `${locals.page.title} - ${appTitle}` : appTitle
|
|
198
210
|
locals.page.fullTitle = locals.fullTitle ?? fullTitle
|
|
199
211
|
}
|
|
@@ -205,16 +217,16 @@ async function factory (pkgName) {
|
|
|
205
217
|
const subNses = ['layout', 'template', 'partial']
|
|
206
218
|
const { ns, path, subNs, subSubNs, qs } = this.app.bajo.breakNsPath(name)
|
|
207
219
|
const plugin = this.app.bajo.getPlugin(ns)
|
|
208
|
-
const dir = `${plugin.dir.pkg}/bajoTemplate`
|
|
220
|
+
const dir = `${plugin.dir.pkg}/extend/bajoTemplate`
|
|
209
221
|
if (!subNses.includes(subNs)) throw this.error('unknownResource%s', name)
|
|
210
222
|
const fullPath = subSubNs ? `${dir}/${subSubNs}/${subNs}${path}` : `${dir}/${subNs}${path}`
|
|
211
223
|
return { ns, subNs, subSubNs, path, qs, fullPath }
|
|
212
224
|
}
|
|
213
225
|
|
|
214
226
|
parseFrontMatter = async (input = '', lang) => {
|
|
215
|
-
const { isEmpty, isPlainObject, isArray, filter, map } = this.lib._
|
|
227
|
+
const { isEmpty, isPlainObject, isArray, filter, map } = this.app.lib._
|
|
216
228
|
const { parseObject } = this.app.bajo
|
|
217
|
-
const handlers = map(filter(this.app.
|
|
229
|
+
const handlers = map(filter(this.app.configHandlers, h => !['.js'].includes(h.ext)), h => h.readHandler)
|
|
218
230
|
let success
|
|
219
231
|
for (const handler of handlers) {
|
|
220
232
|
if (success) break
|
|
@@ -230,7 +242,7 @@ async function factory (pkgName) {
|
|
|
230
242
|
|
|
231
243
|
compile = async (content, locals, { lang, ttl = 0 } = {}) => {
|
|
232
244
|
locals.attr = locals.attr ?? {}
|
|
233
|
-
const _ = this.lib._
|
|
245
|
+
const _ = this.app.lib._
|
|
234
246
|
const { template } = _
|
|
235
247
|
const cache = this.app.bajoCache
|
|
236
248
|
let canCache = this.config.cache !== false && cache && this.app.bajo.config.env !== 'dev'
|
|
@@ -258,7 +270,7 @@ async function factory (pkgName) {
|
|
|
258
270
|
|
|
259
271
|
render = async (tpl, locals = {}, opts = {}) => {
|
|
260
272
|
const { runHook, breakNsPath } = this.app.bajo
|
|
261
|
-
const { upperFirst } = this.lib._
|
|
273
|
+
const { upperFirst } = this.app.lib._
|
|
262
274
|
const cache = this.app.bajoCache
|
|
263
275
|
const key = crypto.createHash('md5').update(`${tpl}:${JSON.stringify(locals)}`).digest('hex')
|
|
264
276
|
let subNs
|
|
@@ -269,43 +281,43 @@ async function factory (pkgName) {
|
|
|
269
281
|
const item = await cache.get({ key })
|
|
270
282
|
if (item) return item
|
|
271
283
|
}
|
|
272
|
-
if (subNs) await runHook(`${this.
|
|
284
|
+
if (subNs) await runHook(`${this.ns}:beforeRender${upperFirst(subNs)}`, { tpl, locals, opts })
|
|
273
285
|
let text = await this._render(tpl, locals, opts)
|
|
274
286
|
if (opts.postProcessor) text = await opts.postProcessor({ text, locals, opts })
|
|
275
|
-
if (subNs) await runHook(`${this.
|
|
287
|
+
if (subNs) await runHook(`${this.ns}:afterRender${upperFirst(subNs)}`, { tpl, locals, opts, text })
|
|
276
288
|
if (canCache) await cache.set({ key, value: text, ttl: opts.cacheMaxAge ?? this.config.cache.maxAgeDur })
|
|
277
289
|
return text
|
|
278
290
|
}
|
|
279
291
|
|
|
280
292
|
resolveLayout = (item = '', opts = {}) => {
|
|
281
|
-
const { find } = this.lib._
|
|
293
|
+
const { find } = this.app.lib._
|
|
282
294
|
const fallbackHandler = ({ file, exts, ns, subSubNs, type, theme }) => {
|
|
283
295
|
const dir = ''
|
|
284
296
|
const base = 'default'
|
|
285
297
|
if (!this.config.layout.fallback) return false
|
|
286
298
|
// check main: theme specific
|
|
287
299
|
if (theme && !file) {
|
|
288
|
-
const check = `${this.app.main.dir.pkg}/${this.
|
|
300
|
+
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${type}/_${theme}`
|
|
289
301
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
290
302
|
}
|
|
291
303
|
// check main: common
|
|
292
304
|
if (!file) {
|
|
293
|
-
const check = `${this.app.main.dir.pkg}/${this.
|
|
305
|
+
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${type}`
|
|
294
306
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
295
307
|
}
|
|
296
308
|
if (theme && !file) {
|
|
297
309
|
const otheme = find(this.app.waibuMpa.themes, { name: theme })
|
|
298
|
-
const check = `${otheme.plugin.dir.pkg}/${this.
|
|
310
|
+
const check = `${otheme.plugin.dir.pkg}/extend/${this.ns}/extend/${this.ns}/${type}`
|
|
299
311
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
300
312
|
}
|
|
301
313
|
// check fallback: common
|
|
302
314
|
if (!file) {
|
|
303
|
-
const check = `${this.app[ns].dir.pkg}/${this.
|
|
315
|
+
const check = `${this.app[ns].dir.pkg}/extend/${this.ns}/${subSubNs ? (subSubNs + '/') : ''}${type}`
|
|
304
316
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
305
317
|
}
|
|
306
318
|
// check general fallback
|
|
307
319
|
if (!file) {
|
|
308
|
-
const check = `${this.dir.pkg}/${this.
|
|
320
|
+
const check = `${this.dir.pkg}/extend/${this.ns}/${subSubNs ? (subSubNs + '/') : ''}${type}`
|
|
309
321
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
310
322
|
}
|
|
311
323
|
return file
|
|
@@ -323,7 +335,7 @@ async function factory (pkgName) {
|
|
|
323
335
|
}
|
|
324
336
|
|
|
325
337
|
splitContent = (input, readFile) => {
|
|
326
|
-
const { fs } = this.lib
|
|
338
|
+
const { fs } = this.app.lib
|
|
327
339
|
const start = '---\n'
|
|
328
340
|
const end = '\n---'
|
|
329
341
|
|
|
@@ -353,6 +365,8 @@ async function factory (pkgName) {
|
|
|
353
365
|
return output
|
|
354
366
|
}
|
|
355
367
|
}
|
|
368
|
+
|
|
369
|
+
return BajoTemplate
|
|
356
370
|
}
|
|
357
371
|
|
|
358
372
|
export default factory
|
package/lib/resolve-resource.js
CHANGED
|
@@ -2,7 +2,7 @@ import _path from 'path'
|
|
|
2
2
|
const cache = {}
|
|
3
3
|
|
|
4
4
|
export function filecheck ({ check, dir, base, exts }) {
|
|
5
|
-
const { fs } = this.lib
|
|
5
|
+
const { fs } = this.app.lib
|
|
6
6
|
let file
|
|
7
7
|
for (const ext of exts) {
|
|
8
8
|
let path = `${check}/${dir}/${base}${ext}`
|
|
@@ -16,8 +16,8 @@ export function filecheck ({ check, dir, base, exts }) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function resolveResource (type, item = '', opts = {}, fallbackHandler) {
|
|
19
|
-
const { trim, uniq, find } = this.lib._
|
|
20
|
-
const { fs } = this.lib
|
|
19
|
+
const { trim, uniq, find } = this.app.lib._
|
|
20
|
+
const { fs } = this.app.lib
|
|
21
21
|
const env = this.app.bajo.config.env
|
|
22
22
|
if (env !== 'dev' && cache[item]) return cache[item]
|
|
23
23
|
|
|
@@ -34,30 +34,30 @@ function resolveResource (type, item = '', opts = {}, fallbackHandler) {
|
|
|
34
34
|
let file
|
|
35
35
|
// check main override: theme specific
|
|
36
36
|
if (opts.theme) {
|
|
37
|
-
const check = `${this.app.main.dir.pkg}/${this.
|
|
37
|
+
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/extend/${ns}/${type}/_${opts.theme}`
|
|
38
38
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
39
39
|
}
|
|
40
40
|
// check main override: common
|
|
41
41
|
if (!file) {
|
|
42
|
-
const check = `${this.app.main.dir.pkg}/${this.
|
|
42
|
+
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/extend/${ns}/${type}`
|
|
43
43
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
44
44
|
}
|
|
45
45
|
// check override: theme specific
|
|
46
46
|
if (opts.theme && !file) {
|
|
47
47
|
const theme = find(this.app.waibuMpa.themes, { name: opts.theme })
|
|
48
48
|
if (theme) {
|
|
49
|
-
const check = `${theme.plugin.dir.pkg}/${this.
|
|
49
|
+
const check = `${theme.plugin.dir.pkg}/extend/${this.ns}/extend/${ns}/${extension}${type}`
|
|
50
50
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
// check real: theme specific
|
|
54
54
|
if (opts.theme && !file) {
|
|
55
|
-
const check = `${this.app[ns].dir.pkg}/${this.
|
|
55
|
+
const check = `${this.app[ns].dir.pkg}/extend/${this.ns}/${extension}${type}/_${opts.theme}`
|
|
56
56
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
57
57
|
}
|
|
58
58
|
// check real: common
|
|
59
59
|
if (!file) {
|
|
60
|
-
const check = `${this.app[ns].dir.pkg}/${this.
|
|
60
|
+
const check = `${this.app[ns].dir.pkg}/extend/${this.ns}/${extension}${type}`
|
|
61
61
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
62
62
|
}
|
|
63
63
|
if (fallbackHandler) file = fallbackHandler.call(this, { file, dir, base, exts, ns, subSubNs, type, theme: opts.theme })
|
package/package.json
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "bajo-template",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Template Renderer for Bajo Framework",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "bajo-template",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Template Renderer for Bajo Framework",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build-doc": "jsdoc -c .jsdoc.conf.json",
|
|
8
|
+
"test": "mocha"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bajo": {
|
|
12
|
+
"type": "plugin"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/ardhi/bajo-template.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"template",
|
|
20
|
+
"bajo",
|
|
21
|
+
"framework",
|
|
22
|
+
"modular"
|
|
23
|
+
],
|
|
24
|
+
"author": "Ardhi Lukianto <ardhi@lukianto.com>",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/ardhi/bajo-template/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/ardhi/bajo-template#readme",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"clean-jsdoc-theme": "^4.3.0",
|
|
32
|
+
"jsdoc-plugin-intersection": "^1.0.4"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/wiki/CONFIG.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks very much to everyone who wants to join as a contributor, but I have committed to devoting 100% of my time to this project. Therefore, I'm currently unable to accept pull requests from anyone until the project is large enough for me to manage it independently.
|
|
4
|
+
|
|
5
|
+
However, I am available if you encounter any bugs that require immediate fixes. Please report your issues in a GitHub issue, and I'll try to address them promptly. I'm also open to criticism and suggestions for improvements or requests for new features.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|