1 | # babel-plugin-yo-yoify
|
2 |
|
3 | Like [yo-yoify][], but as a Babel plugin. Transform [yo-yo][] or [bel][]
|
4 | template strings into raw document calls.
|
5 |
|
6 | ## Example
|
7 |
|
8 | Using `babel --plugins yo-yoify | prettier --stdin`:
|
9 |
|
10 | **In**
|
11 |
|
12 | ```js
|
13 | import bel from 'bel'
|
14 |
|
15 | const title = 'yo-yoify'
|
16 | const header = bel`
|
17 | <header id="page-header">
|
18 | <h1>${title}</h1>
|
19 | <button onclick=${event => alert('Hello world!')}>Click here</button>
|
20 | </header>
|
21 | `
|
22 | ```
|
23 |
|
24 | **Out**
|
25 |
|
26 | ```js
|
27 | var _h, _button, _pageHeader;
|
28 |
|
29 | var _appendChild = require('yo-yoify/lib/appendChild');
|
30 |
|
31 | const title = 'yo-yoify';
|
32 | const header = (_pageHeader = document.createElement(
|
33 | 'header'
|
34 | ), _pageHeader.setAttribute('id', 'page-header'), _appendChild(_pageHeader, [
|
35 | '\n ',
|
36 | (_h = document.createElement('h1'), _appendChild(_h, [title]), _h),
|
37 | '\n ',
|
38 | (_button = document.createElement('button'), _button.onclick = event =>
|
39 | alert('Hello world!'), _button.textContent = 'Click here', _button),
|
40 | '\n '
|
41 | ]), _pageHeader);
|
42 | ```
|
43 |
|
44 | ## Installation
|
45 |
|
46 | ```bash
|
47 | npm install --save-dev babel-plugin-yo-yoify
|
48 | ```
|
49 |
|
50 | ## Usage
|
51 |
|
52 | Without options:
|
53 |
|
54 | ```js
|
55 | // .babelrc
|
56 | {
|
57 | "plugins": [
|
58 | "yo-yoify"
|
59 | ]
|
60 | }
|
61 | ```
|
62 |
|
63 | With options:
|
64 |
|
65 | ```js
|
66 | // .babelrc
|
67 | {
|
68 | "plugins": [
|
69 | ["yo-yoify", {
|
70 | "appendChildModule": "yo-yoify/lib/appendChild"
|
71 | }]
|
72 | ]
|
73 | }
|
74 | ```
|
75 |
|
76 | ## Options
|
77 |
|
78 | - `appendChildModule` - Import path to a module that contains a function that
|
79 | appends different types of children to an element. By default, the function
|
80 | included with [yo-yoify][] is used. Signature: `appendChild(el, array)`,
|
81 | where the `array` can contain any JavaScript value.
|
82 |
|
83 | ## License
|
84 |
|
85 | [ISC][]
|
86 |
|
87 | [yo-yoify]: https://github.com/shama/yo-yoify
|
88 | [yo-yo]: https://github.com/maxogden/yo-yo
|
89 | [bel]: https://github.com/shama/bel
|
90 | [ISC]: ./LICENSE
|