diff --git a/DEPENDENCIES b/DEPENDENCIES new file mode 100644 index 0000000..3635f89 --- /dev/null +++ b/DEPENDENCIES @@ -0,0 +1,22 @@ +react-html-attributes is used here during code generation, under the terms of the MIT license: + + The MIT License (MIT) + Copyright (c) 2017 Jacky Ho + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. diff --git a/codegen/.gitignore b/codegen/.gitignore new file mode 100644 index 0000000..7a7b33a --- /dev/null +++ b/codegen/.gitignore @@ -0,0 +1,2 @@ +package-lock.json +node_modules diff --git a/codegen/index.js b/codegen/index.js new file mode 100644 index 0000000..68110fc --- /dev/null +++ b/codegen/index.js @@ -0,0 +1,58 @@ +const props = require('react-html-attributes'); +const voids = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']; +const types = { + "allowFullScreen": "Boolean", + "async": "Boolean", + "autoPlay": "Boolean", + "capture": "Boolean", + "checked": "Boolean", + "cols": "Number", + "controls": "Boolean", + "default": "Boolean", + "defer": "Boolean", + "disabled": "Boolean", + "formNoValidate": "Boolean", + "hidden": "Boolean", + "itemScope": "Boolean", + "loop": "Boolean", + "multiple": "Boolean", + "muted": "Boolean", + "noValidate": "Boolean", + "open": "Boolean", + "playsInline": "Boolean", + "readOnly": "Boolean", + "required": "Boolean", + "reversed": "Boolean", + "rowSpan": "Number", + "rows": "Number", + "scoped": "Boolean", + "seamless": "Boolean", + "selected": "Boolean", + "size": "Number", + "span": "Number", + "start": "Number", + "zoomAndPan": "String" +}; + +printRecord = (elProps) => ` + ( ${ elProps.map((p) => + `${p} :: ${types[p] || 'String'}`).join('\n , ') + } + )` + +props.elements.html + .map((e) =>` + type Props_${e} = ${ + props[e] + ? printRecord(props[e]) + : '()' + } + + ${e} + :: forall attrs attrs_ + . Union attrs attrs_ (SharedProps Props_${e})) + => Record attrs + -> Array JSX + -> JSX + ${e} = ${voids.indexOf(e) >= 0 ? 'createElementNoChildren' : 'createElement'} "${e}" +`).forEach((x) => console.log(x.replace(/^\n\ {4}/, '').replace(/\n\ {4}/g, '\n'))) diff --git a/codegen/package.json b/codegen/package.json new file mode 100644 index 0000000..9b57f88 --- /dev/null +++ b/codegen/package.json @@ -0,0 +1,10 @@ +{ + "name": "purescript-react-basic-codegen", + "version": "1.0.0", + "description": "", + "main": "index.js", + "author": "", + "dependencies": { + "react-html-attributes": "^1.4.1" + } +}