-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor geomakiedocumenterblocks to be really generic
- Loading branch information
1 parent
1d27b68
commit 139324c
Showing
11 changed files
with
151 additions
and
56 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# GeoMakieDocumenterBlocks | ||
|
||
This package implements two Documenter blocks, `@cardmeta` and `@overviewgallery`, which are used to generate DemoCards-like cards but in memory and without file manipulation or external json files, nor any requirement for directory structure. | ||
|
||
The package is integrated with Makie but can also be used standalone, with Strings encoding either base64 images or urls. | ||
|
||
## Usage | ||
|
||
See the GeoMakie docs for usage examples, the idea is that you put a cardmeta block in each example file (it's automagically moved to the end) and put an overviewgallery block in your gallery page if you want one. | ||
|
||
You also have to pass the `ExampleFormat` plugin to your `makedocs` function to use these blocks. This can be a no-arg constructor if you just want defaults. | ||
|
||
## How it works | ||
|
||
1. The Documenter build step moves all cardmeta blocks to the bottom of the page, and adds a "copy pastable code block" to the top just below the title. | ||
2. The example blocks run and do magical things. | ||
3. The cardmeta block runs and: | ||
1. Pushes a dict of card metadata | ||
2. Places the cover image directly below the title, displacing the copy pastable code block | ||
3. Nothing else yet but coming soon | ||
4. The overviewgallery block parses this metadata and emits HTML for the gallery blocks and links. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
function _stitch_all_example_blocks(page) | ||
# Extract all example blocks (this is naturally in order) | ||
all_example_blocks_in_order = filter(page.mdast.children) do x | ||
x.element isa MarkdownAST.CodeBlock && Base.occursin("@example", x.element.info) | ||
end | ||
# Join all the code blocks into a single string | ||
result = join(getproperty.(getproperty.(all_example_blocks_in_order, :element), :code), "\n") | ||
return result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
ExampleProcessing <: Documenter.Builder.DocumenterPipeline | ||
What does this do? | ||
- Moves Cardmeta blocks | ||
- Adds a quick example block (in Vitepress syntax) if requested in the pipeline and a cardmeta block is found | ||
- Adds badges to the page if necessary | ||
""" | ||
abstract type ExampleProcessing <: Documenter.Builder.DocumentPipeline end | ||
|
||
Documenter.Selectors.order(::Type{ExampleProcessing}) = 1.2 # after doctest, before expand templates. | ||
|
||
function _is_cardmeta_block(x) | ||
return x.element isa MarkdownAST.CodeBlock && Base.occursin("@cardmeta", x.element.info) | ||
end | ||
|
||
function Documenter.Selectors.runner(::Type{ExampleProcessing}, doc::Documenter.Document) | ||
# Main.@infiltrate | ||
for (filename, page) in doc.blueprint.pages | ||
cardmeta_blocks = filter(_is_cardmeta_block, collect(page.mdast.children)) | ||
is_examples_page = Base.occursin("examples", splitdir(page.build)[1]) || !isempty(cardmeta_blocks) | ||
if !isempty(cardmeta_blocks) # some cardmeta block was detected | ||
# move the cardmeta block from wherever it is to the end of the page. | ||
MarkdownAST.insert_after!(last(page.mdast.children), first(cardmeta_blocks)) | ||
elseif Base.occursin("examples", splitdir(page.build)[1]) # only inject cardmeta if in examples dir | ||
# do nothing for now - potentially inject an extra cardmeta block at the end | ||
# of every page. | ||
MarkdownAST.insert_after!(last(page.mdast.children), MarkdownAST.@ast MarkdownAST.CodeBlock("@cardmeta", "")) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
abstract type Feature end | ||
|
||
struct CopyPastableExample <: Feature end | ||
|
||
abstract type Badge <: Feature end | ||
struct JuliaFileBadge <: Badge end | ||
struct DateBadge <: Badge end | ||
struct AuthorBadge <: Badge end | ||
struct LicenseBadge <: Badge | ||
name::String | ||
link::String | ||
end | ||
|
||
|
||
@kwdef struct ExampleConfig <: Documenter.Plugin | ||
features::Vector{Feature} = Feature[CopyPastableExample()] | ||
known_examples::Vector = [] | ||
gallery_dict::Dict = Dict{String, Any}() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using GLMakie, GeoMakie, Geodesy | ||
|
||
transf = Geodesy.ECEFfromLLA(Geodesy.WGS84()) | ||
|
||
transf2 = Makie.PointTrans{3}() do p | ||
ϕ, θ, r = p | ||
sθ, cθ = sincos(deg2rad(θ)) | ||
sϕ, cϕ = sincos(deg2rad(ϕ)) | ||
Point3(r * cθ * cϕ, r * sθ * cϕ, r * sϕ) | ||
end | ||
|
||
f, a, p = meshimage(-180..180, -90..90, GeoMakie.earth(); npoints = 100, z_level = 0, axis = (; type = LScene)); | ||
lp = lines!(a, Point3f.(1:10, 1:10, 110); color = :red, linewidth = 2) | ||
cc = cameracontrols(a.scene) | ||
cc.settings.mouse_translationspeed[] = 0.0 | ||
cc.settings.zoom_shift_lookat[] = false | ||
Makie.update_cam!(a.scene, cc) | ||
p.transformation.transform_func[] = transf | ||
lp.transformation.transform_func[] = transf | ||
f | ||
|