Skip to content

Commit 242f827

Browse files
authored
Merge pull request #5 from lumihq/codegen
Add code generator
2 parents bfbb49d + 82839fa commit 242f827

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

Diff for: DEPENDENCIES

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
react-html-attributes is used here during code generation, under the terms of the MIT license:
2+
3+
The MIT License (MIT)
4+
Copyright (c) 2017 Jacky Ho
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

Diff for: codegen/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock.json
2+
node_modules

Diff for: codegen/index.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const props = require('react-html-attributes');
2+
const voids = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
3+
const types = {
4+
"allowFullScreen": "Boolean",
5+
"async": "Boolean",
6+
"autoPlay": "Boolean",
7+
"capture": "Boolean",
8+
"checked": "Boolean",
9+
"cols": "Number",
10+
"controls": "Boolean",
11+
"default": "Boolean",
12+
"defer": "Boolean",
13+
"disabled": "Boolean",
14+
"formNoValidate": "Boolean",
15+
"hidden": "Boolean",
16+
"itemScope": "Boolean",
17+
"loop": "Boolean",
18+
"multiple": "Boolean",
19+
"muted": "Boolean",
20+
"noValidate": "Boolean",
21+
"open": "Boolean",
22+
"playsInline": "Boolean",
23+
"readOnly": "Boolean",
24+
"required": "Boolean",
25+
"reversed": "Boolean",
26+
"rowSpan": "Number",
27+
"rows": "Number",
28+
"scoped": "Boolean",
29+
"seamless": "Boolean",
30+
"selected": "Boolean",
31+
"size": "Number",
32+
"span": "Number",
33+
"start": "Number",
34+
"zoomAndPan": "String"
35+
};
36+
37+
printRecord = (elProps) => `
38+
( ${ elProps.map((p) =>
39+
`${p} :: ${types[p] || 'String'}`).join('\n , ')
40+
}
41+
)`
42+
43+
props.elements.html
44+
.map((e) =>`
45+
type Props_${e} = ${
46+
props[e]
47+
? printRecord(props[e])
48+
: '()'
49+
}
50+
51+
${e}
52+
:: forall attrs attrs_
53+
. Union attrs attrs_ (SharedProps Props_${e}))
54+
=> Record attrs
55+
-> Array JSX
56+
-> JSX
57+
${e} = ${voids.indexOf(e) >= 0 ? 'createElementNoChildren' : 'createElement'} "${e}"
58+
`).forEach((x) => console.log(x.replace(/^\n\ {4}/, '').replace(/\n\ {4}/g, '\n')))

Diff for: codegen/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "purescript-react-basic-codegen",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"author": "",
7+
"dependencies": {
8+
"react-html-attributes": "^1.4.1"
9+
}
10+
}

0 commit comments

Comments
 (0)