Skip to content

Commit

Permalink
Expose gb_components
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Salceanu committed Aug 8, 2024
1 parent f82b6d8 commit 8170f6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GenieDevTools"
uuid = "4e5d9629-6565-4102-a9ff-45c707eb060e"
authors = ["essenciary <[email protected]> and contributors"]
version = "2.9.6"
version = "2.10.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -14,7 +14,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Dates = "1.6"
Genie = "5.23.8"
Genie = "5.30.4"
RemoteREPL = "0.2"
Revise = "3"
Stipple = "0.27.31, 0.28"
Expand Down
44 changes: 35 additions & 9 deletions src/route_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function pages(defaultroute)
:assets => assets(),
:config => config(),
:sesstoken => Stipple.sessionid(),
:gb_components => gb_components(),
)

push!(result[:pages], page_info)
Expand Down Expand Up @@ -244,15 +245,8 @@ function assets(rootdir = Genie.config.server_document_root; extensions = ["js",
Sys.iswindows() ? [replace(p, "\\" => "/") for p in result] : result
end

function modeldeps(m::M) where {M<:Stipple.ReactiveModel}
Stipple.deps(m)

scripts = String[]
styles = String[]

channelname = params(:CHANNEL__, "")

basepath::String = if haskey(ENV, "BASEPATH")
function assets_basepath() :: String
if haskey(ENV, "BASEPATH")
# the BASEPATH is the GBJL basepath, not the app's
if haskey(ENV, "GBJL_PATH") && (ENV["GBJL_PATH"] == ( (startswith(ENV["BASEPATH"], "/") ? "" : "/") * ENV["BASEPATH"] ))
""
Expand All @@ -263,6 +257,16 @@ function modeldeps(m::M) where {M<:Stipple.ReactiveModel}
else
""
end
end

function modeldeps(m::M) where {M<:Stipple.ReactiveModel}
Stipple.deps(m)

scripts = String[]
styles = String[]

channelname = params(:CHANNEL__, "")
basepath = assets_basepath()

if ! isempty(channelname)
push!(scripts, "$basepath/$channelname.js")
Expand All @@ -277,6 +281,7 @@ function modeldeps(m::M) where {M<:Stipple.ReactiveModel}

for r in routes(reversed = false)
! isempty(channelname) && endswith(r.path, "$channelname.js") && continue # don't add the channel script again
occursin("gb_component", r.path) && continue # don't include gb_component assets

if endswith(r.path, ".js")
push!(scripts, basepath * r.path)
Expand All @@ -288,6 +293,27 @@ function modeldeps(m::M) where {M<:Stipple.ReactiveModel}
Dict(:scripts => scripts, :styles => styles)
end

function gb_components()
prefix = "components"
suffix = "gb_component"
basepath = assets_basepath()
components = Dict{String, Vector{String}}()

for r in routes(reversed = false)
(occursin(prefix, r.path) && occursin(suffix, r.path)) || continue # only include gb_component assets
m = match(Regex("/$prefix/(.*)/$suffix/"), r.path)
m === nothing && continue
isempty(m.captures) && continue

component_name = m.captures[1]
haskey(components, component_name) || (components[component_name] = String[])

push!(components[component_name], basepath * r.path)
end

components
end

function startrepl(defaultroute)
route("$defaultroute/startrepl") do
port = params(:port, )
Expand Down

2 comments on commit 8170f6c

@essenciary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/112667

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.10.0 -m "<description of version>" 8170f6c14698600d1e69d8d9d5ee14935853440e
git push origin v2.10.0

Please sign in to comment.