Merge pull request #340 from JunoLab/avi/emptyheader

fix case when `weave_options` are empty
pull/341/head
Shuhei Kadowaki 2020-05-23 21:55:38 +09:00 committed by GitHub
commit 3ee7dec864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -128,12 +128,13 @@ function weave(
# overwrites options with those specified in header, that are needed for running document
# NOTE: these YAML options can NOT be given dynamically
weave_options = get(doc.header, WEAVE_OPTION_NAME, Dict())
weave_options = get(doc.header, WEAVE_OPTION_NAME, nothing)
if haskey(doc.header, WEAVE_OPTION_NAME_DEPRECATED)
@warn "Weave: `options` key is deprecated. Use `weave_options` key instead."
weave_options = get(doc.header, WEAVE_OPTION_NAME_DEPRECATED, Dict())
weave_options = get(doc.header, WEAVE_OPTION_NAME_DEPRECATED, nothing)
end
if !isempty(weave_options)
if !isnothing(weave_options)
doctype = get(weave_options, "doctype", doctype)
specific_options!(weave_options, doctype)
if haskey(weave_options, "out_path")
@ -173,7 +174,7 @@ function weave(
# overwrites options with those specified in header, that are needed for formatting document
# NOTE: these YAML options can be given dynamically
if !isempty(weave_options)
if !isnothing(weave_options)
if haskey(weave_options, "template")
template = weave_options["template"]
# resolve relative to this document

View File

@ -10,9 +10,9 @@ function WeaveDoc(source, informat = nothing)
# update default chunk options from header
chunk_defaults = deepcopy(get_chunk_defaults())
if haskey(header, WEAVE_OPTION_NAME)
if (weave_options = get(header, WEAVE_OPTION_NAME, nothing)) !== nothing
for key in keys(chunk_defaults)
if (val = get(header[WEAVE_OPTION_NAME], string(key), nothing)) !== nothing
if (val = get(weave_options, string(key), nothing)) !== nothing
chunk_defaults[key] = val
end
end

View File

@ -39,6 +39,16 @@ end
end
@testset "empty header" begin
str = """
---
weave_options:
---
"""
@test (mock_doc(str; run = true); true) # no throw
end
@testset "dynamic header specifications" begin
let