boxwood 0.68.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.
Files changed (2) hide show
  1. package/index.js +26 -5
  2. 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,20 +481,23 @@ function i18n(translations) {
465
481
 
466
482
  i18n.load = function () {
467
483
  const path = join(...arguments)
468
- const content = readFileSync(path, "utf8")
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
 
477
- function component(fn, styles) {
490
+ function component(fn, { styles, i18n } = {}) {
478
491
  function execute(a, b) {
479
492
  if (typeof a === "string" || Array.isArray(a)) {
480
493
  return fn({}, a)
481
494
  }
495
+ if (i18n) {
496
+ function translate(key) {
497
+ return i18n[key][a.language]
498
+ }
499
+ return fn({ ...a, translate }, b || [])
500
+ }
482
501
  return fn(a, b || [])
483
502
  }
484
503
  return function (a, b) {
@@ -503,6 +522,8 @@ module.exports = {
503
522
  raw,
504
523
  css,
505
524
  js,
525
+ yaml,
526
+ json,
506
527
  tag,
507
528
  i18n,
508
529
  ...nodes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "0.68.0",
3
+ "version": "0.69.0",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "scripts": {