Skip to content

Commit 7270ba1

Browse files
committed
✨ Add multi-theme doc generation
1 parent 61bd7f9 commit 7270ba1

File tree

14 files changed

+121
-61
lines changed

14 files changed

+121
-61
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# sphinx-design (IN-DEVELOPMENT)
22

3-
A sphinx extension for designing beautiful, size responsive web components.
3+
A sphinx extension for designing beautiful, view size responsive web components.
44

55
Created with inspiration from [Bootstrap](https://getbootstrap.com/) (v5), [Material Design](https://material.io) and [Material-UI](https://material-ui.com/) design frameworks.
66

@@ -53,5 +53,8 @@ card header/footer syntax?
5353

5454
Use autoprefixer when compiling SASS (see <https://getbootstrap.com/docs/5.0/getting-started/browsers-devices/#supported-browsers>)
5555

56-
horizontal card (grid row inside card),
56+
horizontal card (grid row inside card, picture on left)
57+
5758
avatars (rounded images)
59+
60+
horizontally scrollable cards: (see <https://stackoverflow.com/questions/35993300/horizontally-scrollable-list-of-cards-in-bootstrap>)

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"""Configuration file for the Sphinx documentation builder."""
2+
import os
23

34
project = "Sphinx Design"
45
copyright = "2021, Executable Book Project"
56
author = "Executable Book Project"
67

78
extensions = ["myst_parser", "sphinx_design"]
89

10+
html_theme = os.environ.get("SPHINX_THEME", "alabaster")
11+
html_title = f"Sphinx Design ({html_theme})"
12+
913
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
1014
myst_enable_extensions = ["colon_fence", "substitution"]
1115

docs/index.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@ A sphinx extension for designing beautiful, size responsive web components.
44

55
Created with inspiration from [Bootstrap](https://getbootstrap.com/) (v5), [Material Design](https://material.io) and [Material-UI](https://material-ui.com/) design frameworks.
66

7+
## Cards
8+
9+
:::{card}
10+
:width: 25
11+
:margin: 0 2 auto auto
12+
:text-align: center
13+
14+
align center
15+
:::
16+
17+
:::{card}
18+
:width: 50
19+
:margin: 0 2 auto 0
20+
:text-align: right
21+
22+
align right
23+
:::
24+
25+
:::{card}
26+
:width: 50
27+
:margin: 0 2 0 auto
28+
:text-align: left
29+
30+
align left
31+
:::
32+
33+
paragraph
34+
735
## Grids
836

937
::::{grid}
@@ -78,22 +106,6 @@ next paragraph 1
78106

79107
::::
80108

81-
## Cards
82-
83-
:::{card}
84-
:width: 25
85-
:align: center
86-
87-
align center
88-
:::
89-
90-
:::{card}
91-
:width: 50
92-
:align: right
93-
94-
align right
95-
:::
96-
97109
(badges)=
98110

99111
## Badges
@@ -147,6 +159,7 @@ Button text
147159
```
148160

149161
:::{card} Card with an expanded button
162+
:hover:
150163

151164
```{button-link} https://example.com
152165
:color: info

setup.cfg

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22
name = sphinx_design
33
version = attr: sphinx_design.__version__
4-
description = A sphinx extension for designing beautiful, size responsive web components.
4+
description = A sphinx extension for designing beautiful, view size responsive web components.
55
long_description = file: README.md
66
long_description_content_type = text/markdown
77
url = https://github.com/executablebooks/sphinx-design
@@ -41,6 +41,14 @@ testing =
4141
pytest~=5.4
4242
pytest-cov
4343
pytest-regressions
44+
theme_furo =
45+
furo==2021.7.5b38
46+
theme_pydata =
47+
pydata-sphinx-theme~=0.6.0
48+
theme_rtd =
49+
sphinx-rtd-theme~=0.5.0
50+
theme_sbt =
51+
sphinx-book-theme~=0.1.0
4452

4553
[options.packages.find]
4654
exclude =

sphinx_design/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""A sphinx extension for designing beautiful, size responsive web components."""
1+
"""A sphinx extension for designing beautiful, view size responsive web components."""
22
from typing import TYPE_CHECKING
33

44
__version__ = "0.0.1"

sphinx_design/badges_buttons.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class _ButtonDirective(SphinxDirective):
147147

148148
def create_ref_node(
149149
self, rawtext: str, target: str, explicit_title: bool, classes: List[str]
150-
):
150+
) -> nodes.Node:
151151
"""Create the reference node."""
152152
raise NotImplementedError
153153

@@ -197,7 +197,7 @@ class ButtonLinkDirective(_ButtonDirective):
197197

198198
def create_ref_node(
199199
self, rawtext: str, target: str, explicit_title: bool, classes: List[str]
200-
):
200+
) -> nodes.Node:
201201
"""Create the reference node."""
202202
return nodes.reference(
203203
rawtext,
@@ -211,14 +211,14 @@ class ButtonRefDirective(_ButtonDirective):
211211

212212
def create_ref_node(
213213
self, rawtext: str, target: str, explicit_title: bool, classes: List[str]
214-
):
214+
) -> nodes.Node:
215215
"""Create the reference node."""
216216
options = {
217217
"classes": classes,
218218
"reftarget": target,
219219
"refdoc": self.env.docname,
220220
"refdomain": "",
221-
"reftype": "any",
221+
"reftype": "any", # TODO allow for variable ref type
222222
"refexplicit": explicit_title,
223223
"refwarn": True,
224224
}

sphinx_design/cards.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sphinx.application import Sphinx
88
from sphinx.util.docutils import SphinxDirective
99

10-
from .shared import create_component, make_choice, text_align
10+
from .shared import create_component, make_choice, margin_option, text_align
1111

1212
DIRECTIVE_NAME_CARD = "card"
1313
REGEX_HEADER = re.compile(r"^\^{3,}\s*$")
@@ -40,11 +40,12 @@ class CardDirective(SphinxDirective):
4040
option_spec = {
4141
# TODO adaptive width/ width based on content
4242
"width": make_choice(["auto", "25", "50", "75", "100"]),
43-
"align": make_choice(["left", "center", "right"]),
43+
"margin": margin_option,
4444
"text-align": text_align,
4545
"img-top": directives.uri,
4646
"img-bottom": directives.uri,
4747
"no-shadow": directives.flag,
48+
"hover": directives.flag,
4849
"class-card": directives.class_option,
4950
"class-header": directives.class_option,
5051
"class-body": directives.class_option,
@@ -64,15 +65,12 @@ def create_card(
6465
card_classes = ["sd-card", "sd-sphinx-override"]
6566
if "width" in options:
6667
card_classes += [f'sd-w-{options["width"]}']
67-
if "align" in options:
68-
align_class = {
69-
"center": "sd-mx-auto",
70-
"left": "sd-mr-auto",
71-
"right": "sd-ml-auto",
72-
}[options["align"]]
73-
card_classes += [align_class]
68+
if "margin" in options:
69+
card_classes += options["margin"]
7470
if "no-shadow" not in options:
7571
card_classes += ["sd-shadow"]
72+
if "hover" in options:
73+
card_classes += ["sd-card-hover"]
7674
card = create_component(
7775
"card",
7876
card_classes

sphinx_design/compiled/style.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sphinx_design/grids.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class GridItemCardDirective(SphinxDirective):
198198
"img-top": directives.uri,
199199
"img-bottom": directives.uri,
200200
"no-shadow": directives.flag,
201+
"hover": directives.flag,
201202
"class-item": directives.class_option,
202203
"class-card": directives.class_option,
203204
"class-body": directives.class_option,
@@ -229,6 +230,7 @@ def run(self) -> List[nodes.Node]:
229230
"img-top",
230231
"img-bottom",
231232
"no-shadow",
233+
"hover",
232234
"class-card",
233235
"class-body",
234236
"class-title",

sphinx_design/shared.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@ def make_choice(choices: Sequence[str]):
3535
return lambda argument: directives.choice(argument, choices)
3636

3737

38-
def _margin_or_padding_option(argument: Optional[str], class_prefix: str) -> List[str]:
38+
def _margin_or_padding_option(
39+
argument: Optional[str],
40+
class_prefix: str,
41+
allowed: Sequence[str],
42+
) -> List[str]:
3943
"""Validate the margin/padding is one (all) or four (top bottom left right) integers,
40-
between 0 and 5.
44+
between 0 and 5 or 'auto'.
4145
"""
4246
if argument is None:
4347
raise ValueError("argument required but none supplied")
4448
values = argument.split()
45-
try:
46-
int_values = [int(value) for value in values]
47-
except Exception:
48-
raise ValueError("argument must be space separated list of integers")
49-
for value in int_values:
50-
if not 0 <= value <= 5:
51-
raise ValueError("argument must be integers in range 0 to 5")
49+
for value in values:
50+
if value not in allowed:
51+
raise ValueError(f"{value} is not in: {allowed}")
5252
if len(values) == 1:
5353
return [f"{class_prefix}-{values[0]}"]
5454
if len(values) == 4:
5555
return [
5656
f"{class_prefix}{side}-{value}"
57-
for side, value in zip(["t", "b", "l", "r"], int_values)
57+
for side, value in zip(["t", "b", "l", "r"], values)
5858
]
5959
raise ValueError(
6060
"argument must be one (all) or four (top bottom left right) integers"
@@ -63,16 +63,18 @@ def _margin_or_padding_option(argument: Optional[str], class_prefix: str) -> Lis
6363

6464
def margin_option(argument: Optional[str]) -> List[str]:
6565
"""Validate the margin is one (all) or four (top bottom left right) integers,
66-
between 0 and 5.
66+
between 0 and 5 or 'auto'.
6767
"""
68-
return _margin_or_padding_option(argument, "sd-m")
68+
return _margin_or_padding_option(
69+
argument, "sd-m", ("auto", "0", "1", "2", "3", "4", "5")
70+
)
6971

7072

7173
def padding_option(argument: Optional[str]) -> List[str]:
7274
"""Validate the padding is one (all) or four (top bottom left right) integers,
7375
between 0 and 5.
7476
"""
75-
return _margin_or_padding_option(argument, "sd-p")
77+
return _margin_or_padding_option(argument, "sd-p", ("0", "1", "2", "3", "4", "5"))
7678

7779

7880
def text_align(argument: Optional[str]) -> List[str]:

style/_button.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,22 @@
5959
color: var(--sd-color-#{$color}-text) !important;
6060
background-color: var(--sd-color-#{$color}) !important;
6161
border-color: var(--sd-color-#{$color}) !important;
62-
border: 1px solid !important;
62+
border-width: 1px !important;
63+
border-style: solid !important;
6364
}
6465
.sd-btn-#{$color}:hover,
6566
.sd-btn-#{$color}:focus {
6667
color: var(--sd-color-#{$color}-text) !important;
6768
background-color: var(--sd-color-#{$color}-highlight) !important;
6869
border-color: var(--sd-color-#{$color}-highlight) !important;
69-
border: 1px solid !important;
70+
border-width: 1px !important;
71+
border-style: solid !important;
7072
}
7173
.sd-btn-outline-#{$color} {
7274
color: var(--sd-color-#{$color}) !important;
7375
border-color: var(--sd-color-#{$color}) !important;
74-
border: 1px solid !important;
76+
border-width: 1px !important;
77+
border-style: solid !important;
7578
}
7679
}
7780

@@ -85,5 +88,3 @@
8588
z-index: 1;
8689
content: "";
8790
}
88-
89-
//

style/_cards.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
background-color: var(--sd-color-card-background);
99
border: 1px solid var(--sd-color-card-border);
1010
border-radius: 0.25rem;
11+
color: var(--sd-color-card-text);
1112
display: -ms-flexbox;
1213
display: flex;
1314
-ms-flex-direction: column;
@@ -22,6 +23,10 @@
2223
}
2324
}
2425

26+
.sd-card-hover:hover {
27+
border-color: var(--sd-color-card-border-hover);
28+
}
29+
2530
.sd-card-body {
2631
-ms-flex: 1 1 auto;
2732
flex: 1 1 auto;

style/_colors.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $black-0: rgba(0, 0, 0, 0) !default;
1414
$black-3: rgba(0, 0, 0, .03) !default;
1515
$black-12-5: rgba(0, 0, 0, .125) !default;
1616
$black-15: rgba(0, 0, 0, .15) !default;
17+
$black-25: rgba(0, 0, 0, .25) !default;
1718
$black-50: rgba(0, 0, 0, .5) !default;
1819

1920
$blue: #007bff !default;
@@ -61,9 +62,11 @@ $semantic-colors: (
6162
--sd-color-shadow: #{$black-15};
6263
// cards
6364
--sd-color-card-border: #{$black-12-5};
64-
--sd-color-card-background: #{$white};
65-
--sd-color-card-header: #{$black-3};
66-
--sd-color-card-footer: #{$black-3};
65+
--sd-color-card-border-hover: #{$black-25};
66+
--sd-color-card-background: transparent;
67+
--sd-color-card-text: inherit;
68+
--sd-color-card-header: transparent;
69+
--sd-color-card-footer: transparent;
6770
}
6871

6972
.sd-bg-transparent {

0 commit comments

Comments
 (0)