From b794e51f7a42ccb166304c470c6e163526dd10e9 Mon Sep 17 00:00:00 2001 From: Miguel Biron Date: Wed, 27 Apr 2022 19:38:36 -0700 Subject: [PATCH 1/8] flag to conditionally gen assets --- src/types/julia.jl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/types/julia.jl b/src/types/julia.jl index cf853d6e..cf9690d1 100644 --- a/src/types/julia.jl +++ b/src/types/julia.jl @@ -174,13 +174,16 @@ function save_democards(card_dir::String, isdir(x) || mkdir(x) end - # run scripts in a sandbox - m = Module(gensym()) - # modules created with Module() does not have include defined - # abspath is needed since this will call `include_relative` - Core.eval(m, :(include(x) = Base.include($m, abspath(x)))) - gen_assets() = Core.eval(m, :(include($cardname * ".jl"))) - verbose_mode() ? gen_assets() : @suppress gen_assets() + # conditionally generate assets + if get(ENV, "DEMOCARDS_BUILD_ASSETS", "false") == "true" + # run scripts in a sandbox + m = Module(gensym()) + # modules created with Module() does not have include defined + # abspath is needed since this will call `include_relative` + Core.eval(m, :(include(x) = Base.include($m, abspath(x)))) + gen_assets() = Core.eval(m, :(include($cardname * ".jl"))) + verbose_mode() ? gen_assets() : @suppress gen_assets() + end # WARNING: card.path is modified here card.path = cardname*".jl" From 3df61b8fc2eba4ef02a07861a3bbafa2701e6c96 Mon Sep 17 00:00:00 2001 From: Miguel Biron Date: Wed, 27 Apr 2022 22:09:14 -0700 Subject: [PATCH 2/8] updated readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9d49eefb..63dd1f35 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # DemoCards +**NOTE**: the purpose of this fork of DemoCards is to generate cover images during HTML generation, thereby needing only a **single pass**. It has only been tested in very narrow scenarios, so **use with caution.** + | **Documentation** | **Build Status** | |:-------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:| | [![][docs-stable-img]][docs-stable-url] [![][docs-dev-img]][docs-dev-url] | [![][action-img]][action-url] [![][pkgeval-img]][pkgeval-url] [![][codecov-img]][codecov-url] | From 224872792a0a3a1005021e368bf8423159809e98 Mon Sep 17 00:00:00 2001 From: Miguel Biron Date: Thu, 28 Apr 2022 17:28:22 -0700 Subject: [PATCH 3/8] reversed flow: do work in DemoCards, nothing in Documenter --- src/types/julia.jl | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/types/julia.jl b/src/types/julia.jl index cf9690d1..bb778f94 100644 --- a/src/types/julia.jl +++ b/src/types/julia.jl @@ -174,16 +174,13 @@ function save_democards(card_dir::String, isdir(x) || mkdir(x) end - # conditionally generate assets - if get(ENV, "DEMOCARDS_BUILD_ASSETS", "false") == "true" - # run scripts in a sandbox - m = Module(gensym()) - # modules created with Module() does not have include defined - # abspath is needed since this will call `include_relative` - Core.eval(m, :(include(x) = Base.include($m, abspath(x)))) - gen_assets() = Core.eval(m, :(include($cardname * ".jl"))) - verbose_mode() ? gen_assets() : @suppress gen_assets() - end + # run scripts in a sandbox + m = Module(gensym()) + # modules created with Module() does not have include defined + # abspath is needed since this will call `include_relative` + Core.eval(m, :(include(x) = Base.include($m, abspath(x)))) + gen_assets() = Core.eval(m, :(include($cardname * ".jl"))) + verbose_mode() ? gen_assets() : @suppress gen_assets() # WARNING: card.path is modified here card.path = cardname*".jl" @@ -231,7 +228,11 @@ function save_democards(card_dir::String, end # 3. markdown - @suppress Literate.markdown(src_path, card_dir; credit=false) # manually add credit later + @suppress Literate.markdown( + src_path, card_dir; + credit=false, # manually add credit later + codefence=("````julia" => "````") # do not put code in @example blocks, so that they don't get executed again inside Documenter's pipeline + ) # remove meta info generated by Literate.jl contents = readlines(md_path) offsets = findall(x->startswith(x, "```"), contents) From 37319f3457b7adc554c7807b5981867fad9d5275 Mon Sep 17 00:00:00 2001 From: Miguel Biron Date: Sat, 14 May 2022 18:07:09 -0700 Subject: [PATCH 4/8] pass kwargs... to save_democards --- src/generate.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/generate.jl b/src/generate.jl index aaf41d95..6d4a3efc 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -92,8 +92,9 @@ function makedemos(source::String, templates::Union{Dict, Nothing} = nothing; branch::String = "gh-pages", edit_branch::String = "master", credit = true, - throw_error = false) - + throw_error = false, + kwargs... + ) if !(basename(pwd()) == "docs" || basename(root) == "docs" || root == preview_build_dir()) # special cases that warnings are not printed: # 1. called from `docs/make.jl` @@ -194,7 +195,9 @@ function makedemos(source::String, templates::Union{Dict, Nothing} = nothing; src = src, credit = credit, nbviewer_root_url = get_nbviewer_root_url(branch), - throw_error=throw_error) + throw_error=throw_error, + kwargs... + ) isnothing(templates) || save_cover(joinpath(absolute_root, "covers"), page) isnothing(templates) || generate(joinpath(absolute_root, "index.md"), page, templates) From aa8d2b127801d4e98903e0d51edb3b48d1eab340 Mon Sep 17 00:00:00 2001 From: Miguel Biron Date: Sat, 14 May 2022 18:08:54 -0700 Subject: [PATCH 5/8] pass kwargs... to Literate.markdown --- src/types/julia.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/julia.jl b/src/types/julia.jl index bb778f94..7ad2f0c2 100644 --- a/src/types/julia.jl +++ b/src/types/julia.jl @@ -230,8 +230,8 @@ function save_democards(card_dir::String, # 3. markdown @suppress Literate.markdown( src_path, card_dir; - credit=false, # manually add credit later - codefence=("````julia" => "````") # do not put code in @example blocks, so that they don't get executed again inside Documenter's pipeline + credit=false, # manually add credit later + kwargs... ) # remove meta info generated by Literate.jl contents = readlines(md_path) From cdca5d83d7ba103970837dee610f87fe2a0b2453 Mon Sep 17 00:00:00 2001 From: Miguel Biron Date: Sat, 14 May 2022 18:13:20 -0700 Subject: [PATCH 6/8] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index ca8ff469..64fa07ba 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # DemoCards -**NOTE**: the purpose of this fork of DemoCards is to generate cover images during HTML generation, thereby needing only a **single pass**. It has only been tested in very narrow scenarios, so **use with caution.** - | **Documentation** | **Build Status** | |:-------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:| | [![][docs-stable-img]][docs-stable-url] [![][docs-dev-img]][docs-dev-url] | [![][action-img]][action-url] [![][pkgeval-img]][pkgeval-url] [![][codecov-img]][codecov-url] | From 5ff92ba6987d8d1588eccad28a2948fca10d0d51 Mon Sep 17 00:00:00 2001 From: Miguel Biron Date: Sat, 14 May 2022 18:19:22 -0700 Subject: [PATCH 7/8] pass literate_kwargs instead of all the kwargs --- src/types/julia.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/julia.jl b/src/types/julia.jl index 7ad2f0c2..8cfb8f46 100644 --- a/src/types/julia.jl +++ b/src/types/julia.jl @@ -231,7 +231,7 @@ function save_democards(card_dir::String, @suppress Literate.markdown( src_path, card_dir; credit=false, # manually add credit later - kwargs... + literate_kwargs... ) # remove meta info generated by Literate.jl contents = readlines(md_path) From 651a30a5a024a6473361f25e316dc4f8eb9afb2d Mon Sep 17 00:00:00 2001 From: Miguel Biron Date: Sat, 14 May 2022 18:34:26 -0700 Subject: [PATCH 8/8] Update julia.jl --- src/types/julia.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/julia.jl b/src/types/julia.jl index 8cfb8f46..b2ee4cad 100644 --- a/src/types/julia.jl +++ b/src/types/julia.jl @@ -139,6 +139,7 @@ function save_democards(card_dir::String, src="src", throw_error = false, properties = Dict{String, Any}(), + literate_kwargs = (), kwargs...) isdir(card_dir) || mkpath(card_dir) @debug card.path