Skip to content

Commit

Permalink
Fully implement the example meta block
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Jun 8, 2024
1 parent 34eccbe commit 7d4a5b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
19 changes: 16 additions & 3 deletions docs/example_meta_block.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Documenter

abstract type CardMetaBlocks <: Documenter.Expanders.NestedExpanderPipeline end
abstract type CardMetaBlocks <: Documenter.Expanders.ExpanderPipeline end

# Order doesn't really matter, because the expansion is done based on page location first.
Documenter.Selectors.order(::Type{CardMetaBlocks}) = 12.0
Documenter.Selectors.matcher(::Type{CardMetaBlocks}, node, page, doc) = Documenter.iscode(node, r"^@cardmeta")

Expand Down Expand Up @@ -32,14 +33,14 @@ function Documenter.Selectors.runner(::Type{CardMetaBlocks}, node, page, doc)
x = node.element
lines = Documenter.find_block_in_file(x.code, page.source)
@debug "Evaluating @cardmeta block:\n$(x.code)"
@infiltrate
# @infiltrate

for (ex, str) in Documenter.parseblock(x.code, doc, page)
# If not `isassign`, this might be a comment, or any code that the user
# wants to hide. We should probably warn, but it is common enough that
# we will silently skip for now.
if Documenter.isassign(ex)
if !(ex.args[1] in (:Title, :Description, :Cover))
if !(ex.args[1] in (:Title, :Description, :Cover, :Authors, :Date))
source = Documenter.locrepr(page.source, lines)
@warn(
"In $source: `@cardmeta` block has an unsupported " *
Expand All @@ -59,6 +60,18 @@ function Documenter.Selectors.runner(::Type{CardMetaBlocks}, node, page, doc)
end
end
end

# TODO: get defaults
# How?
# Title: get the first heading node on the page as DocumenterVitepress does
# Description: empty string as default
# Cover: no image as default
# Author: Default should be hardcoded to `["Anshul Singhvi"](https://github.com/asinghvi17)`
# Date: nothing, don't include it if nothing

# Authors and Date are for the transformer and can be applied within this block, the first four
# params need to go to the gallery/card object though.

node.element = Documenter.MetaNode(x, page.globals.meta)

end
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ using Documenter, DocumenterVitepress, Literate
using GeoMakie, CairoMakie, Makie, GeoInterfaceMakie

include("gallery_setup.jl")
include("example_meta_block.jl")
# Set some global settings
# Good quality CairoMakie with PNG
CairoMakie.activate!(px_per_unit = 3, type = :png)
CairoMakie.activate!(px_per_unit = 2, type = :png)
# Rasters should download into the artifacts folder (so they can be cached :D)
haskey(ENV, "RASTERDATASOURCES_PATH") || (ENV["RASTERDATASOURCES_PATH"] = joinpath(first(Base.DEPOT_PATH), "artifacts"))
# invoke some geomakie things to be sure it works
Expand Down
16 changes: 7 additions & 9 deletions examples/basic.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# ```@cardmeta
# Title = "Basic examples"
# Description = "Basic examples of GeoMakie"
# Cover = fig
# ```
# # Basic examples

using GeoMakie, CairoMakie # you could use GLMakie too

Expand Down Expand Up @@ -37,7 +33,9 @@ scatter!(slons, slats; color = sfield)
fig
# Again, to save, run e.g. `save("scatter_example.png", fig; px_per_unit=2)`.
#
# make cover image #jl
mkpath("covers") #hide
save("covers/$(splitext(basename(@__FILE__))[1]).png", fig) #hide
nothing #hide

# ```@cardmeta
# Title = "Basic examples"
# Description = "Basic examples of GeoMakie"
# Cover = fig
# ```

0 comments on commit 7d4a5b7

Please sign in to comment.