boxwood 0.67.0 → 0.69.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.
- package/index.js +45 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -457,6 +457,22 @@ function classes() {
|
|
|
457
457
|
return array.join(" ")
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
+
const yaml = {
|
|
461
|
+
load() {
|
|
462
|
+
const path = join(...arguments)
|
|
463
|
+
const content = readFileSync(path, "utf8")
|
|
464
|
+
return YAML.parse(content)
|
|
465
|
+
},
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const json = {
|
|
469
|
+
load() {
|
|
470
|
+
const path = join(...arguments)
|
|
471
|
+
const content = readFileSync(path, "utf8")
|
|
472
|
+
return JSON.parse(content)
|
|
473
|
+
},
|
|
474
|
+
}
|
|
475
|
+
|
|
460
476
|
function i18n(translations) {
|
|
461
477
|
return function translate(language, key) {
|
|
462
478
|
return translations[key][language]
|
|
@@ -465,17 +481,40 @@ function i18n(translations) {
|
|
|
465
481
|
|
|
466
482
|
i18n.load = function () {
|
|
467
483
|
const path = join(...arguments)
|
|
468
|
-
const
|
|
469
|
-
const data = path.endsWith(".yaml")
|
|
470
|
-
? YAML.parse(content)
|
|
471
|
-
: JSON.parse(content)
|
|
484
|
+
const data = path.endsWith(".yaml") ? yaml.load(path) : json.load(path)
|
|
472
485
|
return function translate(language, key) {
|
|
473
486
|
return data[key][language]
|
|
474
487
|
}
|
|
475
488
|
}
|
|
476
489
|
|
|
490
|
+
function component(fn, { styles, i18n } = {}) {
|
|
491
|
+
function execute(a, b) {
|
|
492
|
+
if (typeof a === "string" || Array.isArray(a)) {
|
|
493
|
+
return fn({}, a)
|
|
494
|
+
}
|
|
495
|
+
if (i18n) {
|
|
496
|
+
function translate(key) {
|
|
497
|
+
return i18n[key][a.language]
|
|
498
|
+
}
|
|
499
|
+
return fn({ ...a, translate }, b || [])
|
|
500
|
+
}
|
|
501
|
+
return fn(a, b || [])
|
|
502
|
+
}
|
|
503
|
+
return function (a, b) {
|
|
504
|
+
const tree = execute(a, b)
|
|
505
|
+
if (styles) {
|
|
506
|
+
if (Array.isArray(tree)) {
|
|
507
|
+
return tree.concat(styles.css)
|
|
508
|
+
}
|
|
509
|
+
return [tree, styles.css]
|
|
510
|
+
}
|
|
511
|
+
return tree
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
477
515
|
module.exports = {
|
|
478
516
|
compile,
|
|
517
|
+
component,
|
|
479
518
|
classes,
|
|
480
519
|
doctype,
|
|
481
520
|
escape: escapeHTML,
|
|
@@ -483,6 +522,8 @@ module.exports = {
|
|
|
483
522
|
raw,
|
|
484
523
|
css,
|
|
485
524
|
js,
|
|
525
|
+
yaml,
|
|
526
|
+
json,
|
|
486
527
|
tag,
|
|
487
528
|
i18n,
|
|
488
529
|
...nodes,
|