Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit e5e2c3b

Browse files
committed
docs: service: http: Clean up JavaScript example
* Create docs page for HTTP service JavaScript example * Fix port assignment for http service * Add static file serving to HTTP service * Add serving api.js from HTTP service * Lint files with js-beautify * Enforce linting in CI style check Signed-off-by: John Andersen <[email protected]>
1 parent 454bbd8 commit e5e2c3b

File tree

19 files changed

+310
-217
lines changed

19 files changed

+310
-217
lines changed

.ci/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ function run_whitespace() {
118118

119119
function run_style() {
120120
black --check "${SRC_ROOT}"
121+
122+
for filename in $(git ls-files \*.js); do
123+
echo "Checking JavaScript file \'${filename}\'"
124+
diff <(js-beautify -n -s 2 "${filename}") "${filename}"
125+
done
121126
}
122127

123128
function run_docs() {

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Test for `cached_download`
1212
- Directions on how to read the CI under the Git and GitHub page of the
1313
contributing documentation.
14+
- HTTP API
15+
- Static file serving from a dirctory with `-static`
16+
- `api.js` file serving with the `-js` flag
17+
- Docs page for JavaScript example
18+
### Fixed
19+
- Port assignment for the HTTP API via the `-port` flag
1420
### Changed
1521
- `repo`/`Repo` to `record`/`Record`
1622
- Definitions with a `spec` can use the `subspec` parameter to declare that they
1723
are a list or a dict where the values are of the `spec` type. Rather than the
1824
list or dict itself being of the `spec` type.
1925
- Fixed the URL mentioned in example to configure a model.
2026
- Sphinx doctests are now run in the CI in the DOCS task.
27+
- Lint JavaScript files with js-beautify and enforce with CI
2128
### Removed
2229
- Unused imports
2330

docs/contributing/style.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,29 @@ Style
44
This document talks about code formatting, conventions, documentation, and any
55
stylistic choices that we adhere to.
66

7-
File Formatting
8-
---------------
7+
Try to run the formatters before every commit. This way, if you push up files
8+
for review, they are easy to read, even if your pull request isn't yet ready to
9+
merge.
910

10-
We run the `black <https://github.com/psf/black>`_ formatter on all files. Try
11-
to run it before every commit. This way, if you push up files for review, they
12-
are easy to read, even if your pull request isn't yet ready to merge.
11+
Python File Formatting
12+
----------------------
13+
14+
Run the `black <https://github.com/psf/black>`_ formatter on all Python files.
1315

1416
.. code-block:: console
1517
1618
$ black .
1719
20+
JavaScript File Formatting
21+
--------------------------
22+
23+
Run the `js-beautify <https://github.com/beautify-web/js-beautify>`_ formatter
24+
on all JavaScript files. Use the following options.
25+
26+
.. code-block:: console
27+
28+
$ js-beautify -r -n -s 2 file_to_format.js
29+
1830
Imports
1931
-------
2032

examples/maintained/main.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function populate_table(tableDOM, URLs) {
1+
function populate_table (tableDOM, URLs) {
22
var row;
33
var col;
44
// Clear the table
@@ -35,23 +35,23 @@ function populate_table(tableDOM, URLs) {
3535
}
3636
}
3737

38-
function refreshTable(tableDOM) {
38+
function refreshTable (tableDOM) {
3939
return fetch('cgi-bin/api.py?action=dump')
40-
.then(function(response) {
41-
return response.json()
42-
})
43-
.then(function(URLs) {
44-
populate_table(tableDOM, URLs);
45-
});
40+
.then(function(response) {
41+
return response.json()
42+
})
43+
.then(function(URLs) {
44+
populate_table(tableDOM, URLs);
45+
});
4646
}
4747

48-
function setMaintenance(URL, maintained) {
48+
function setMaintenance (URL, maintained) {
4949
return fetch('cgi-bin/api.py?action=set' +
50-
'&maintained=' + Number(maintained) +
51-
'&URL=' + URL)
52-
.then(function(response) {
53-
return response.json()
54-
}.bind(this));
50+
'&maintained=' + Number(maintained) +
51+
'&URL=' + URL)
52+
.then(function(response) {
53+
return response.json()
54+
}.bind(this));
5555
}
5656

5757
window.addEventListener('DOMContentLoaded', function(event) {
@@ -62,17 +62,17 @@ window.addEventListener('DOMContentLoaded', function(event) {
6262

6363
maintainedDOM.addEventListener('click', function(event) {
6464
setMaintenance(URLDOM.value, true)
65-
.then(function() {
66-
refreshTable(tableDOM);
67-
});
65+
.then(function() {
66+
refreshTable(tableDOM);
67+
});
6868
});
6969

7070
unmaintainedDOM.addEventListener('click', function(event) {
7171
setMaintenance(URLDOM.value, false)
72-
.then(function() {
73-
refreshTable(tableDOM);
74-
});
72+
.then(function() {
73+
refreshTable(tableDOM);
74+
});
7575
});
7676

7777
refreshTable(tableDOM);
78-
});
78+
});

examples/maintained/ml.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function predict(URL) {
1+
function predict (URL) {
22
return fetch('cgi-bin/api-ml.py?action=predict' +
3-
'&maintained=' + Number(maintained) +
4-
'&URL=' + URL)
5-
.then(function(response) {
6-
return response.json()
7-
}.bind(this));
3+
'&maintained=' + Number(maintained) +
4+
'&URL=' + URL)
5+
.then(function(response) {
6+
return response.json()
7+
}.bind(this));
88
}
99

1010
window.addEventListener('DOMContentLoaded', function(event) {
@@ -14,8 +14,8 @@ window.addEventListener('DOMContentLoaded', function(event) {
1414

1515
predictDOM.addEventListener('click', function(event) {
1616
predict(URLDOM.value)
17-
.then(function() {
18-
refreshTable(tableDOM);
19-
});
17+
.then(function() {
18+
refreshTable(tableDOM);
19+
});
2020
});
21-
});
21+
});

service/http/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include README.md
22
include LICENSE
3+
include dffml_service_http/api.js

0 commit comments

Comments
 (0)