boxwood 0.68.0 → 0.69.1

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 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5,10 +5,6 @@ const toHash = require("string-hash")
5
5
  const YAML = require("yaml")
6
6
 
7
7
  async function compile(path) {
8
- if (process.env.NODE_ENV === "development") {
9
- const name = require.resolve(path)
10
- delete require.cache[name]
11
- }
12
8
  const fn = require(path)
13
9
  return {
14
10
  template() {
@@ -457,6 +453,22 @@ function classes() {
457
453
  return array.join(" ")
458
454
  }
459
455
 
456
+ const yaml = {
457
+ load() {
458
+ const path = join(...arguments)
459
+ const content = readFileSync(path, "utf8")
460
+ return YAML.parse(content)
461
+ },
462
+ }
463
+
464
+ const json = {
465
+ load() {
466
+ const path = join(...arguments)
467
+ const content = readFileSync(path, "utf8")
468
+ return JSON.parse(content)
469
+ },
470
+ }
471
+
460
472
  function i18n(translations) {
461
473
  return function translate(language, key) {
462
474
  return translations[key][language]
@@ -465,20 +477,23 @@ function i18n(translations) {
465
477
 
466
478
  i18n.load = function () {
467
479
  const path = join(...arguments)
468
- const content = readFileSync(path, "utf8")
469
- const data = path.endsWith(".yaml")
470
- ? YAML.parse(content)
471
- : JSON.parse(content)
480
+ const data = path.endsWith(".yaml") ? yaml.load(path) : json.load(path)
472
481
  return function translate(language, key) {
473
482
  return data[key][language]
474
483
  }
475
484
  }
476
485
 
477
- function component(fn, styles) {
486
+ function component(fn, { styles, i18n } = {}) {
478
487
  function execute(a, b) {
479
488
  if (typeof a === "string" || Array.isArray(a)) {
480
489
  return fn({}, a)
481
490
  }
491
+ if (i18n) {
492
+ function translate(key) {
493
+ return i18n[key][a.language]
494
+ }
495
+ return fn({ ...a, translate }, b || [])
496
+ }
482
497
  return fn(a, b || [])
483
498
  }
484
499
  return function (a, b) {
@@ -503,6 +518,8 @@ module.exports = {
503
518
  raw,
504
519
  css,
505
520
  js,
521
+ yaml,
522
+ json,
506
523
  tag,
507
524
  i18n,
508
525
  ...nodes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "0.68.0",
3
+ "version": "0.69.1",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "scripts": {