bajo-template 1.1.8 → 1.1.9

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,13 @@
1
+ <script>
2
+ <%= block.root.join('\n') %>
3
+ <% if (block.alpineInitializing) { %>
4
+ document.addEventListener('alpine:initializing', () => {
5
+ <%= block.alpineInitializing.join('\n') %>
6
+ })
7
+ <% } %>
8
+ <% if (block.alpineInit) { %>
9
+ document.addEventListener('alpine:init', () => {
10
+ <%= block.alpineInit.join('\n') %>
11
+ })
12
+ <% } %>
13
+ </script>
@@ -0,0 +1,5 @@
1
+ <style>
2
+ <% for (const b in block) { %>
3
+ <%= block[b].join('\n') %>
4
+ <% } %>
5
+ </style>
@@ -17,6 +17,7 @@ export function filecheck ({ check, dir, base, exts }) {
17
17
 
18
18
  function resolveResource (type, item = '', opts = {}, fallbackHandler) {
19
19
  const { trim, uniq, find } = this.lib._
20
+ const { fs } = this.lib
20
21
  const env = this.app.bajo.config.env
21
22
  if (env !== 'dev' && cache[item]) return cache[item]
22
23
 
@@ -60,6 +61,10 @@ function resolveResource (type, item = '', opts = {}, fallbackHandler) {
60
61
  file = filecheck.call(this, { dir, base, exts, check })
61
62
  }
62
63
  if (fallbackHandler) file = fallbackHandler.call(this, { file, dir, base, exts, ns, subSubNs, type, theme: opts.theme })
64
+ if (opts.default) {
65
+ const fname = this.getResource(opts.default).fullPath
66
+ if (fs.existsSync(fname)) file = fname
67
+ }
63
68
  if (!file) throw this.error('cantFind%s%s', type, item)
64
69
  const result = { file, ns, layout: opts.layout }
65
70
  if (env !== 'dev') cache[item] = result
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo-template",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Template Renderer for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin/factory.js CHANGED
@@ -139,7 +139,7 @@ async function factory (pkgName) {
139
139
  }
140
140
 
141
141
  _renderString = async (content, locals = {}, opts = {}) => {
142
- const { merge, without, isString, omit } = this.lib._
142
+ const { merge, without, isString, omit, kebabCase } = this.lib._
143
143
  if (opts.ext === '.md' && this.app.bajoMarkdown) {
144
144
  content = await this.compile(content, locals, { lang: opts.lang, ttl: -1 }) // markdown can't process template tags, hence preprocess here
145
145
  content = this.app.bajoMarkdown.parse(content)
@@ -148,8 +148,13 @@ async function factory (pkgName) {
148
148
  if (!opts.partial) {
149
149
  const pageFm = await this.parseFrontMatter(opts.frontMatter, opts.lang)
150
150
  if (pageFm.layout) opts.layout = pageFm.layout
151
+ if (pageFm.scriptBlock) opts.scriptBlock = pageFm.scriptBlock
152
+ if (pageFm.styleBlock) opts.styleBlock = pageFm.styleBlock
151
153
  locals.page = merge({}, locals.page, omit(pageFm, ['layout']))
152
154
  layout = opts.layout ?? locals.page.layout ?? (locals.page.ns ? `${locals.page.ns}.layout:/default.html` : 'main.layout:/default.html')
155
+ for (const b of ['scriptBlock', 'styleBlock']) {
156
+ locals.page[b] = pageFm[b] ?? opts[b] ?? (locals.page.ns ? `${locals.page.ns}.partial:/${kebabCase(b)}.html` : `bajoTemplate.partial:/${kebabCase(b)}.html`)
157
+ }
153
158
  const ext = path.extname(layout)
154
159
  const { file } = this.resolveLayout(layout, opts)
155
160
  let { content: layoutContent, frontMatter: layoutFm } = this.splitContent(file, true)