Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
muppet-strings
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Hörnquist
muppet-strings
Commits
4b981e88
Commit
4b981e88
authored
2 years ago
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
Add breadcrumbs.
parent
8b0f2f68
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
muppet/breadcrumbs.py
+59
-0
59 additions, 0 deletions
muppet/breadcrumbs.py
muppet/output.py
+9
-1
9 additions, 1 deletion
muppet/output.py
static/style.css
+14
-0
14 additions, 0 deletions
static/style.css
templates/base.html
+9
-0
9 additions, 0 deletions
templates/base.html
with
91 additions
and
1 deletion
muppet/breadcrumbs.py
0 → 100644
+
59
−
0
View file @
4b981e88
"""
Page breadcrumbs.
Page breadcrumbs are the
"
how did we get here
"
at the top of web pages.
For example, the page
``/modules/example-module/example-class`` would have a breadcrumb list like
- ``/modules`` - Modules
- ``/modules/example-module`` - Example Module
- ``/modules/example-module/example-class`` Example Class
"""
import
re
from
dataclasses
import
dataclass
from
typing
import
(
Tuple
,
)
@dataclass
class
Breadcrumb
:
"""
A breadcrumb entry.
:param ref:
A url path. Meaning that it should contain all parents.
:param text:
The displayed text for this entry.
"""
ref
:
str
text
:
str
def
breadcrumbs
(
*
items
:
str
|
Tuple
[
str
,
str
])
->
list
[
Breadcrumb
]:
"""
Generate a breadcrumb trail.
:param items:
The parts of the trace.
Each item should either be a single string, which is then used
as both the name, and the url component, or a tuple, in which
case the left value will be the displaed string, and the right
value the url component.
"""
url
=
'
/
'
result
=
[]
for
item
in
items
:
if
isinstance
(
item
,
str
):
url
+=
item
+
'
/
'
text
=
item
else
:
url
+=
item
[
1
]
+
'
/
'
text
=
item
[
0
]
url
=
re
.
sub
(
'
/+
'
,
'
/
'
,
url
)
result
.
append
(
Breadcrumb
(
ref
=
url
,
text
=
text
))
return
result
This diff is collapsed.
Click to expand it.
muppet/output.py
+
9
−
1
View file @
4b981e88
...
...
@@ -29,6 +29,7 @@ from collections.abc import (
)
from
.util
import
group_by
from
.puppet.strings
import
isprivate
from
.breadcrumbs
import
breadcrumbs
# TODO replace 'output' with base, or put this somewhere else
...
...
@@ -301,8 +302,15 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
with
open
(
os
.
path
.
join
(
dir
,
'
index.html
'
),
'
w
'
)
as
f
:
template
=
jinja
.
get_template
(
'
code_page.html
'
)
crumbs
=
breadcrumbs
(
(
'
Environment
'
,
''
),
module
.
name
,
(
puppet_class
[
'
name
'
],
'
manifests/
'
+
'
/
'
.
join
(
puppet_class
[
'
name
'
].
split
(
'
::
'
)[
1
:])),
)
f
.
write
(
template
.
render
(
content
=
format_class
(
puppet_class
),
path_base
=
path_base
))
path_base
=
path_base
,
breadcrumbs
=
crumbs
))
# puppet_class['file']
# puppet_class['line']
...
...
This diff is collapsed.
Click to expand it.
static/style.css
+
14
−
0
View file @
4b981e88
...
...
@@ -80,3 +80,17 @@ code.json {
.comment
p
:last-child
{
margin-bottom
:
0
;
}
.breadcrumb
{
padding
:
0
;
}
.breadcrumb
li
{
display
:
inline-block
;
padding
:
0
;
}
.breadcrumb
li
:not
(
:first-child
)
::before
{
content
:
"»"
;
padding
:
1ex
;
}
This diff is collapsed.
Click to expand it.
templates/base.html
+
9
−
0
View file @
4b981e88
...
...
@@ -20,6 +20,15 @@
</noscript>
</head>
<body>
<header>
{% if breadcrumbs %}
<ul
class=
"breadcrumb"
>
{%- for item in breadcrumbs -%}
<li><a
href=
"{{ path_base }}{{ item.ref }}"
>
{{ item.text }}
</a></li>
{%- endfor -%}
</ul>
{% endif %}
</header>
{% block content %}
{% endblock %}
</body>
...
...
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