boxwood 0.66.0 → 0.68.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 +24 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5,6 +5,10 @@ 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
+ }
8
12
  const fn = require(path)
9
13
  return {
10
14
  template() {
@@ -470,8 +474,28 @@ i18n.load = function () {
470
474
  }
471
475
  }
472
476
 
477
+ function component(fn, styles) {
478
+ function execute(a, b) {
479
+ if (typeof a === "string" || Array.isArray(a)) {
480
+ return fn({}, a)
481
+ }
482
+ return fn(a, b || [])
483
+ }
484
+ return function (a, b) {
485
+ const tree = execute(a, b)
486
+ if (styles) {
487
+ if (Array.isArray(tree)) {
488
+ return tree.concat(styles.css)
489
+ }
490
+ return [tree, styles.css]
491
+ }
492
+ return tree
493
+ }
494
+ }
495
+
473
496
  module.exports = {
474
497
  compile,
498
+ component,
475
499
  classes,
476
500
  doctype,
477
501
  escape: escapeHTML,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "0.66.0",
3
+ "version": "0.68.0",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "scripts": {