Skip to content

Commit

Permalink
Implement gen for regular expressions (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer authored Dec 4, 2022
1 parent ac4218d commit 00d71dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Books"
uuid = "939d5c6b-51ae-42e7-97ca-7564d0d4ad91"
authors = ["Rik Huijzer <[email protected]>"]
version = "2.0.3"
authors = ["Rik Huijzer <[email protected]>"]
version = "2.0.4"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand Down
33 changes: 29 additions & 4 deletions src/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ Expand path to allow an user to pass `index` instead of `contents/index.md` to `
Not allowing `index.md` because that is confusing with entr(f, ["contents"], M).
"""
function expand_path(p)
joinpath("contents", "$p.md")
filename = endswith(p, ".md") ? p : "$p.md"
return joinpath("contents", filename)
end

function _included_expressions(paths)
Expand Down Expand Up @@ -382,16 +383,40 @@ function gen(path::AbstractString, block_number::Union{Nothing,Int}=nothing; kwa
path = string(path)::String
return gen([path], block_number; kwargs...)
end
precompile(gen, (String,))

function gen(path::Regex, block_number::Union{Nothing,Int}=nothing; kwargs...)
paths = readdir("contents")
matches = filter(contains(path), paths)
return gen(matches, block_number; kwargs)
end

"""
entr_gen(path::AbstractString, [block_number]; M=[], kwargs...)
entr_gen(
path::Union{AbstractString,Regex},
[block_number];
M=[],
kwargs...
)
Execute `gen(path, [block_number]; M, kwargs...)` whenever files in `contents` or code in
one of the modules `M` changes.
This is a convenience function around `Revise.entr(() -> gen(...), ["contents"], M)`.
# Example
```
julia> entr_gen("plots"; M=[MyModule])
[...]
julia> entr_gen(r"plot*"; M=[MyModule])
[...]
```
"""
function entr_gen(path::AbstractString, block_number=nothing; M=[], kwargs...)
function entr_gen(
path::Union{AbstractString,Regex},
block_number=nothing;
M=[],
kwargs...
)
entr(["contents"], M) do
gen(path, block_number; kwargs...)
end
Expand Down

2 comments on commit 00d71dd

@rikhuijzer
Copy link
Collaborator Author

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/73443

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.0.4 -m "<description of version>" 00d71ddb444bbae7df37b4bf609cc2920e18ef4d
git push origin v2.0.4

Please sign in to comment.