Skip to content

Commit 67e8131

Browse files
authored
Merge pull request #2 from edcdavid/refactor-code-v0.0.2
* Clean code, separate HTML, Javascript and CSS code, add linters, support claim format v0.1.0 * documentation
2 parents cb9027f + c3ae151 commit 67e8131

File tree

15 files changed

+1499
-4146
lines changed

15 files changed

+1499
-4146
lines changed

.github/workflows/checkbuild.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: check result.html
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
workflow_dispatch:
8+
9+
jobs:
10+
check-result-html:
11+
name: check if result.html is up to date with index.html
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: install nodejs
16+
run: sudo apt-get update; sudo apt-get -y install nodejs npm; npm install inline-source
17+
- name: modify build sccript
18+
run: sed -i 's/results.html/test.html/g' html/build.js
19+
- name: generate test.html
20+
run: cd html; node build.js
21+
- name: compare results.html with test.html
22+
run: cd html;diff results.html test.html

.github/workflows/linters.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: linters
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
workflow_dispatch:
8+
9+
jobs:
10+
js-linter:
11+
name: Javascript linter (standard)
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Init yarn
16+
run: yarn init -y
17+
- name: Install standard modules
18+
run: yarn add standard
19+
- name: Run Standard
20+
run: yarn standard html/index.js
21+
css-linter:
22+
name: CSS linter (stylelint)
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- name: Init yarn
27+
run: yarn init -y
28+
- name: Install standard modules
29+
run: yarn add stylelint stylelint-config-standard
30+
- name: create stylelint config file
31+
run: |
32+
cat << EOF > .stylelintrc
33+
{ "extends": ["stylelint-config-standard"] }
34+
EOF
35+
- name: Run stylelint
36+
run: yarn stylelint html/*.css
37+
html-linter:
38+
name: HTML linter (html5validator)
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
- uses: Cyb3r-Jak3/[email protected]
43+
with:
44+
root: html/
45+
extra: --ignore inline

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build:
2+
cd html;node build.js

README.md

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,107 @@
11
# parser
2-
The HTML Parser helps parse claim.json files generated by the CNF suite of tests
2+
The HTML Parser helps parse claim.json files generated by the CNF suite of
3+
tests. The HTML parser does the following:
4+
- display results in a human readable way. Decoding failure reasons
5+
- annotate test results and download a shareable HTML page
6+
- save annotations to a file to be reused with other claim files
7+
- load claim files and annotation(feedback) files from local disk, uploaded by user or passed on the URL (HTML server only)
8+
9+
## Relationship between the claim format and parser release versions
10+
### The claim format version
11+
12+
A given parser release can only decode a single claim format version. The claim format version is defined as follows:
13+
- `v0.0.1` is the initial claim format version. It is used by the previous code before creating this repository
14+
- For newer versions, the minor version is incremented by 1 for each new claim format versions. The patch version is always zero.
15+
- The Major version is set to zero. The first claim format version supported by the parser in this repo is:`v0.1.0`
16+
17+
### The parser release version
18+
19+
The release version of the parser is based on the claim format version. The patch version is incremented by one for each new parser release supporting the same claim format version. For instance, a parser with a `v0.1.4` release version supports claim format `v0.1.0` and so is a release `v0.1.34`. A parser release 'v0.2.1' supports claim format `v0.2.0`.
20+
21+
## Project directory structure
22+
```
23+
├── doc
24+
├── html
25+
│   ├── build.js
26+
│   ├── index.js
27+
│   ├── results.html
28+
│   └── style.css
29+
├── LICENSE
30+
├── Makefile
31+
└── README.md
32+
```
33+
34+
`doc`: documentation
35+
36+
`html`: directory contains the HTML artifacts
37+
38+
`html/build.js`: nodejs script to merger HTML artifacts and minify
39+
40+
`html/index.js`: javascript component of the HTML page
41+
42+
`html/style.css`: CSS component of the HTML page
43+
44+
`LICENSE`: license file
45+
46+
`Makefile`: Makefile
47+
48+
`README.md`: README
49+
50+
## Uploading a previous feedback to the html parser page
51+
52+
Users can write notes or feedback about their test run in the HTML parser.
53+
This displayed results and feedback can be downloaded as a static HTML page to be shared.
54+
Users can also save their feedback as a json file for later use.
55+
To load a file containing previouly entered feedback, users can
56+
upload their `feedback.json` file to the parser HTML page via the `Upload Feedback File` button. Alternatively,
57+
users can convert their `feedback.json` to `feedback.js` and place it in the same folder as the result.html page.
58+
The feedback will be loaded automatically.
59+
60+
to convert a feedback.json to feedback.js, rename the file to `feedback.js` and prepend `var feedback=` to the `feedback.json file` from:
61+
```
62+
{"source-all-access-control-cluster-role-bindings":"test2","so
63+
```
64+
to:
65+
```
66+
var feedback={"source-all-access-control-cluster-role-bindings":"test2","so ...
67+
```
68+
69+
similarly the `claim.json` file can be automatically loaded, but first needs to be converted to a `claimjson.js` file.
70+
To do this first rename the `claim.json` file to `claimjson.js` then prepend `var initialjson=` to the renamed file:
71+
```
72+
{
73+
"claim": {
74+
"configurations": {
75+
```
76+
to
77+
```
78+
var initialjson = {
79+
"claim": {
80+
"configurations": {
81+
```
82+
## HTML Page modes
83+
84+
### Manually uploading claim and feedback files via the webpage
85+
86+
load the result.html or result-embed.html files locally and click on the "Choose File" button to pick the claim file to load:
87+
88+
![claim](doc/images/pick-claim.jpg)
89+
90+
Click on the "Upload Feedback File: Choose File" button to pick the feedback file to upload:
91+
92+
![feedback](doc/images/pick-feedback.jpg)
93+
94+
### Load local claimjson.js and feedback.js files
95+
96+
When it is loaded, the webpage also looks for the following properly formatted javascript files: claimjson.js and feedback.js.
97+
If present in the same directory as the webpage, both files are loaded to update the webpage content without user interaction. Delete the files to prevent auto-loading the results and feedback. Works for hosted pages and local pages.
98+
99+
### Load claim and feedback files via URL parameters
100+
101+
When the result.html or result-embed.html are hosted it is also possible to pass the url of a claim and a feedback file as follows:
102+
http://localhost/results-embed.html?claimfile=claim.json&feedback=feedback3.json
103+
104+
* the `claimfile=` parameter indicates the claim file to load
105+
* the `feedback=` parameter indicates the feedback file to load
106+
107+
Both files are loaded without user interaction.

doc/images/pick-claim.jpg

7.58 KB
Loading

doc/images/pick-feedback.jpg

5.71 KB
Loading

html/build.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const fs = require('fs');
2+
const inline = require('inline-source');
3+
4+
const htmlFile = 'index.html';
5+
const options = {
6+
compress: true, // minify
7+
};
8+
9+
inline.inlineSource(htmlFile, options)
10+
.then((html) => {
11+
fs.writeFileSync('results.html', html);
12+
console.log('Build successful!');
13+
})
14+
.catch((err) => {
15+
console.error('Error during build:', err);
16+
});

0 commit comments

Comments
 (0)