@jaredwray/fumanchu 3.1.3 → 4.0.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/README.md +51 -36
- package/dist/index.cjs +2250 -0
- package/dist/index.d.cts +119 -0
- package/dist/index.d.ts +57 -21
- package/dist/index.js +2110 -2104
- package/package.json +21 -39
package/README.md
CHANGED
|
@@ -10,11 +10,12 @@ Handlebars + Helpers Together
|
|
|
10
10
|
[](https://github.com/jaredwray/fumanchu/blob/master/LICENSE)
|
|
11
11
|
[](https://npmjs.com/package/@jaredwray/fumanchu)
|
|
12
12
|
|
|
13
|
-
[Handlebars](https://github.com/handlebars-lang/handlebars.js) + [Handlebars-helpers](https://github.com/helpers/handlebars-helpers) (helpers are now maintained in this project) combined into a single package. Easily use it as a drop in replacement when using handlebars directly. More than
|
|
13
|
+
[Handlebars](https://github.com/handlebars-lang/handlebars.js) + [Handlebars-helpers](https://github.com/helpers/handlebars-helpers) (helpers are now maintained in this project) combined into a single package. Easily use it as a drop in replacement when using handlebars directly. More than 160 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project. Currently **189 helpers** in **20 categories**! 🎉
|
|
14
14
|
|
|
15
15
|
# Table of Contents
|
|
16
16
|
* [Using in Nodejs](#using-in-nodejs)
|
|
17
17
|
* [Just using Handlebar Helpers](#using-handlebars-helpers)
|
|
18
|
+
* [Migrating from v3 to v4](#migrating-from-v3-to-v4)
|
|
18
19
|
* [Helpers](https://fumanchu.org/docs/helpers/)
|
|
19
20
|
* [array](https://fumanchu.org/docs/helpers/array/)
|
|
20
21
|
* [code](https://fumanchu.org/docs/helpers/code/)
|
|
@@ -46,29 +47,11 @@ Handlebars + Helpers Together
|
|
|
46
47
|
npm install @jaredwray/fumanchu --save
|
|
47
48
|
```
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
var {handlebars, helpers} = require('@jaredwray/fumanchu');
|
|
51
|
-
helpers({ handlebars: handlebars });
|
|
52
|
-
var template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
53
|
-
var html = template({foo: 'bar'});
|
|
54
|
-
console.log(html);
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
If using it with es6 you can access `handlebars` and `helpers`:
|
|
58
|
-
|
|
59
|
-
```javascript
|
|
60
|
-
import {handlebars, helpers} from '@jaredwray/fumanchu';
|
|
61
|
-
helpers({ handlebars: handlebars });
|
|
62
|
-
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
63
|
-
const html = template({foo: 'bar'});
|
|
64
|
-
console.log(html);
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
If you want to just get an instance of handlebars via `createHandlebars` you can do the following **(it is async)**:
|
|
50
|
+
To use Handlebars with all the helpers:
|
|
68
51
|
|
|
69
52
|
```javascript
|
|
70
|
-
import {
|
|
71
|
-
const handlebars =
|
|
53
|
+
import {fumanchu} from '@jaredwray/fumanchu';
|
|
54
|
+
const handlebars = fumanchu(); // this will return handlebars with all the helpers
|
|
72
55
|
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
73
56
|
const html = template({foo: 'bar'});
|
|
74
57
|
console.log(html); // <p>Foo is bar</p>
|
|
@@ -80,17 +63,6 @@ It's just that easy! No need to add Handlebars to your project, it's already inc
|
|
|
80
63
|
|
|
81
64
|
If you only want to use handlebar helpers you can easily do that by doing the following:
|
|
82
65
|
|
|
83
|
-
```javascript
|
|
84
|
-
var {helpers} = require('@jaredwray/fumanchu');
|
|
85
|
-
var handlebars = require('handlebars');
|
|
86
|
-
var helpersFunction = await helpers();
|
|
87
|
-
helpersFunction({ handlebars: handlebars });
|
|
88
|
-
var fn = handlebars.compile('{{add value 5}}');
|
|
89
|
-
console.log(fn); // 10
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
If using it with es6 you can access `helpers` via destructuring:
|
|
93
|
-
|
|
94
66
|
```javascript
|
|
95
67
|
import {helpers} from '@jaredwray/fumanchu';
|
|
96
68
|
import handlebars from 'handlebars';
|
|
@@ -101,10 +73,53 @@ const html = template({foo: 'bar'});
|
|
|
101
73
|
console.log(html); // <p>Foo is bar</p>
|
|
102
74
|
```
|
|
103
75
|
|
|
104
|
-
|
|
105
|
-
clone the repository locally and run 'npm i' in the root. Now that you've set up your workspace, you're ready to contribute changes to the `fumanchu` repository you can refer to the [CONTRIBUTING](CONTRIBUTING.md) guide. If you have any questions please feel free to ask by creating an issue and label it `question`.
|
|
76
|
+
If using it with es6 you can access `handlebars` and `helpers`:
|
|
106
77
|
|
|
107
|
-
|
|
78
|
+
```javascript
|
|
79
|
+
import {handlebars, helpers} from '@jaredwray/fumanchu';
|
|
80
|
+
helpers({ handlebars: handlebars });
|
|
81
|
+
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
82
|
+
const html = template({foo: 'bar'});
|
|
83
|
+
console.log(html);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
# Using the Helper Registry
|
|
87
|
+
|
|
88
|
+
The helper registry allows you to manage and use Handlebars helpers more easily. You can register new helpers, filter existing ones, and access them in your templates.
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
import { HelperRegistry, handlebars } from '@jaredwray/fumanchu';
|
|
92
|
+
|
|
93
|
+
const registry = new HelperRegistry();
|
|
94
|
+
registry.register('eq', (a, b) => a === b);
|
|
95
|
+
registry.register('if', (condition, template) => condition ? template() : '');
|
|
96
|
+
const hbs = handlebars;
|
|
97
|
+
registry.load(hbs); // Load all helpers into Handlebars
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
If you want to do filtering you can use the `HelperFilter` on `load`:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
import { HelperRegistry, handlebars } from '@jaredwray/fumanchu';
|
|
104
|
+
|
|
105
|
+
const registry = new HelperRegistry();
|
|
106
|
+
registry.register('eq', (a, b) => a === b);
|
|
107
|
+
registry.register('if', (condition, template) => condition ? template() : '');
|
|
108
|
+
const hbs = handlebars;
|
|
109
|
+
registry.load(hbs, { names: ['if']}); // Load the helpers into Handlebars
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
In addition, we have made the helper functions have a compatibility such as `HelperRegistryCompatibility.NODEJS` or `HelperRegistryCompatibility.BROWSER`. This will allow you to filter out based on your environment!
|
|
113
|
+
|
|
114
|
+
# Migrating from v3 to v4
|
|
115
|
+
|
|
116
|
+
We have made some breaking changes in v4:
|
|
117
|
+
* We no longer support the legacy helpers that were in this project as we have migrated to a new helper system.
|
|
118
|
+
* `createHandlebars` is now deprecated in favor of just using `fumanchu()` and no more needing async.
|
|
119
|
+
* The `FumanchuOptions` has been changed on filtering and also now fully supported with `fumanchu()`
|
|
120
|
+
|
|
121
|
+
## How to Contribute
|
|
122
|
+
Clone the repository locally refer to the [CONTRIBUTING](CONTRIBUTING.md) guide. If you have any questions please feel free to ask by creating an issue and label it `question`.
|
|
108
123
|
|
|
109
124
|
## License and Copyright
|
|
110
125
|
[MIT](LICENSE) and codebase after 2023 will be copyright of Jared Wray.
|