Changes additional_kwargs to expect Dict and warns about ignored kwargs
This commit is contained in:
parent
eb356e0ec9
commit
6cb0b8583b
@ -33,14 +33,22 @@ function gen_plugin(p::Documenter, t::Template, pkg_name::AbstractString)
|
||||
end
|
||||
|
||||
kwargs_string = if :additional_kwargs in fieldnames(typeof(p))
|
||||
set_kwargs = ["modules", "format", "pages", "repo", "sitename", "authors", "assets"]
|
||||
standard_kwargs = ["modules", "format", "pages", "repo", "sitename", "authors", "assets"]
|
||||
|
||||
# We want something that looks like the following:
|
||||
# key1="val1",
|
||||
# key2="val2",
|
||||
#
|
||||
kwargs = (x for x in p.additional_kwargs if first(x) ∉ set_kwargs)
|
||||
join(string(tab, first(p), "=", repr(last(p)), ",\n") for p in kwargs)
|
||||
valid_keys = [k for k in keys(p.additional_kwargs) if k ∉ standard_kwargs]
|
||||
if length(p.additional_kwargs) > length(valid_keys)
|
||||
invalid_keys = (repr(k) for k in keys(p.additional_kwargs) if k in standard_kwargs)
|
||||
@warn string(
|
||||
"Ignoring predefined Documenter kwargs ",
|
||||
join(invalid_keys, ", "),
|
||||
" from additional kwargs."
|
||||
)
|
||||
end
|
||||
join(string(tab, k, "=", repr(p.additional_kwargs[k]), ",\n") for k in valid_keys)
|
||||
else
|
||||
""
|
||||
end
|
||||
|
@ -13,11 +13,6 @@ end
|
||||
struct Bar <: CustomPlugin end
|
||||
# A dummy Plugin subtype.
|
||||
struct Baz <: Plugin end
|
||||
# A Documenter with extra kwargs
|
||||
struct Bat <: Documenter
|
||||
assets::Vector{AbstractString}
|
||||
additional_kwargs::Vector{<:Pair}
|
||||
end
|
||||
|
||||
# Various options to be passed into templates.
|
||||
const me = "christopher-dG"
|
||||
@ -402,19 +397,25 @@ end
|
||||
include(joinpath("plugins", "githubpages.jl"))
|
||||
end
|
||||
|
||||
# A Documenter with extra kwargs
|
||||
struct Qux <: Documenter
|
||||
assets::Vector{AbstractString}
|
||||
additional_kwargs::AbstractDict
|
||||
end
|
||||
@testset "Documenter add kwargs" begin
|
||||
t = Template(; user=me)
|
||||
pkg_dir = joinpath(t.dir, test_pkg)
|
||||
p = Bat(
|
||||
p = Qux(
|
||||
[],
|
||||
["strict"=>true, "checkdocs"=>:none, "format"=>:markdown, "stringarg"=>"string"]
|
||||
Dict("strict"=>true, "checkdocs"=>:none, "format"=>:markdown, "stringarg"=>"string")
|
||||
)
|
||||
gen_plugin(p, t, test_pkg)
|
||||
warn_str = "Ignoring predefined Documenter kwargs \"format\" from additional kwargs."
|
||||
@test_logs (:warn, warn_str) gen_plugin(p, t, test_pkg)
|
||||
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
|
||||
@test occursin(
|
||||
strip("""
|
||||
strict=true,
|
||||
checkdocs=:none,
|
||||
strict=true,
|
||||
stringarg="string",
|
||||
"""),
|
||||
make,
|
||||
|
Loading…
Reference in New Issue
Block a user