Skip to content

Commit c5d8877

Browse files
Convert Mux provider to extension
- Mux tests were failing because the rdeits CSAIL account is expired - Added the js file to the assets/ folder in the docs build to provide a stable URI to test against - (Explicitly add the js file so its removed/handled when switching branches but should otherwise be ignored.)
1 parent fe6e364 commit c5d8877

File tree

8 files changed

+71
-21
lines changed

8 files changed

+71
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ coverage/
66
*.jl.cov
77
*.jl.*.cov
88
*.jl.mem
9+
docs/src/assets/trivial_import.js
910

1011
# JavaScript
1112
dist

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ Widgets = "cc8bc4a8-27d6-5769-a93b-9d913e69aa62"
2121

2222
[weakdeps]
2323
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
24+
Mux = "a975b10e-0019-58db-a62f-e48ff68538c9"
2425

2526
[extensions]
2627
IJuliaExt = "IJulia"
28+
MuxExt = "Mux"
2729

2830
[compat]
2931
AssetRegistry = "0.1.0"
3032
FunctionalCollections = "0.5.0"
3133
IJulia = "1.13"
3234
JSON = "0.18, 0.19, 0.20, 0.21"
35+
Mux = "1"
3336
Observables = "0.5"
3437
Requires = "0.4.4, 0.5, 1.0.0"
3538
WebSockets = "1.5.0, 1.6.0"

docs/Project.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ Blink = "ad839575-38b3-5650-b840-f874b8c74a25"
33
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
44
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
55
Mux = "a975b10e-0019-58db-a62f-e48ff68538c9"
6+
WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"
7+
8+
[compat]
9+
Blink = "0.12"
10+
Documenter = "1.8"
11+
IJulia = "1.13"
12+
Mux = "1"

docs/make.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1-
using Documenter
1+
using Documenter, SHA
22
using WebIO
33

4+
# Copy or update trivial_import.js
5+
docs_trivial_path = joinpath(@__DIR__, "src/assets/trivial_import.js")
6+
test_trivial_path = joinpath(@__DIR__, "../test/assets/trivial_import.js")
7+
if isfile(docs_trivial_path)
8+
test_sha = open(test_trivial_path) do io
9+
sha1(io)
10+
end
11+
docs_sha = open(docs_trivial_path) do io
12+
sha1(io)
13+
end
14+
if test_sha != docs_sha
15+
cp(test_trivial_path, docs_trivial_path; force=true)
16+
end
17+
else
18+
mkdir(dirname(docs_trivial_path))
19+
cp(test_trivial_path, docs_trivial_path)
20+
end
21+
422
# We have to ensure that these modules are loaded because some functions are
523
# defined behind @require guards.
624
using IJulia, Mux, Blink
725

26+
DocMeta.setdocmeta!(WebIO, :DocTestSetup, :(using WebIO); recursive=true)
27+
828
makedocs(
929
sitename="WebIO",
30+
warnonly=true,
1031
format=Documenter.HTML(),
1132
modules=[WebIO],
1233
pages=[

docs/src/assets/trivial_import.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// A trivial importable module that simply produces "ok".
2+
// Used for testing the WebIO Scope imports machinery.
3+
4+
(function (root, factory) {
5+
if (typeof define === 'function' && define.amd) {
6+
// AMD. Register as an anonymous module.
7+
define([], factory);
8+
} else {
9+
// Browser globals
10+
root.amdWeb = factory();
11+
}
12+
}(typeof self !== 'undefined' ? self : this, function () {
13+
return {x: "ok"}
14+
}));

ext/mux.jl renamed to ext/MuxExt.jl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
using .JSON
2-
using .AssetRegistry
3-
using .Sockets
4-
using .Base64: stringmime
5-
export webio_serve
1+
module MuxExt
2+
3+
using WebIO
4+
using WebIO: MUX_BUNDLE_PATH
5+
6+
using Mux, JSON, AssetRegistry
7+
using Sockets
8+
using Base64: stringmime
69

710
"""
811
webio_serve(app, port=8000)
912
1013
Serve a Mux app which might return a WebIO node.
1114
"""
12-
function webio_serve(app, args...)
15+
function WebIO.webio_serve(app, args...)
1316
http = Mux.App(Mux.mux(
1417
Mux.defaults,
1518
app,
1619
Mux.notfound()
1720
))
18-
webio_serve(http, args...)
21+
WebIO.webio_serve(http, args...)
1922
end
20-
function webio_serve(app::Mux.App, args...)
23+
function WebIO.webio_serve(app::Mux.App, args...)
2124
websock = Mux.App(Mux.mux(
2225
Mux.wdefaults,
2326
Mux.route("/webio-socket", create_socket),
@@ -53,7 +56,9 @@ end
5356

5457
Base.isopen(p::WebSockConnection) = isopen(p.sock)
5558

56-
Mux.Response(o::AbstractWidget) = Mux.Response(Widgets.render(o))
59+
# TYPE-PIRACY
60+
# Mux.Response(o::AbstractWidget) = Mux.Response(Widgets.render(o))
61+
5762
function Mux.Response(content::Union{Node, Scope})
5863
script_url = try
5964
AssetRegistry.register(MUX_BUNDLE_PATH)
@@ -86,4 +91,9 @@ function WebIO.register_renderable(::Type{T}, ::Val{:mux}) where {T}
8691
end
8792

8893
WebIO.setup_provider(::Val{:mux}) = nothing # Mux setup has no side-effects
89-
WebIO.setup(:mux)
94+
95+
function __init__()
96+
WebIO.setup(:mux)
97+
end
98+
99+
end

src/WebIO.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@ function prefetch_provider_file(basename)
9494
(file = filepath, code = code)
9595
end
9696

97-
provider_mux = prefetch_provider_file("mux.jl")
9897
provider_generic_http = prefetch_provider_file("generic_http.jl")
9998

99+
function webio_serve end
100+
100101
function __init__()
101102
push!(Observables.addhandler_callbacks, WebIO.setup_comm)
102-
@require Mux="a975b10e-0019-58db-a62f-e48ff68538c9" begin
103-
include_string(@__MODULE__, provider_mux.code, provider_mux.file)
104-
end
105103
@require WebSockets="104b5d7c-a370-577a-8038-80a2059c5097" begin
106104
include_string(@__MODULE__, provider_generic_http.code, provider_generic_http.file)
107105
end

test/blink-tests.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,11 @@ w = open_window()
9090
end
9191

9292
@testset "global URL, no http:" begin
93-
# TODO: change this to a permanent URL because this CSAIL account
94-
# will eventually expire.
95-
@test scope_import(w, "//people.csail.mit.edu/rdeits/webio_tests/trivial_import.js", use_iframe) == "ok"
93+
@test scope_import(w, "//juliagizmos.github.io/WebIO.jl/dev/assets/trivial_import.js", use_iframe) == "ok"
9694
end
9795

9896
@testset "global URL, with http:" begin
99-
# TODO: change this to a permanent URL because this CSAIL account
100-
# will eventually expire.
101-
@test scope_import(w, "http://people.csail.mit.edu/rdeits/webio_tests/trivial_import.js", use_iframe) == "ok"
97+
@test scope_import(w, "http://juliagizmos.github.io/WebIO.jl/dev/assets/trivial_import.js", use_iframe) == "ok"
10298
end
10399
end
104100
end

0 commit comments

Comments
 (0)