@opengis/admin 0.2.129 → 0.2.131

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,8 @@ import tableList from "./list/tableList.js";
7
7
  import buttonHelper from "./core/buttonHelper.js";
8
8
  import select from "./core/select.js";
9
9
  import badge from "./core/badge.js";
10
+ import coalesce from "./core/coalesce.js";
11
+ import mdToHTML from "./utils/mdToHTML.js";
10
12
 
11
13
 
12
14
  import ifCond from "./temp/ifCond.js";
@@ -17,6 +19,7 @@ import contentList from "./temp/contentList.js";
17
19
  export default async function route() {
18
20
 
19
21
  handlebars.registerHelper('token', token);
22
+ handlebars.registerHelper('mdToHTML', mdToHTML);
20
23
  handlebars.registerHelper('descriptionList', descriptionList);
21
24
  handlebars.registerHelper('tableList', tableList);
22
25
  handlebars.registerHelper('button', buttonHelper);
@@ -28,4 +31,6 @@ export default async function route() {
28
31
  handlebars.registerHelper('ifCond', ifCond);
29
32
  handlebars.registerHelper('empty', () => { });
30
33
  handlebarsSync.registerHelper('empty', () => { });
34
+ handlebars.registerHelper('coalesce', coalesce);
35
+ handlebarsSync.registerHelper('coalesce', coalesce);
31
36
  }
@@ -1,16 +1,17 @@
1
- import { handlebarsSync, handlebars } from '@opengis/fastify-table/utils.js'
1
+ import { config, handlebarsSync, handlebars } from '@opengis/fastify-table/utils.js'
2
2
 
3
- function format(d, key, data) {
3
+ async function format(d, key, data) {
4
4
  if (!key?.includes) return '';
5
5
  if (d === true) return 'Так';
6
- if (d === false) return 'Ні'
6
+ if (d === false) return 'Ні';
7
7
 
8
8
  if (key.startsWith('{{') && key.match(/\{\{([^\s]+)/)?.[1] in handlebarsSync.helpers) {
9
9
  return handlebarsSync.compile(key)(data);
10
- } else if (key.startsWith('{{') && key.includes(' ') && !(key.match(/\{\{([^\s]+)/)?.[1] in handlebars.helpers)) {
11
- return null;
10
+ } else if (key.startsWith('{{')) {
11
+ return handlebars.compile(key)(data);
12
12
  }
13
13
 
14
+ // if (config.local && config.debug) console.log('descriptionList:d', d, key, data);
14
15
  if (!d) return null;
15
16
  return d;
16
17
  }
@@ -29,15 +30,17 @@ export default async function descriptionList(data, opt) {
29
30
 
30
31
  for (let i = 0; i < keys.length; i += 2) {
31
32
  const name = keys[i];
32
- const nameHBS = name.includes('{{') ? handlebarsSync.compile(name)({ ...data, hash }) : false
33
+ const nameHBS = name.includes('{{') ? await handlebars.compile(name)({ ...data, hash }) : false;
33
34
 
34
35
  if (!nameHBS && name.includes('{{')) continue;
35
36
 
36
37
  const key = keys[i + 1];
37
38
 
38
- const d1 = format(data[key], key, data)
39
- || (key.includes('{{') ? await handlebars.compile(key)(data) : '-')
40
- || '-';
39
+ const d1 = await format(data[key], key, data) || '-';
40
+
41
+ if (config.local && config.debug && d1 === '-') {
42
+ // console.log('descriptionList:for', name, nameHBS, key, data);
43
+ }
41
44
 
42
45
  result.push(`<div class="grid grid-cols-1 gap-1 py-3 sm:grid-cols-3 sm:gap-4">
43
46
  <dt class="text-gray-900">${nameHBS || name}</dt>
@@ -0,0 +1,17 @@
1
+ import md from 'markdown-it';
2
+
3
+ const md1 = md({ html: true });
4
+
5
+ /**
6
+ * Перетворення з файла readme.md до формату HTML.
7
+ * Потрабно вставити в хелпер шлях до файла або текст readme.md і за допомогою бібліотеки markdown-it перетвориться в HTML.
8
+
9
+ * @returns {String} Returns HTML
10
+ */
11
+ export default function mdToHTML(data, options) {
12
+ // auto detect HTML or MD
13
+ // const result = md().render(data);
14
+ if (!data) return 'empty data';
15
+ const result = md1.render(data);
16
+ return result;
17
+ };