mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-08-06 04:21:33 +00:00
Improve documentation (#199)
Let's use Literate.jl to automatically generate usage examples. * Automatically generate documentation from other packages (first try to include each package's docs/src/index.md, but if that fails, then use README.md to introduce the package). * Add example how to calculate local element matrices. * Add example how to perform 2d contact analysis.
This commit is contained in:
+107
-31
@@ -3,24 +3,59 @@
|
||||
|
||||
using Documenter, JuliaFEM
|
||||
|
||||
if !haskey(Pkg.installed(), "Literate")
|
||||
Pkg.add("Literate")
|
||||
end
|
||||
using Literate
|
||||
|
||||
if haskey(ENV, "TRAVIS") && get(ENV, "INSTALL_PYPLOT", "false") == "true"
|
||||
info("inside TRAVIS, installing PyPlot + matplotlib")
|
||||
Pkg.add("PyPlot")
|
||||
run(`pip install matplotlib`)
|
||||
end
|
||||
|
||||
"""
|
||||
copy_docs(pkg_name)
|
||||
|
||||
Copy documentation of some package `pkg_name` to `docs/src/pkg_name`,
|
||||
where `pkg_name` is the name of package. Return true if success, false
|
||||
otherwise.
|
||||
|
||||
If package is undocumented, i.e. directory `docs/src` is missing,
|
||||
but there still exists `README.md`, copy that file to
|
||||
`docs/src/pkg_name/index.md`.
|
||||
"""
|
||||
function copy_docs(pkg_name)
|
||||
src = joinpath(Pkg.dir(pkg_name), "docs", "src")
|
||||
if !isdir(src)
|
||||
warn("Cannot copy documentation of package $pkg_name from $src: ",
|
||||
"No such directory exists. (Is the package in REQUIRE of JuliaFEM?)")
|
||||
return false
|
||||
|
||||
src_dir = Pkg.dir(pkg_name, "docs", "src")
|
||||
pkg_dir = Pkg.dir("JuliaFEM", "docs", "src", "packages")
|
||||
dst_dir = joinpath(pkg_dir, pkg_name)
|
||||
isdir(pkg_dir) || mkpath(pkg_dir)
|
||||
|
||||
# if can find pkg_name/docs/src =>
|
||||
# copy that to docs/src/packages/pkg_name
|
||||
if isdir(src_dir)
|
||||
isdir(dst_dir) || cp(src_dir, dst_dir)
|
||||
info("Copied documentation of package $pkg_name from $src_dir succesfully.")
|
||||
return true
|
||||
end
|
||||
dst = joinpath(Pkg.dir("JuliaFEM"), "docs", "src", pkg_name)
|
||||
cp(src, dst; remove_destination=true)
|
||||
info("Copied documentation of package $pkg_name from $src succesfully.")
|
||||
return true
|
||||
|
||||
# if can find pkg_name/README.md =>
|
||||
# copy that to docs/src/packages/pkg_name/index.md
|
||||
readme_file = Pkg.dir(pkg_name, "README.md")
|
||||
if isfile(readme_file)
|
||||
isdir(dst_dir) || mkpath(dst_dir)
|
||||
dst_file = joinpath(dst_dir, "index.md")
|
||||
isfile(dst_file) || cp(readme_file, dst_file)
|
||||
info("Copied README.md of package $pkg_name from $readme_file succesfully.")
|
||||
return true
|
||||
end
|
||||
|
||||
warn("Cannot copy documentation of package $pkg_name from $src_dir: ",
|
||||
"No such directory exists. (Is the package in REQUIRE of JuliaFEM?)")
|
||||
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
"""
|
||||
@@ -48,22 +83,19 @@ add_page!(PACKAGES, "Theory" => "MyPackage/theory.md")
|
||||
"""
|
||||
function add_page!(dst, src)
|
||||
file = isa(src, Pair) ? src.second : src
|
||||
if !isfile(joinpath(Pkg.dir("JuliaFEM"), "docs", "src", file))
|
||||
warn("Cannot add page $file: no such file")
|
||||
return false
|
||||
src_dir = Pkg.dir("JuliaFEM", "docs", "src")
|
||||
if isfile(joinpath(src_dir, file))
|
||||
push!(dst, src)
|
||||
return true
|
||||
end
|
||||
push!(dst, src)
|
||||
return true
|
||||
if isfile(joinpath(src_dir, "packages", file))
|
||||
push!(dst, joinpath("packages", src))
|
||||
return true
|
||||
end
|
||||
warn("Cannot add page $file: no such file")
|
||||
return false
|
||||
end
|
||||
|
||||
#=
|
||||
if haskey(ENV, "TRAVIS")
|
||||
println("inside TRAVIS, installing PyPlot + matplotlib")
|
||||
Pkg.add("PyPlot")
|
||||
run(`pip install matplotlib`)
|
||||
end
|
||||
=#
|
||||
|
||||
USER_GUIDE = []
|
||||
|
||||
# Developer's guide is published in FEMBase.jl
|
||||
@@ -82,18 +114,61 @@ if copy_docs("FEMBase")
|
||||
end
|
||||
|
||||
# Let's construct here some description for packages
|
||||
|
||||
PACKAGES = []
|
||||
copy_docs("FEMBase") && add_page!(PACKAGES, "FEMBase/index.md")
|
||||
copy_docs("FEMBasis") && add_page!(PACKAGES, "FEMBasis/index.md")
|
||||
copy_docs("FEMQuad") && add_page!(PACKAGES, "FEMQuad/index.md")
|
||||
copy_docs("FEMSparse") && add_page!(PACKAGES, "FEMSparse/index.md")
|
||||
copy_docs("Materials") && add_page!(PACKAGES, "Materials/index.md")
|
||||
copy_docs("AsterReader") && add_page!(PACKAGES, "AsterReader/index.md")
|
||||
copy_docs("AbaqusReader") && add_page!(PACKAGES, "AbaqusReader/index.md")
|
||||
copy_docs("LinearImplicitDynamics") && add_page!(PACKAGES, "LinearImplicitDynamics/index.md")
|
||||
copy_docs("HeatTransfer") && add_page!(PACKAGES, "HeatTransfer/index.md")
|
||||
copy_docs("PlaneElasticity") && add_page!(PACKAGES, "PlaneElasticity/index.md")
|
||||
copy_docs("FEMBeam") && add_page!(PACKAGES, "FEMBeam/index.md")
|
||||
copy_docs("FEMCoupling") && add_page!(PACKAGES, "FEMCoupling/index.md")
|
||||
copy_docs("FEMTruss") && add_page!(PACKAGES, "FEMTruss/index.md")
|
||||
copy_docs("Mortar2D") && add_page!(PACKAGES, "Mortar2D/index.md")
|
||||
copy_docs("Mortar3D") && add_page!(PACKAGES, "Mortar3D/index.md")
|
||||
copy_docs("MortarContact2D") && add_page!(PACKAGES, "MortarContact2D/index.md")
|
||||
copy_docs("MortarContact2DAD") && add_page!(PACKAGES, "MortarContact2DAD/index.md")
|
||||
copy_docs("OptoMechanics") && add_page!(PACKAGES, "OptoMechanics/index.md")
|
||||
copy_docs("Miniball") && add_page!(PACKAGES, "Miniball/index.md")
|
||||
copy_docs("ModelReduction") && add_page!(PACKAGES, "ModelReduction/index.md")
|
||||
copy_docs("NodeNumbering") && add_page!(PACKAGES, "NodeNumbering/index.md")
|
||||
#copy_docs("Xdmf") && add_page!(PACKAGES, "Xdmf/index.md")
|
||||
copy_docs("UMAT") && add_page!(PACKAGES, "UMAT/index.md")
|
||||
|
||||
if copy_docs("FEMQuad")
|
||||
add_page!(PACKAGES, "FEMQuad/index.md")
|
||||
# Generate examples using Literate.jl
|
||||
|
||||
function license_stripper(s)
|
||||
# return replace(s, r"# This file is a part of JuliaFEM.*?\n\n"sm, "")
|
||||
lines = split(s, '\n')
|
||||
function myfilt(line)
|
||||
contains(line, "# This file is a part of JuliaFEM.") && return false
|
||||
contains(line, "# License is MIT") && return false
|
||||
return true
|
||||
end
|
||||
new_s = join(filter(myfilt, lines), '\n')
|
||||
return new_s
|
||||
end
|
||||
|
||||
if copy_docs("FEMBasis")
|
||||
add_page!(PACKAGES, "FEMBasis/index.md")
|
||||
end
|
||||
|
||||
if copy_docs("HeatTransfer")
|
||||
add_page!(PACKAGES, "HeatTransfer/index.md")
|
||||
EXAMPLES = []
|
||||
docs_src = Pkg.dir("JuliaFEM", "docs", "src")
|
||||
ex_src = Pkg.dir("JuliaFEM", "examples")
|
||||
ex_dst = joinpath(docs_src, "examples")
|
||||
for ex_file in readdir(ex_src)
|
||||
endswith(ex_file, ".jl") || continue
|
||||
startswith(ex_file, "test_") && continue
|
||||
dst_file = Literate.markdown(joinpath(ex_src, ex_file), ex_dst;
|
||||
documenter=true, preprocess=license_stripper)
|
||||
ex_dir = joinpath(ex_src, first(splitext(ex_file)))
|
||||
dst_ex_dir = joinpath(ex_dst, first(splitext(ex_file)))
|
||||
if isdir(ex_dir) && !isdir(dst_ex_dir)
|
||||
info("Copy $ex_dir to $dst_ex_dir")
|
||||
cp(ex_dir, dst_ex_dir)
|
||||
end
|
||||
add_page!(EXAMPLES, relpath(dst_file, docs_src))
|
||||
end
|
||||
|
||||
# API documentation
|
||||
@@ -103,6 +178,7 @@ LIBRARY = ["api.md"]
|
||||
PAGES = []
|
||||
push!(PAGES, "Home" => "index.md")
|
||||
#push!(PAGES, "User's guide" => USER_GUIDE)
|
||||
push!(PAGES, "Examples" => EXAMPLES)
|
||||
push!(PAGES, "Developer's guide" => DEVELOPER_GUIDE)
|
||||
push!(PAGES, "Description of packages" => PACKAGES)
|
||||
#push!("API documentation" => LIBRARY)
|
||||
|
||||
Reference in New Issue
Block a user