diff --git a/docs/generate.jl b/docs/generate.jl index 5e00cfd13c..4d5e86ee91 100644 --- a/docs/generate.jl +++ b/docs/generate.jl @@ -1,41 +1,56 @@ import Literate -using Literate: script, markdown, notebook -# source directory for model files written using Literate.jl format source_dir = joinpath(@__DIR__, "..", "examples") - -# target directory for the tests files (bare .jl files) +# target directory for script files (*.jl) (used in the tests) target_dir_jl = joinpath(@__DIR__, "..", "test", "models", "generated") - -# target directory for the markdown files (used by Documenter) +# target directory for markdown and notebook files (used by Documenter) target_dir_md = joinpath(@__DIR__, "src", "generated_examples") mkpath(target_dir_md) -# model files in sub-directories of source_dir -MODELS = ["Brusselator/Brusselator.jl", - "Building/Building.jl", - "DuffingOscillator/DuffingOscillator.jl", - "EMBrake/EMBrake.jl", - "Heat3D/Heat3D.jl", - "ISS/ISS.jl", - "LaubLoomis/LaubLoomis.jl", - "Lorenz/Lorenz.jl", - "LotkaVolterra/LotkaVolterra.jl", - "OpAmp/OpAmp.jl", - "SquareWaveOscillator/SquareWaveOscillator.jl", - "Platoon/Platoon.jl", - "ProductionDestruction/ProductionDestruction.jl", - "Quadrotor/Quadrotor.jl", - "SEIR/SEIR.jl", - "Spacecraft/Spacecraft.jl", - "TransmissionLine/TransmissionLine.jl", - "VanDerPol/VanDerPol.jl"] +MODELS = [ + "Brusselator", + "Building", + "DuffingOscillator", + "EMBrake", + "Heat3D", + "ISS", + "LaubLoomis", + "Lorenz", + "LotkaVolterra", + "OpAmp", + "SquareWaveOscillator", + "Platoon", + "ProductionDestruction", + "Quadrotor", + "SEIR", + "Spacecraft", + "TransmissionLine", + "VanDerPol" + ] + +for model in MODELS + model_path = abspath(joinpath(source_dir, model)) + for file in readdir(model_path) + if endswith(file, ".jl") + input = abspath(joinpath(model_path, file)) + script = Literate.script(input, target_dir_jl; credit=false) + code = strip(read(script, String)) + mdpost(str) = replace(str, "@__CODE__" => code) + if get(ENV, "DOCUMENTATIONGENERATOR", "") == "true" + Literate.markdown(input, target_dir_md; postprocess=mdpost, credit=false) + else + # for the local build, one needs to set `nbviewer_root_url` + Literate.markdown(input, target_dir_md; postprocess=mdpost, credit=false, nbviewer_root_url="..") + end -for file in MODELS - source_path = abspath(joinpath(source_dir, file)) - text = script(source_path, target_dir_jl; credit=false) - code = strip(read(text, String)) - mdpost(str) = replace(str, "@__CODE__" => code) - markdown(source_path, target_dir_md; postprocess=mdpost, credit=false) - notebook(source_path, target_dir_md; execute=true, credit=false) + # notebooks are deactivated to speed up the generation +# Literate.notebook(input, target_dir_md; execute=true, credit=false) +# if used, add the following to the top of the script files (where `MODELNAME` is the model name): +#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/MODELNAME.ipynb) + elseif any(endswith.(file, [".jld2", ".png"])) + # ignore *.jld2 and *.png files without warning + else + @warn "ignoring $file in $model_path" + end + end end diff --git a/examples/Brusselator/Brusselator.jl b/examples/Brusselator/Brusselator.jl index a12f5d3668..533e805810 100644 --- a/examples/Brusselator/Brusselator.jl +++ b/examples/Brusselator/Brusselator.jl @@ -1,5 +1,4 @@ # # Brusselator -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Brusselator.ipynb) # #md # !!! note "Overview" #md # System type: polynomial continuous system\ diff --git a/examples/Building/Building.jl b/examples/Building/Building.jl index c99755765d..5e24658021 100644 --- a/examples/Building/Building.jl +++ b/examples/Building/Building.jl @@ -1,5 +1,4 @@ # # Building -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Building.ipynb) # #md # !!! note "Overview" #md # System type: Affine system\ diff --git a/examples/DuffingOscillator/DuffingOscillator.jl b/examples/DuffingOscillator/DuffingOscillator.jl index ecb249e4b7..283327a805 100644 --- a/examples/DuffingOscillator/DuffingOscillator.jl +++ b/examples/DuffingOscillator/DuffingOscillator.jl @@ -1,5 +1,4 @@ # # Duffing Oscillator -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/DuffingOscillator.ipynb) # #md # !!! note "Overview" #md # System type: nonlinear\ diff --git a/examples/EMBrake/EMBrake.jl b/examples/EMBrake/EMBrake.jl index e92bf61bed..ff81bba257 100644 --- a/examples/EMBrake/EMBrake.jl +++ b/examples/EMBrake/EMBrake.jl @@ -1,5 +1,4 @@ # # Electromechanic break -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/EMBrake.ipynb) # #md # !!! note "Overview" #md # System type: Affine system\ diff --git a/examples/Heat3D/Heat3D.jl b/examples/Heat3D/Heat3D.jl index ca9fc29d36..63b545dd43 100644 --- a/examples/Heat3D/Heat3D.jl +++ b/examples/Heat3D/Heat3D.jl @@ -1,5 +1,4 @@ # # Heat PDE -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Heat3D.ipynb) # #md # !!! note "Overview" #md # System type: Affine system\ diff --git a/examples/ISS/ISS.jl b/examples/ISS/ISS.jl index fc476ca663..d910c552c6 100644 --- a/examples/ISS/ISS.jl +++ b/examples/ISS/ISS.jl @@ -1,5 +1,4 @@ # # Structural Model -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/ISS.ipynb) # #md # !!! note "Overview" #md # System type: linear time-invariant continuous system\ diff --git a/examples/LaubLoomis/LaubLoomis.jl b/examples/LaubLoomis/LaubLoomis.jl index e2ffb10efb..6cc95465fc 100644 --- a/examples/LaubLoomis/LaubLoomis.jl +++ b/examples/LaubLoomis/LaubLoomis.jl @@ -1,5 +1,4 @@ # # Laub-Loomis -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/LaubLoomis.ipynb) # #md # !!! note "Overview" #md # System type: polynomial with quadratic nonlinearities\ diff --git a/examples/Lorenz/Lorenz.jl b/examples/Lorenz/Lorenz.jl index 4f23ace9f0..5738f8999f 100644 --- a/examples/Lorenz/Lorenz.jl +++ b/examples/Lorenz/Lorenz.jl @@ -1,5 +1,4 @@ # # Lorenz equations -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Lorenz.ipynb) # #md # !!! note "Overview" #md # System type: Continuous blackbox system\ diff --git a/examples/LotkaVolterra/LotkaVolterra.jl b/examples/LotkaVolterra/LotkaVolterra.jl index c541a11412..5e1767549b 100644 --- a/examples/LotkaVolterra/LotkaVolterra.jl +++ b/examples/LotkaVolterra/LotkaVolterra.jl @@ -1,5 +1,4 @@ # # Lotka-Volterra -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/LotkaVolterra.ipynb) # #md # !!! note "Overview" #md # System type: Nonlinear system\ diff --git a/examples/LotkaVolterraTangential/LotkaVolterraTangential b/examples/LotkaVolterraTangential/LotkaVolterraTangential index aa8ff6bf79..93e010f229 100644 --- a/examples/LotkaVolterraTangential/LotkaVolterraTangential +++ b/examples/LotkaVolterraTangential/LotkaVolterraTangential @@ -1,5 +1,4 @@ # # Lotka-Voltera with Nonlinear Guard -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/LotkaVolterraGuard.ipynb) # #md # !!! note "Overview" #md # System type: hybrid system with nonlinear guard\ diff --git a/examples/OpAmp/OpAmp.jl b/examples/OpAmp/OpAmp.jl index b5735535cf..fff22f02dc 100644 --- a/examples/OpAmp/OpAmp.jl +++ b/examples/OpAmp/OpAmp.jl @@ -1,5 +1,4 @@ # # Amplifier circuit -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/OpAmp.ipynb) # #md # !!! note "Overview" #md # System type: linear continuous system with piecewise-linear input\ diff --git a/examples/Platoon/Platoon.jl b/examples/Platoon/Platoon.jl index 567aa6a2ef..d14e4acdf9 100644 --- a/examples/Platoon/Platoon.jl +++ b/examples/Platoon/Platoon.jl @@ -1,5 +1,4 @@ # # Vehicle Platoon Model -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Platoon.ipynb) # #md # !!! note "Overview" #md # System type: affine with hybrid dynamics\ diff --git a/examples/ProductionDestruction/ProductionDestruction.jl b/examples/ProductionDestruction/ProductionDestruction.jl index 934f567cd5..239cb536c0 100644 --- a/examples/ProductionDestruction/ProductionDestruction.jl +++ b/examples/ProductionDestruction/ProductionDestruction.jl @@ -1,5 +1,4 @@ # # Production-Destruction -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/ProductionDestruction.ipynb) # #md # !!! note "Overview" #md # System type: rational function\ diff --git a/examples/Quadrotor/Quadrotor.jl b/examples/Quadrotor/Quadrotor.jl index 9a3b5f2b2a..8a16eb6ad4 100644 --- a/examples/Quadrotor/Quadrotor.jl +++ b/examples/Quadrotor/Quadrotor.jl @@ -1,5 +1,4 @@ # # Quadrotor -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Quadrotor.ipynb) # #md # !!! note "Overview" #md # System type: polynomial continuous system\ diff --git a/examples/SEIR/SEIR.jl b/examples/SEIR/SEIR.jl index a269988d9c..4fa73774f0 100644 --- a/examples/SEIR/SEIR.jl +++ b/examples/SEIR/SEIR.jl @@ -1,5 +1,4 @@ # # SEIR -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/SEIR.ipynb) # #md # !!! note "Overview" #md # System type: Nonlinear system\ diff --git a/examples/Spacecraft/Spacecraft.jl b/examples/Spacecraft/Spacecraft.jl index e0ba45c118..9a9cb88bd0 100644 --- a/examples/Spacecraft/Spacecraft.jl +++ b/examples/Spacecraft/Spacecraft.jl @@ -1,5 +1,4 @@ # # Spacecraft -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Spacecraft.ipynb) # #md # !!! note "Overview" #md # System type: hybrid system with nonlinear dynamics\ diff --git a/examples/SquareWaveOscillator/SquareWaveOscillator.jl b/examples/SquareWaveOscillator/SquareWaveOscillator.jl index 82d4b502a9..f2eb196550 100644 --- a/examples/SquareWaveOscillator/SquareWaveOscillator.jl +++ b/examples/SquareWaveOscillator/SquareWaveOscillator.jl @@ -1,5 +1,4 @@ # # Square Wave Oscillator -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/SquareWaveOscillator.ipynb) # #md # !!! note "Overview" #md # System type: linear hybrid\ diff --git a/examples/TransmissionLine/TransmissionLine.jl b/examples/TransmissionLine/TransmissionLine.jl index 84ff699c00..7c1d364fc9 100644 --- a/examples/TransmissionLine/TransmissionLine.jl +++ b/examples/TransmissionLine/TransmissionLine.jl @@ -1,7 +1,5 @@ # # Transmission line circuit # -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/TransmissionLine.ipynb) -# #md # !!! note "Overview" #md # System type: linear continuous system\ #md # State dimension: parametric, typically between 4 to 40\ diff --git a/examples/VanDerPol/VanDerPol.jl b/examples/VanDerPol/VanDerPol.jl index 30ffaa5a32..cc12c5a466 100644 --- a/examples/VanDerPol/VanDerPol.jl +++ b/examples/VanDerPol/VanDerPol.jl @@ -1,5 +1,4 @@ # # Van der Pol oscillator -#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/VanDerPol.ipynb) # #md # !!! note "Overview" #md # System type: polynomial continuous system\