Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dumux-repositories
dumux
Commits
8714bd5d
Commit
8714bd5d
authored
4 years ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[examples] Add possibility to autogenerate mainpage/subpage layout with navigation
parent
4a44821d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1899
Feature/improve tracer example
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/generate_example_docs.py
+78
-2
78 additions, 2 deletions
examples/generate_example_docs.py
with
78 additions
and
2 deletions
examples/generate_example_docs.py
+
78
−
2
View file @
8714bd5d
...
...
@@ -6,7 +6,76 @@ import argparse
from
convert_code_to_doc
import
*
def
convertToMarkdownAndMerge
(
dir
,
config
):
class
Navigation
:
"""
Add nagivation bars to examples with subpages
"""
def
__init__
(
self
,
config
,
dir
):
# read and check the configuration
if
"
mainpage
"
not
in
config
:
raise
IOError
(
"
The .doc_config navigation section has to contain a mainpage entry!
"
)
mainpage
=
config
[
"
mainpage
"
]
if
"
subpages
"
not
in
config
:
raise
IOError
(
"
The .doc_config navigation section has to contain a subpages entry!
"
)
if
len
(
config
[
"
subpages
"
])
<
1
:
raise
IOError
(
"
The .doc_config navigation:subpages array has to have at least one entry!
"
)
subpages
=
config
[
"
subpages
"
]
if
"
subtitles
"
not
in
config
:
subtitles
=
[
"
Part {} of the documentation
"
.
format
(
i
+
1
)
for
i
in
range
(
len
(
subpages
))]
else
:
if
len
(
config
[
"
subtitles
"
])
!=
len
(
subpages
):
raise
IOError
(
"
In the .doc_config navigation section the subpages array has to have the same length as the subtitles array!
"
)
subtitles
=
[
"
Part {}: {}
"
.
format
(
i
+
1
,
t
)
for
i
,
t
in
enumerate
(
config
[
"
subtitles
"
])]
self
.
dir
=
dir
# the working directory
# create the snippets to insert into the docs
self
.
snippets
=
{}
# first the navigation snippet for the main page
self
.
snippets
[
mainpage
]
=
{
"
header
"
:
""
,
"
footer
"
:
""
}
makeHead
=
lambda
t
:
"
\n
## {}
\n\n
"
.
format
(
t
)
makeEntry
=
lambda
i
,
l
:
"
| [:arrow_right: Click to continue with part {} of the documentation]({}) |
\n
|---:|
\n\n
"
.
format
(
i
,
l
)
self
.
snippets
[
mainpage
][
"
footer
"
]
=
"
"
.
join
(
[
makeHead
(
title
)
+
makeEntry
(
index
+
1
,
self
.
getRelPath
(
mainpage
,
subpage
))
for
index
,
(
subpage
,
title
)
in
enumerate
(
zip
(
subpages
,
subtitles
))]
).
rstrip
(
"
\n
"
)
# then the navigation snippets for the subpages
pagetypes
=
[
"
mid
"
for
i
in
range
(
len
(
subpages
))]
pagetypes
[
0
]
=
"
first
"
pagetypes
[
-
1
]
=
"
last
"
for
index
,
(
subpage
,
pagetype
)
in
enumerate
(
zip
(
subpages
,
pagetypes
)):
self
.
snippets
[
subpage
]
=
{
"
header
"
:
""
,
"
footer
"
:
""
}
if
pagetype
==
"
mid
"
:
self
.
snippets
[
subpage
][
"
header
"
]
=
"
"
.
join
([
"
\n
|
"
,
"
[:arrow_left: Back to the main documentation](
"
+
self
.
getRelPath
(
subpage
,
mainpage
)
+
"
) |
"
,
"
[:arrow_left: Go back to part {}]
"
.
format
(
index
)
+
"
(
"
+
self
.
getRelPath
(
subpage
,
subpages
[
index
-
1
])
+
"
) |
"
,
"
[:arrow_right: Continue with part {}]
"
.
format
(
index
+
2
)
+
"
(
"
+
self
.
getRelPath
(
subpage
,
subpages
[
index
+
1
])
+
"
) |
"
])
+
"
\n
|---|---|---:|
\n\n
"
elif
pagetype
==
"
last
"
:
self
.
snippets
[
subpage
][
"
header
"
]
=
"
"
.
join
([
"
\n
|
"
,
"
[:arrow_left: Back to the main documentation](
"
+
self
.
getRelPath
(
subpage
,
mainpage
)
+
"
) |
"
,
"
[:arrow_left: Go back to part {}]
"
.
format
(
index
)
+
"
(
"
+
self
.
getRelPath
(
subpage
,
subpages
[
index
-
1
])
+
"
) |
"
])
+
"
\n
|---|---:|
\n\n
"
else
:
# first subpage
self
.
snippets
[
subpage
][
"
header
"
]
=
"
"
.
join
([
"
\n
|
"
,
"
[:arrow_left: Back to the main documentation](
"
+
self
.
getRelPath
(
subpage
,
mainpage
)
+
"
) |
"
,
"
[:arrow_right: Continue with part {}]
"
.
format
(
index
+
2
)
+
"
(
"
+
self
.
getRelPath
(
subpage
,
subpages
[
index
+
1
])
+
"
) |
"
])
+
"
\n
|---|---:|
\n\n
"
# for subpages header and footer are the same
self
.
snippets
[
subpage
][
"
footer
"
]
=
self
.
snippets
[
subpage
][
"
header
"
]
def
getRelPath
(
self
,
page
,
target
):
absPageBasePath
=
os
.
path
.
split
(
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
dir
,
page
)))[
0
]
absTargetPath
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
dir
,
target
))
return
os
.
path
.
relpath
(
absTargetPath
,
absPageBasePath
)
def
header
(
self
,
page
):
return
self
.
snippets
[
page
][
"
header
"
]
def
footer
(
self
,
page
):
return
self
.
snippets
[
page
][
"
footer
"
]
def
convertToMarkdownAndMerge
(
dir
,
config
,
navigation
=
None
):
for
target
,
sources
in
config
.
items
():
...
...
@@ -20,6 +89,8 @@ def convertToMarkdownAndMerge(dir, config):
with
open
(
targetPath
,
"
w
"
)
as
targetFile
:
thisScript
=
os
.
path
.
basename
(
__file__
)
targetFile
.
write
(
"
<!-- Important: This file has been automatically generated by {}. Do not edit this file directly! -->
\n\n
"
.
format
(
thisScript
))
if
navigation
:
targetFile
.
write
(
navigation
.
header
(
target
))
for
source
in
sources
:
fileExtension
=
os
.
path
.
splitext
(
source
)[
1
]
if
fileExtension
==
"
.md
"
:
...
...
@@ -31,6 +102,8 @@ def convertToMarkdownAndMerge(dir, config):
targetFile
.
write
(
"
\n\n
"
+
transformCode
(
cppCode
.
read
(),
cppRules
(),
sourceRelPath
)
+
"
\n
"
)
else
:
raise
IOError
(
"
Unsupported or unknown file extension *{}
"
.
format
(
fileExtension
))
if
navigation
:
targetFile
.
write
(
navigation
.
footer
(
target
))
def
generateReadme
(
dir
):
config
=
None
...
...
@@ -42,7 +115,10 @@ def generateReadme(dir):
except
FileNotFoundError
:
pass
if
config
is
not
None
:
convertToMarkdownAndMerge
(
dir
,
config
)
navigation
=
None
if
"
navigation
"
in
config
:
navigation
=
Navigation
(
config
.
pop
(
"
navigation
"
),
dir
)
convertToMarkdownAndMerge
(
dir
,
config
,
navigation
)
if
__name__
==
'
__main__
'
:
parser
=
argparse
.
ArgumentParser
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment