Skip to content

Commit 458e2cd

Browse files
committed
fix documentation
1 parent 788fd86 commit 458e2cd

File tree

8 files changed

+72
-54
lines changed

8 files changed

+72
-54
lines changed

docs/main.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
from pathlib import Path
44

5-
from sanic import Sanic, response
5+
from sanic import Sanic
66

77
import idom
88
from idom.server.sanic import PerClientStateServer
@@ -12,12 +12,7 @@
1212
here = Path(__file__).parent
1313

1414
app = Sanic(__name__)
15-
app.static("/docs", str(here / "build"))
16-
17-
18-
@app.route("/")
19-
async def forward_to_index(request):
20-
return response.redirect("/docs/index.html")
15+
app.static("/", str(here / "build"))
2116

2217

2318
mount, component = multiview()
@@ -51,7 +46,9 @@ async def forward_to_index(request):
5146
idom.run = original_run
5247

5348

54-
PerClientStateServer(component, {"redirect_root_to_index": False}).register(app)
49+
PerClientStateServer(
50+
component, {"redirect_root_to_index": False, "url_prefix": "/_idom"}
51+
).register(app)
5552

5653

5754
if __name__ == "__main__":

docs/source/_exts/interactive_widget.py

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sphinx.application import Sphinx
66

77

8-
_IDOM_SERVER_LOC = os.environ.get("IDOM_DOC_EXAMPLE_SERVER_HOST", "")
8+
_IDOM_SERVER_LOC = os.environ.get("IDOM_DOC_EXAMPLE_SERVER_HOST", "") + "/_idom"
99

1010

1111
class IteractiveWidget(Directive):
@@ -25,44 +25,8 @@ def run(self):
2525
<div>
2626
<div id="{container_id}" class="interactive widget-container center-content" style="" />
2727
<script async type="module">
28-
const loc = window.location;
29-
const idom_url = "//" + ("{_IDOM_SERVER_LOC}" || loc.host);
30-
const http_proto = loc.protocol;
31-
const ws_proto = http_proto === "https:" ? "wss:" : "ws:";
32-
33-
const mount = document.getElementById("{container_id}");
34-
const enableWidgetButton = document.createElement("button");
35-
enableWidgetButton.innerHTML = "Enable Widget";
36-
enableWidgetButton.setAttribute("class", "enable-widget-button")
37-
38-
enableWidgetButton.addEventListener("click", () => {{
39-
import(http_proto + idom_url + "/client/index.js").then((module) => {{
40-
fadeOutAndThen(enableWidgetButton, () => {{
41-
mount.removeChild(enableWidgetButton);
42-
mount.setAttribute("class", "interactive widget-container");
43-
module.mountLayoutWithWebSocket(
44-
mount,
45-
ws_proto + idom_url + "/stream?view_id={view_id}",
46-
);
47-
}});
48-
}});
49-
}});
50-
51-
function fadeOutAndThen(element, callback) {{
52-
var op = 1; // initial opacity
53-
var timer = setInterval(function () {{
54-
if ( op < 0.001 ) {{
55-
clearInterval(timer);
56-
element.style.display = "none";
57-
callback();
58-
}}
59-
element.style.opacity = op;
60-
element.style.filter = 'alpha(opacity=' + op * 100 + ")";
61-
op -= op * 0.5;
62-
}}, 50);
63-
}}
64-
65-
mount.appendChild(enableWidgetButton);
28+
import loadWidgetExample from "/_static/js/load-widget-example.js";
29+
loadWidgetExample("{_IDOM_SERVER_LOC}", "{container_id}", "{view_id}");
6630
</script>
6731
</div>
6832
""",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export default function loadWidgetExample(idomServerLocation, mountID, viewID) {
2+
const loc = window.location;
3+
const idom_url = "//" + (idomServerLocation || loc.host);
4+
const http_proto = loc.protocol;
5+
const ws_proto = http_proto === "https:" ? "wss:" : "ws:";
6+
7+
const mount = document.getElementById(mountID);
8+
const enableWidgetButton = document.createElement("button");
9+
enableWidgetButton.innerHTML = "Enable Widget";
10+
enableWidgetButton.setAttribute("class", "enable-widget-button");
11+
12+
enableWidgetButton.addEventListener("click", () => {
13+
{
14+
import(http_proto + idom_url + "/client/src/index.js").then((module) => {
15+
{
16+
fadeOutAndThen(enableWidgetButton, () => {
17+
{
18+
mount.removeChild(enableWidgetButton);
19+
mount.setAttribute("class", "interactive widget-container");
20+
module.mountLayoutWithWebSocket(
21+
mount,
22+
ws_proto + idom_url + `/stream?view_id=${viewID}`
23+
);
24+
}
25+
});
26+
}
27+
});
28+
}
29+
});
30+
31+
function fadeOutAndThen(element, callback) {
32+
{
33+
var op = 1; // initial opacity
34+
var timer = setInterval(function () {
35+
{
36+
if (op < 0.001) {
37+
{
38+
clearInterval(timer);
39+
element.style.display = "none";
40+
callback();
41+
}
42+
}
43+
element.style.opacity = op;
44+
element.style.filter = "alpha(opacity=" + op * 100 + ")";
45+
op -= op * 0.5;
46+
}
47+
}, 50);
48+
}
49+
}
50+
51+
mount.appendChild(enableWidgetButton);
52+
}

docs/source/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For more installation options see the :ref:`Extra Features` section.
1717

1818
.. note::
1919

20-
To contribute to IDOM, refer to the :ref:`Developer Workflow` instructions.
20+
To contribute to IDOM, refer to the :ref:`Developer Guide` instructions.
2121

2222

2323
Extra Features

docs/source/package-api.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ Client
9191
.. automodule:: idom.client.manage
9292
:members:
9393

94-
.. automodule:: idom.client.utils
95-
:members:
96-
9794

9895
Useful Tools
9996
------------

noxfile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
from pathlib import Path
34
from typing import List
@@ -56,10 +57,14 @@ def docs(session: Session) -> None:
5657
"python",
5758
"scripts/live_docs.py",
5859
"--open-browser",
60+
"--ignore=build/**/*",
61+
"-a",
62+
"-E",
5963
"-b",
6064
"html",
6165
"docs/source",
6266
"docs/build",
67+
env={"PYTHONPATH": os.getcwd()},
6368
)
6469

6570

@@ -142,4 +147,5 @@ def test_docs(session: Session) -> None:
142147

143148
def install_idom_dev(session: Session, extras: str = "stable") -> None:
144149
session.install("-e", f".[{extras}]")
145-
session.run("idom", "client", "restore")
150+
if "--no-restore" not in session.posargs:
151+
session.run("idom", "client", "restore")

scripts/live_docs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def new_builder():
2626

2727
importlib.reload(main)
2828

29-
server = PerClientStateServer(main.component, {"cors": True})
29+
server = PerClientStateServer(
30+
main.component, {"cors": True, "url_prefix": "_idom"}
31+
)
3032
_running_idom_servers.append(server)
3133
server.daemon("127.0.0.1", 5555, debug=True)
3234
old_builder()

src/idom/client/manage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def build(packages_to_install: Sequence[str], clean_build: bool = True) -> None:
8989
}
9090

9191
# make sure we don't delete anything we've already installed
92-
built_package_json_path = temp_build_dir / "package.json"
92+
built_package_json_path = _private.build_dir() / "package.json"
9393
if not clean_build and built_package_json_path.exists():
9494
built_package_json = json.loads(built_package_json_path.read_text())
9595
for dep_name, dep_ver in built_package_json.get("dependencies", {}).items():

0 commit comments

Comments
 (0)