JuliaDocs / DemoCards.jl

Let's focus on writing demos
MIT License
66 stars 14 forks source link

add "theme" key to page's config file and deprecate direct usage of cardtheme #66

Closed johnnychen94 closed 4 years ago

johnnychen94 commented 4 years ago

Two improvements:

unify makedemos API

64 introduces a new way of how demos are navigated, which I call "themeless". The downside of it is that makedemos becomes more complex to configure, this PR unifies how themeless and themed versions are used, and make it even simpler.

Previous:

# themed version

demos_theme, demos_assets = cardtheme("grid")
demos, demos_cb = makedemos("examples", demos_theme)
makedocs(format = Documenter.HTML(assets=[demos_assets]),
    pages = [
        "Home" => "index.md",
        demos
    ]
)
demos_cb()

# themeless version
demos, demos_cb = makedemos("examples")
makedocs(format = Documenter.HTML(),
    pages = [
        "Home" => "index.md",
        demos
    ]
)
demos_cb()

Now:

# works for both themed and themeless verions

demos, demos_cb = makedemos("examples")

isnothing(demo_assets) || (push!(assets, demo_assets))
format = Documenter.HTML(assets=assets)

makedocs(format = format,
    pages = [
        "Home" => "index.md",
        demos
    ]
)

demos_cb()

The page theme is configured via config.json file, for example:

{
    "theme": "grid",
    "order": [
        "basic",
        "advanced"
    ]
}

Currently, "theme" can be one of "grid", "list" or "nothing", where "nothing" represents the themeless case. If you don't configure "theme", it would defaults to nothing.

Simplify preview_demos usage

Previously, we have to manually write preview_demos("examples", theme="grid") to preview a grid-like demos.

Now, it will infer the theme from config.json, and if that's already configured grid, preview_demos("examples") would just work out of the box.

preview_demos("examples", theme="list") would instead override the "grid" theme in "config.json" -- I made it so because if the user explicitly passes a keyword to theme, I believe he knows what he's expecting.


It's a bit hard to add deprecation tests for this, I've tested it locally that the old way still works. I'd save myself a bit of time and skip that step. 😂 The coverage regression isn't problematic.

codecov[bot] commented 4 years ago

Codecov Report

Merging #66 into master will decrease coverage by 0.47%. The diff coverage is 80.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #66      +/-   ##
==========================================
- Coverage   91.74%   91.27%   -0.48%     
==========================================
  Files          14       14              
  Lines         654      676      +22     
==========================================
+ Hits          600      617      +17     
- Misses         54       59       +5     
Impacted Files Coverage Δ
src/generate.jl 81.66% <60.00%> (-1.38%) :arrow_down:
src/types/page.jl 96.25% <90.90%> (-0.98%) :arrow_down:
src/preview.jl 93.54% <100.00%> (+0.36%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a2481fc...4c3b384. Read the comment docs.