")
11 | // => h('div', { id: 'foo' }, (state.name))
12 | ```
13 |
14 | ### Installation
15 |
16 | `npm i hyperviews`
17 |
18 | ### API
19 |
20 | `hyperviews(tmpl, mode, name, argstr)`
21 |
22 | - `tmpl` (required) - The template string.
23 | - `mode` - The output format. Can be one of [`raw`, `esm`, `cjs`, `browser`], or if any other value is passed the function is exported as a variable with that name. The default is `raw`.
24 | - `name` - The default output function name. The default is `view`.
25 | - `args` - The default function arguments. The default is `props state`.
26 |
27 |
28 | ### CLI
29 |
30 | Reads the template from stdin,
31 |
32 | `cat examples/test.html | hyperviews --mode esm --name foo --args bar > examples/test.js`
33 |
34 | See [more CLI examples](./test/cli.js)
35 |
36 |
37 |
38 | ## Template language
39 |
40 |
41 | ### Interpolation
42 |
43 | Use curly braces in attributes and text.
44 |
45 | ```html
46 |
47 |
48 | My name is {state.name} my age is {state.age} and I live at {state.address}
49 |
50 | ```
51 |
52 | See [more interpolation examples](./test/interpolation.js)
53 |
54 |
55 |
56 | ### Conditionals
57 |
58 | There are two forms of conditional.
59 |
60 | Using an `if` attribute.
61 |
62 | ```html
63 | Show Me!
64 | ```
65 |
66 | Or using tags ``, `` and ``
67 |
68 | ```html
69 |
70 |
71 | 1
72 |
73 | 2
74 |
75 | bar is neither 1 or 2, it's {state.bar}!
76 |
77 |
78 | ```
79 |
80 | `if` tags can be [nested](./test/conditionals.js#L84).
81 |
82 | See [more conditional examples](./test/conditionals.js)
83 |
84 |
85 |
86 | ### Iteration
87 |
88 | The `each` attribute can be used to repeat over items in an Array.
89 | Three additional variables are available during each iteration: `$value`, `$index` and `$target`.
90 |
91 | It supports keyed elements as shown here.
92 |
93 | ```html
94 |
205 |
206 | ```
207 |
208 | produces this output
209 |
210 | ```js
211 | function MyComponent (x, y, z) {
212 | return h('div', null, (x))
213 | }
214 | ```
215 |
216 |
217 |
218 | ### Components
219 |
220 | Components are declared with if the tag starts with a capital letter.
221 |
222 | ```html
223 |
224 |
225 |
226 | ```
227 |
228 | produces this output
229 |
230 | ```js
231 | h('div', null, h(MyComponent, { foo: 'bar' }))
232 | ```
233 |
234 |
235 | ### Module example
236 |
237 | How you structure your app is down to you.
238 | I like to keep js and html in separate files so a component might look like this:
239 |
240 | - MyComponent
241 | - view.html (The template file e.g. `