Skip to content

Commit f5ec391

Browse files
committed
Add visual explain
1 parent b25c634 commit f5ec391

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/docs/overrides/__pycache__/

docs/assets/extra.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@
55
--md-accent-fg-color: #eb4432;
66
--md-accent-fg-color--light: #eb4432;
77
--md-accent-fg-color--dark: #eb4432;
8+
}
9+
10+
.mdx-badge__icon{
11+
background:var(--md-accent-fg-color--transparent);
12+
padding:.2rem
13+
}
14+
.mdx-badge__text{
15+
font-size:.85em;
16+
box-shadow:0 0 0 1px inset var(--md-accent-fg-color--transparent);
17+
padding:.2rem .3rem
818
}

docs/collectors.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ The Query Collector has the following features
130130
],
131131
```
132132

133+
#### On-demand query EXPLAIN
134+
135+
<!-- md:version v3.14.0 -->
136+
<!-- md:flag experimental -->
137+
138+
Enable the `options.db.explain` option to run on-demand EXPLAIN queries for any SELECT query in the Debugbar.
139+
This will update in the interface. You also have an option to navigate to mysqlexplain.com for a visual explain.
140+
141+
![Query On-demand Explain](img/query-explain.gif)
142+
133143
### RouteCollector
134144

135145
This shows the current route and middleware.

docs/img/query-explain.gif

806 KB
Loading

docs/overrides/shortcodes.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
## File based on https://github.com/processone/docs.ejabberd.im/blob/master/shortcodes.py and
2+
## https://github.com/squidfunk/mkdocs-material/tree/master/material/overrides/hooks
3+
4+
# Copyright (c) 2016-2024 Martin Donath <[email protected]>
5+
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to
8+
# deal in the Software without restriction, including without limitation the
9+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
# sell copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
13+
# The above copyright notice and this permission notice shall be included in
14+
# all copies or substantial portions of the Software.
15+
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22+
# IN THE SOFTWARE.
23+
24+
from __future__ import annotations
25+
26+
import posixpath
27+
import re
28+
29+
from mkdocs.config.defaults import MkDocsConfig
30+
from mkdocs.structure.files import File, Files
31+
from mkdocs.structure.pages import Page
32+
from re import Match
33+
34+
# -----------------------------------------------------------------------------
35+
# Hooks
36+
# -----------------------------------------------------------------------------
37+
38+
# @todo
39+
def on_page_markdown(
40+
markdown: str, *, page: Page, config: MkDocsConfig, files: Files
41+
):
42+
43+
# Replace callback
44+
def replace(match: Match):
45+
type, args = match.groups()
46+
args = args.strip()
47+
if type == "version":
48+
return _badge_for_version(args, page, files)
49+
elif type == "flag": return flag(args, page, files)
50+
51+
# Otherwise, raise an error
52+
raise RuntimeError(f"Unknown shortcode: {type}")
53+
54+
# Find and replace all external asset URLs in current page
55+
return re.sub(
56+
r"<!-- md:(\w+)(.*?) -->",
57+
replace, markdown, flags = re.I | re.M
58+
)
59+
60+
# -----------------------------------------------------------------------------
61+
# Create a flag of a specific type
62+
def flag(args: str, page: Page, files: Files):
63+
type, *_ = args.split(" ", 1)
64+
if type == "experimental": return _badge_for_experimental(page, files)
65+
66+
raise RuntimeError(f"Unknown type: {type}")
67+
68+
# Create badge
69+
def _badge(icon: str, text: str = "", type: str = ""):
70+
classes = f"mdx-badge mdx-badge--{type}" if type else "mdx-badge"
71+
return "".join([
72+
f"<span class=\"{classes}\">",
73+
*([f"<span class=\"mdx-badge__icon\">{icon}</span>"] if icon else []),
74+
*([f"<span class=\"mdx-badge__text\">{text}</span>"] if text else []),
75+
f"</span>",
76+
])
77+
78+
79+
# Create badge for version
80+
def _badge_for_version(text: str, page: Page, files: Files):
81+
spec = text
82+
path = f"https://github.com/barryvdh/laravel-debugbar/releases/tag/{spec}"
83+
84+
# Return badge
85+
icon = "material-tag-outline"
86+
return _badge(
87+
icon = f"[:{icon}:]({path} 'Minimum version')",
88+
text = f"{text}" if spec else ""
89+
)
90+
91+
# Create badge for default value
92+
def _badge_for_default(text: str, page: Page, files: Files):
93+
icon = "material-water"
94+
return _badge(
95+
icon = f"[:{icon}:]('Default value')",
96+
text = text
97+
)
98+
99+
100+
# Create badge for experimental flag
101+
def _badge_for_experimental(page: Page, files: Files):
102+
icon = "material-flask-outline"
103+
return _badge(
104+
icon = f"[:{icon}:]('Experimental')",
105+
text = f"Experimental"
106+
)

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ theme:
3333
- navigation.footer
3434
- navigation.sections
3535
- navigation.expand
36+
- content.tooltips
3637
- content.code.copy
3738
- content.action.edit
3839
- toc.follow
@@ -44,6 +45,7 @@ extra_javascript:
4445
- assets/debugbar.js
4546
markdown_extensions:
4647
- admonition
48+
- abbr
4749
- attr_list
4850
- pymdownx.emoji:
4951
emoji_index: !!python/name:material.extensions.emoji.twemoji
@@ -78,3 +80,5 @@ extra:
7880
- icon: fontawesome/brands/github
7981
link: https://github.com/barryvdh/laravel-debugbar
8082

83+
hooks:
84+
- docs/overrides/shortcodes.py

0 commit comments

Comments
 (0)