Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ngcodex/js-generator

Generates JavaScript code from HTML or Custom tags
https://github.com/ngcodex/js-generator

dom generate-js html5 java javascript javase jsoup maven

Last synced: about 1 month ago
JSON representation

Generates JavaScript code from HTML or Custom tags

Awesome Lists containing this project

README

        

# API

Using [`httpie`](https://httpie.io/):
```shell
# You can also pass as many HTML content as you want
# Response will be of 'application/json' content type
http -vf :8080/convert \
extension='.js' \
contents[]='


' \
contents[]='click me, please :sob:'

HTTP/1.1 200
Content-Type: application/json

{
"status": "SUCCESS"
"content": [
{
"content": "const targetElement_000 = document.querySelector(`:root > body`);\r\n\r\n\r\nconst hr_000 = document.createElement('hr');\r\ntargetElement_000.appendChild(hr_000);\r\n",
"filename": "inline.0.js"
},
{
"content": "const targetElement_001 = document.querySelector(`:root > body`);\r\n\r\n\r\nconst button_000 = document.createElement('button');\r\nbutton_000.setAttribute(`disabled`, `true`);\r\nconst text_000 = document.createTextNode(`click me, please :sob:`);\r\nbutton_000.appendChild(text_000);\r\ntargetElement_001.appendChild(button_000);\r\n",
"filename": "inline.1.js"
}
]
}
```

Or, give the following two files contents:
> ```json
> { "extension": ".js" } // ./multipart-options.json
> ```
>
> ```html
>
>
>
>
> ...
> ...
> ...
> ```

```shell
# You can call the API with multiple **files** and at most one **options**
# Response will be of 'multipart/form-data' content type
http -vf :8080/convert/files \
'files@./sample.html;type=multipart/form-data' \
'[email protected];type=application/json'

HTTP/1.1 200
Content-Type: multipart/form-data;boundary=3N0wqEqnb7AC3WD8M1cYYG-vLfHDND_JdE90

--3N0wqEqnb7AC3WD8M1cYYG-vLfHDND_JdE90
Content-Disposition: form-data; name="0.sample.html.js"
Content-Type: application/octet-stream
Content-Length: 4156

const targetElement_000 = document.querySelector(`:root > body`);
[... truncated for brievity]
```

---

After starting the `jsgenerator-api` as described in the [README.md](./README.md), you can read:

+ OpenAPI spec. at: [http://localhost:8080/openapi.yaml](http://localhost:8080/openapi.yaml)
+ OpenAPI UI at: [http://localhost:8080](http://localhost:8080)

Two endpoints are exposed:
+ `POST /convert`
+ `POST /convert/files`

Both accept options as follow:
```json
{
"targetElementSelector": ":root > body",
"pattern": "inline-filename-pattern",
"variableNameStrategy": "TYPE_BASED",
"variableDeclaration": "LET",
"extension": ".extension",
"contents": [
"string"
]
}
```
> **NOTE:** The `"content"` field is mandatory for `POST /convert` and forbidden for `POST /convert/files`