Skip to content

Commit

Permalink
Merge pull request #183 from astro-group-bristol/fergus/getting-start…
Browse files Browse the repository at this point in the history
…ed-fixes

Correct typos in getting started + track getting started code in test suite
  • Loading branch information
fjebaker authored Mar 6, 2024
2 parents 4bc304a + 3eef00d commit 80ab5a9
Show file tree
Hide file tree
Showing 42 changed files with 1,204 additions and 2,370 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Manifest.toml

# Housekeeping files generated by Visual Studio Code
.vscode
docs/code/examples.jl
docs/examples-code.jl
275 changes: 0 additions & 275 deletions docs/code/getting-started.jl

This file was deleted.

47 changes: 27 additions & 20 deletions docs/extract-examples.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
lines = readlines(@__DIR__() * "/src/examples.md")

examples = String[]

itt = Iterators.Stateful(lines)
for line in itt
if line == "```julia"
code = String[]
while (line = popfirst!(itt)) != "```"
push!(code, line)
end
push!(examples, join(code, "\n"))
# check if we're supposed to output a picture or not
img = match(r"!\[.*\]\((.*)\)\s*$", peek(itt))
if !isnothing(img)
filename = last(splitdir(first(img.captures)))
savepath = joinpath(@__DIR__() * "/src/example-figures/", filename)
save_line = "savefig(\"$savepath\")"
push!(examples, save_line)
function add_julia_code!(examples::Vector{String}, src_file)
lines = readlines(src_file)
itt = Iterators.Stateful(enumerate(lines))
for (lineno, line) in itt
if line == "```julia"
code = String["# $(src_file):$(lineno)"]
while ((_, line) = popfirst!(itt))[2] != "```"
push!(code, line)
end
push!(examples, join(code, "\n"))
# check if we're supposed to output a picture or not
(_, next_line) = peek(itt)
img = match(r"!\[.*\]\((.*)\)\s*$", next_line)
if !isnothing(img)
filename = last(splitdir(first(img.captures)))
savepath = joinpath(@__DIR__() * "/src/example-figures/", filename)
save_line = "savefig(\"$savepath\")"
push!(examples, save_line)
end
end
end
end

open(@__DIR__() * "/code/examples.jl", "w") do f
file1 = @__DIR__() * "/src/examples.md"
file2 = @__DIR__() * "/src/getting-started.md"

examples = String[]
add_julia_code!(examples, file1)
add_julia_code!(examples, file2)

open(@__DIR__() * "/examples-code.jl", "w") do f
for code in examples
write(f, code)
write(f, "\n", "#"^100, "\n\n")
Expand Down
Loading

0 comments on commit 80ab5a9

Please sign in to comment.