Skip to content

Commit

Permalink
Add a few precompile directives
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Apr 6, 2022
1 parent 3e30f21 commit 8b683ae
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion 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 = "1.2.5"
version = "1.2.6"

[deps]
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
Expand Down
36 changes: 24 additions & 12 deletions src/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,13 @@ function expand_path(p)
end

"""
gen(paths::Vector; M=Main, fail_on_error=false, project="default")
gen(
paths::Vector{String};
M=Main,
fail_on_error::Bool=false,
project="default",
call_html::Bool=true
)
Populate the files in `$(Books.GENERATED_DIR)/` by calling the required methods.
These methods are specified by the filename and will output to that filename.
Expand All @@ -282,8 +288,13 @@ After calling the methods, this method will also call `html()` to update the sit
`call_html == true`.
"""

function gen(paths::Vector{String};
M=Main, fail_on_error=false, project="default", call_html=true)
function gen(
paths::Vector{String};
M=Main,
fail_on_error::Bool=false,
project="default",
call_html::Bool=true
)

mkpath(GENERATED_DIR)
paths = [contains(dirname(p), "contents") ? p : expand_path(p) for p in paths]
Expand All @@ -303,6 +314,15 @@ function gen(paths::Vector{String};
return nothing
end

function gen(; M=Main, fail_on_error=false, project="default", call_html=true)
paths = inputs(project)
first_file = first(paths)
if !isfile(first_file)
error("Couldn't find $first_file. Is there a valid project in $(pwd())?")
end
gen(paths; M, fail_on_error, project, call_html)
end

"""
gen(path::AbstractString; kwargs...)
Expand All @@ -312,12 +332,4 @@ function gen(path::AbstractString; kwargs...)
path = string(path)::String
gen([path]; kwargs...)
end

function gen(; M=Main, fail_on_error=false, project="default", call_html=true)
paths = inputs(project)
first_file = first(paths)
if !isfile(first_file)
error("Couldn't find $first_file. Is there a valid project in $(pwd())?")
end
gen(paths; M, fail_on_error, project, call_html)
end
precompile(gen, (String,))
9 changes: 6 additions & 3 deletions src/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Define a code `block` which needs to be evaluated in module `mod`.
By default, the module in which the code is evaluated is shown above the code block.
This can be disabled via `hide_module`.
"""
code(block::AbstractString; mod=Main, hide_module=false) =
Code(rstrip(block), mod, hide_module)
function code(block::AbstractString; mod=Main, hide_module::Bool=false)
return Code(rstrip(block), mod, hide_module)
end

"""
ImageOptions(object; width=nothing, height=nothing)
Expand Down Expand Up @@ -77,7 +78,8 @@ struct Options
label::Union{AbstractString,Nothing,Missing}
link_attributes::Union{AbstractString,Nothing,Missing}

function Options(object;
function Options(
object;
filename=missing,
caption=missing,
label=missing,
Expand All @@ -104,6 +106,7 @@ julia> Options.(objects, filenames)
```
"""
Options(object, filename::AbstractString) = Options(object; filename)
precompile(Options, (Int, String))

function convert_output(expr, path, out::Code)::String
block = out.block
Expand Down
1 change: 1 addition & 0 deletions src/serve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ function serve(; simplewatcher=nothing, host::String="127.0.0.1",
port = config(project, "port")::Int
LiveServer.serve(simplewatcher; verbose, host, port, dir)
end
precompile(serve, ())
2 changes: 2 additions & 0 deletions src/showcode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function scob(expr::AbstractString; M=Main)
post = output_block
sco(expr; M, post)
end
precompile(scob, (String,))

"""
sc(expr::AbstractString; M=Main)
Expand All @@ -150,6 +151,7 @@ function sc(expr::AbstractString; M=Main)
code = remove_hide_comment(expr)
code = code_block(strip(code))
end
precompile(sc, (String,))

function sco_macro_helper(
f::Function,
Expand Down
2 changes: 1 addition & 1 deletion src/sitemap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ function sitemap(project, h)
write(path, text)
return text
end

precompile(sitemap, (String, String))

0 comments on commit 8b683ae

Please sign in to comment.