UNPKG

1.75 kBMarkdownView Raw
1# babel-plugin-yo-yoify
2
3Like [yo-yoify][], but as a Babel plugin. Transform [yo-yo][] or [bel][]
4template strings into raw document calls.
5
6## Example
7
8Using `babel --plugins yo-yoify | prettier --stdin`:
9
10**In**
11
12```js
13import bel from 'bel'
14
15const title = 'yo-yoify'
16const 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
27var _h, _button, _pageHeader;
28
29var _appendChild = require('yo-yoify/lib/appendChild');
30
31const title = 'yo-yoify';
32const 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
47npm install --save-dev babel-plugin-yo-yoify
48```
49
50## Usage
51
52Without options:
53
54```js
55// .babelrc
56{
57 "plugins": [
58 "yo-yoify"
59 ]
60}
61```
62
63With 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