bajo-template 2.0.0 → 2.2.0

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.
Files changed (51) hide show
  1. package/.github/FUNDING.yml +13 -0
  2. package/.github/workflows/repo-lockdown.yml +24 -0
  3. package/.jsdoc.conf.json +42 -0
  4. package/LICENSE +0 -0
  5. package/README.md +49 -1
  6. package/docs/BajoTemplate.html +3 -0
  7. package/docs/data/search.json +1 -0
  8. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  9. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  10. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  11. package/docs/global.html +3 -0
  12. package/docs/index.html +3 -0
  13. package/docs/index.js.html +375 -0
  14. package/docs/scripts/core.js +725 -0
  15. package/docs/scripts/core.min.js +23 -0
  16. package/docs/scripts/resize.js +90 -0
  17. package/docs/scripts/search.js +265 -0
  18. package/docs/scripts/search.min.js +6 -0
  19. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  20. package/docs/scripts/third-party/fuse.js +9 -0
  21. package/docs/scripts/third-party/hljs-line-num-original.js +366 -0
  22. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  23. package/docs/scripts/third-party/hljs-original.js +5164 -0
  24. package/docs/scripts/third-party/hljs.js +1 -0
  25. package/docs/scripts/third-party/popper.js +5 -0
  26. package/docs/scripts/third-party/tippy.js +1 -0
  27. package/docs/scripts/third-party/tocbot.js +671 -0
  28. package/docs/scripts/third-party/tocbot.min.js +1 -0
  29. package/docs/static/bitcoin.jpeg +0 -0
  30. package/docs/static/home.md +23 -0
  31. package/docs/static/logo-ecosystem.png +0 -0
  32. package/docs/static/logo.png +0 -0
  33. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  34. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  35. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  36. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  37. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  38. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  39. package/extend/bajo/intl/en-US.json +0 -0
  40. package/extend/bajo/intl/id.json +0 -0
  41. package/extend/bajoTemplate/layout/default.html +0 -0
  42. package/extend/bajoTemplate/layout/email.html +0 -0
  43. package/extend/bajoTemplate/layout/email.id.html +0 -0
  44. package/extend/bajoTemplate/partial/script-block.html +0 -0
  45. package/extend/bajoTemplate/partial/style-block.html +0 -0
  46. package/index.js +40 -29
  47. package/lib/resolve-resource.js +8 -8
  48. package/package.json +35 -29
  49. package/wiki/CHANGES.md +5 -0
  50. package/wiki/CONFIG.md +3 -0
  51. package/wiki/CONTRIBUTING.md +5 -0
package/index.js CHANGED
@@ -2,13 +2,23 @@ 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
- return class BajoTemplate extends this.lib.Plugin {
14
+ /**
15
+ * BajoTemplate class
16
+ *
17
+ * @class
18
+ */
19
+ class BajoTemplate extends this.app.baseClass.Base {
9
20
  constructor () {
10
21
  super(pkgName, me.app)
11
- this.alias = 'tpl'
12
22
  this.config = {
13
23
  layout: {
14
24
  fallback: true
@@ -22,12 +32,12 @@ async function factory (pkgName) {
22
32
  }
23
33
 
24
34
  buildCompileImports = (lang) => {
25
- const _ = this.lib._
35
+ const _ = this.app.lib._
26
36
  return {
27
37
  _,
28
38
  _t: (text, ...args) => {
29
39
  const params = [...args, { lang }]
30
- return this.print.write(text, ...params)
40
+ return this.t(text, ...params)
31
41
  },
32
42
  _format: (val, type, opts = {}) => {
33
43
  opts.lang = opts.lang ?? lang
@@ -41,8 +51,8 @@ async function factory (pkgName) {
41
51
  if (!this.app.waibu) return input
42
52
  return this.app.waibu.routePath(input, opts)
43
53
  },
44
- _titleize: this.lib.aneka.titleize,
45
- _hasPlugin: name => this.app.bajo.pluginNames.includes(name),
54
+ _titleize: this.app.lib.aneka.titleize,
55
+ _hasPlugin: name => this.app.getAllNs().includes(name),
46
56
  _jsonStringify: this.app.waibuMpa.jsonStringify,
47
57
  _parseMarkdown: content => {
48
58
  if (!this.app.bajoMarkdown) return content
@@ -58,7 +68,7 @@ async function factory (pkgName) {
58
68
  }
59
69
 
60
70
  _clearLoopDetector = () => {
61
- const { omit } = this.lib._
71
+ const { omit } = this.app.lib._
62
72
  const now = Date.now()
63
73
  const omitted = []
64
74
  for (const groupId in this.loopDetector) {
@@ -69,7 +79,7 @@ async function factory (pkgName) {
69
79
  }
70
80
 
71
81
  _detectLoop = (tpl, file, opts) => {
72
- const { last } = this.lib._
82
+ const { last } = this.app.lib._
73
83
  if (opts.groupId) {
74
84
  if (this.loopDetector[opts.groupId]) {
75
85
  if (last(this.loopDetector[opts.groupId].file) === file && path.basename(file)[0] !== '~') {
@@ -87,8 +97,8 @@ async function factory (pkgName) {
87
97
 
88
98
  _render = async (tpl, locals = {}, opts = {}) => {
89
99
  this._clearLoopDetector()
90
- const { trim, isEmpty, last } = this.lib._
91
- const { fs } = this.lib
100
+ const { trim, isEmpty, last } = this.app.lib._
101
+ const { fs } = this.app.lib
92
102
  const { breakNsPath } = this.app.bajo
93
103
 
94
104
  let resp
@@ -122,8 +132,8 @@ async function factory (pkgName) {
122
132
  }
123
133
 
124
134
  _handleInclude = async (content, locals = {}, opts = {}) => {
125
- const { isEmpty, omit, template, merge } = this.lib._
126
- const { extractText } = this.lib.aneka
135
+ const { isEmpty, omit, template, merge } = this.app.lib._
136
+ const { extractText } = this.app.lib.aneka
127
137
  const { breakNsPath } = this.app.bajo
128
138
  const start = '<!-- include '
129
139
  const end = ' -->'
@@ -158,7 +168,7 @@ async function factory (pkgName) {
158
168
  }
159
169
 
160
170
  _renderString = async (content, locals = {}, opts = {}) => {
161
- const { merge, without, isString, omit, kebabCase } = this.lib._
171
+ const { merge, without, isString, omit, kebabCase } = this.app.lib._
162
172
  if (opts.ext === '.md' && this.app.bajoMarkdown) {
163
173
  content = await this.compile(content, locals, { lang: opts.lang, ttl: -1 }) // markdown can't process template tags, hence preprocess here
164
174
  content = this.app.bajoMarkdown.parse(content)
@@ -193,7 +203,7 @@ async function factory (pkgName) {
193
203
  }
194
204
  if (layoutFm.title && !locals.page.title) locals.page.title = layoutFm.title
195
205
  content = layoutContent.replace('<!-- body -->', content)
196
- const appTitle = this.print.write(locals.page.appTitle, { lang: opts.lang })
206
+ const appTitle = this.t(locals.page.appTitle, { lang: opts.lang })
197
207
  const fullTitle = locals.page.title ? `${locals.page.title} - ${appTitle}` : appTitle
198
208
  locals.page.fullTitle = locals.fullTitle ?? fullTitle
199
209
  }
@@ -212,9 +222,9 @@ async function factory (pkgName) {
212
222
  }
213
223
 
214
224
  parseFrontMatter = async (input = '', lang) => {
215
- const { isEmpty, isPlainObject, isArray, filter, map } = this.lib._
216
- const { parseObject } = this.app.bajo
217
- const handlers = map(filter(this.app.bajo.configHandlers, h => !['.js'].includes(h.ext)), h => h.readHandler)
225
+ const { isEmpty, isPlainObject, isArray, filter, map } = this.app.lib._
226
+ const { parseObject } = this.app.lib
227
+ const handlers = map(filter(this.app.configHandlers, h => !['.js'].includes(h.ext)), h => h.readHandler)
218
228
  let success
219
229
  for (const handler of handlers) {
220
230
  if (success) break
@@ -230,8 +240,7 @@ async function factory (pkgName) {
230
240
 
231
241
  compile = async (content, locals, { lang, ttl = 0 } = {}) => {
232
242
  locals.attr = locals.attr ?? {}
233
- const _ = this.lib._
234
- const { template } = _
243
+ const { template } = this.app.lib._
235
244
  const cache = this.app.bajoCache
236
245
  let canCache = this.config.cache !== false && cache && this.app.bajo.config.env !== 'dev'
237
246
  if (ttl === -1) canCache = false
@@ -258,7 +267,7 @@ async function factory (pkgName) {
258
267
 
259
268
  render = async (tpl, locals = {}, opts = {}) => {
260
269
  const { runHook, breakNsPath } = this.app.bajo
261
- const { upperFirst } = this.lib._
270
+ const { upperFirst } = this.app.lib._
262
271
  const cache = this.app.bajoCache
263
272
  const key = crypto.createHash('md5').update(`${tpl}:${JSON.stringify(locals)}`).digest('hex')
264
273
  let subNs
@@ -269,43 +278,43 @@ async function factory (pkgName) {
269
278
  const item = await cache.get({ key })
270
279
  if (item) return item
271
280
  }
272
- if (subNs) await runHook(`${this.name}:beforeRender${upperFirst(subNs)}`, { tpl, locals, opts })
281
+ if (subNs) await runHook(`${this.ns}:beforeRender${upperFirst(subNs)}`, { tpl, locals, opts })
273
282
  let text = await this._render(tpl, locals, opts)
274
283
  if (opts.postProcessor) text = await opts.postProcessor({ text, locals, opts })
275
- if (subNs) await runHook(`${this.name}:afterRender${upperFirst(subNs)}`, { tpl, locals, opts, text })
284
+ if (subNs) await runHook(`${this.ns}:afterRender${upperFirst(subNs)}`, { tpl, locals, opts, text })
276
285
  if (canCache) await cache.set({ key, value: text, ttl: opts.cacheMaxAge ?? this.config.cache.maxAgeDur })
277
286
  return text
278
287
  }
279
288
 
280
289
  resolveLayout = (item = '', opts = {}) => {
281
- const { find } = this.lib._
290
+ const { find } = this.app.lib._
282
291
  const fallbackHandler = ({ file, exts, ns, subSubNs, type, theme }) => {
283
292
  const dir = ''
284
293
  const base = 'default'
285
294
  if (!this.config.layout.fallback) return false
286
295
  // check main: theme specific
287
296
  if (theme && !file) {
288
- const check = `${this.app.main.dir.pkg}/extend/${this.name}/${type}/_${theme}`
297
+ const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${type}/_${theme}`
289
298
  file = filecheck.call(this, { dir, base, exts, check })
290
299
  }
291
300
  // check main: common
292
301
  if (!file) {
293
- const check = `${this.app.main.dir.pkg}/extend/${this.name}/${type}`
302
+ const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${type}`
294
303
  file = filecheck.call(this, { dir, base, exts, check })
295
304
  }
296
305
  if (theme && !file) {
297
306
  const otheme = find(this.app.waibuMpa.themes, { name: theme })
298
- const check = `${otheme.plugin.dir.pkg}/extend/${this.name}/extend/${this.name}/${type}`
307
+ const check = `${otheme.plugin.dir.pkg}/extend/${this.ns}/extend/${this.ns}/${type}`
299
308
  file = filecheck.call(this, { dir, base, exts, check })
300
309
  }
301
310
  // check fallback: common
302
311
  if (!file) {
303
- const check = `${this.app[ns].dir.pkg}/extend/${this.name}/${subSubNs ? (subSubNs + '/') : ''}${type}`
312
+ const check = `${this.app[ns].dir.pkg}/extend/${this.ns}/${subSubNs ? (subSubNs + '/') : ''}${type}`
304
313
  file = filecheck.call(this, { dir, base, exts, check })
305
314
  }
306
315
  // check general fallback
307
316
  if (!file) {
308
- const check = `${this.dir.pkg}/extend/${this.name}/${subSubNs ? (subSubNs + '/') : ''}${type}`
317
+ const check = `${this.dir.pkg}/extend/${this.ns}/${subSubNs ? (subSubNs + '/') : ''}${type}`
309
318
  file = filecheck.call(this, { dir, base, exts, check })
310
319
  }
311
320
  return file
@@ -323,7 +332,7 @@ async function factory (pkgName) {
323
332
  }
324
333
 
325
334
  splitContent = (input, readFile) => {
326
- const { fs } = this.lib
335
+ const { fs } = this.app.lib
327
336
  const start = '---\n'
328
337
  const end = '\n---'
329
338
 
@@ -353,6 +362,8 @@ async function factory (pkgName) {
353
362
  return output
354
363
  }
355
364
  }
365
+
366
+ return BajoTemplate
356
367
  }
357
368
 
358
369
  export default factory
@@ -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}/extend/${this.name}/extend/${ns}/${type}/_${opts.theme}`
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}/extend/${this.name}/extend/${ns}/${type}`
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}/extend/${this.name}/extend/${ns}/${extension}${type}`
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}/extend/${this.name}/${extension}${type}/_${opts.theme}`
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}/extend/${this.name}/${extension}${type}`
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,35 @@
1
- {
2
- "name": "bajo-template",
3
- "version": "2.0.0",
4
- "description": "Template Renderer for Bajo Framework",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "type": "module",
10
- "bajo": {
11
- "type": "plugin"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/ardhi/bajo-template.git"
16
- },
17
- "keywords": [
18
- "template",
19
- "bajo",
20
- "framework",
21
- "modular"
22
- ],
23
- "author": "Ardhi Lukianto <ardhi@lukianto.com>",
24
- "license": "MIT",
25
- "bugs": {
26
- "url": "https://github.com/ardhi/bajo-template/issues"
27
- },
28
- "homepage": "https://github.com/ardhi/bajo-template#readme"
29
- }
1
+ {
2
+ "name": "bajo-template",
3
+ "version": "2.2.0",
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
+ "alias": "tpl"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ardhi/bajo-template.git"
18
+ },
19
+ "keywords": [
20
+ "template",
21
+ "bajo",
22
+ "framework",
23
+ "modular"
24
+ ],
25
+ "author": "Ardhi Lukianto <ardhi@lukianto.com>",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/ardhi/bajo-template/issues"
29
+ },
30
+ "homepage": "https://github.com/ardhi/bajo-template#readme",
31
+ "devDependencies": {
32
+ "clean-jsdoc-theme": "^4.3.0",
33
+ "jsdoc-plugin-intersection": "^1.0.4"
34
+ }
35
+ }
@@ -0,0 +1,5 @@
1
+ # Changes
2
+
3
+ ## 2025-12-30
4
+
5
+ - [2.1.0] Ported to match ```bajo@2.2.x``` specs
package/wiki/CONFIG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Config Object
2
+
3
+ TBD
@@ -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.