Skip to content

Commit a15afa3

Browse files
committed
👌 warn if grid/tab item not in parent
1 parent f6f2235 commit a15afa3

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ grids items cannot contain headers; is this in anyway possible with docutils str
4848

4949
naming of directives/roles: standard prefix?
5050

51+
check grid-items and tab-items are inside parents (or auto-wrap?)
52+
5153
handle latex
5254

5355
card header/footer syntax?

sphinx_design/cards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CardDirective(SphinxDirective):
3838
optional_arguments = 1 # card title
3939
final_argument_whitespace = True
4040
option_spec = {
41-
# TODO adaptive width/ width based on content
41+
# TODO adaptive width based on content
4242
"width": make_choice(["auto", "25", "50", "75", "100"]),
4343
"margin": margin_option,
4444
"text-align": text_align,

sphinx_design/grids.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def setup_grids(app: Sphinx):
3030
app.add_directive(DIRECTIVE_NAME_GRID, GridDirective)
3131
app.add_directive(DIRECTIVE_NAME_GRID_ITEM, GridItemDirective)
3232
app.add_directive(DIRECTIVE_NAME_GRID_ITEM_CARD, GridItemCardDirective)
33-
# TODO check all grid items have grid-row parents (or auto wrap in grid?)
3433

3534

3635
def _media_option(
@@ -169,6 +168,13 @@ class GridItemDirective(SphinxDirective):
169168
def run(self) -> List[nodes.Node]:
170169
"""Run the directive."""
171170
self.assert_has_content()
171+
if not is_component(self.state_machine.node, "grid-row"):
172+
LOGGER.warning(
173+
f"The parent of a 'grid-item' should be a 'grid-row' [{WARNING_TYPE}.grid]",
174+
location=(self.env.docname, self.lineno),
175+
type=WARNING_TYPE,
176+
subtype="grid",
177+
)
172178
column = create_component(
173179
"grid-item",
174180
[
@@ -213,6 +219,13 @@ class GridItemCardDirective(SphinxDirective):
213219
def run(self) -> List[nodes.Node]:
214220
"""Run the directive."""
215221
self.assert_has_content()
222+
if not is_component(self.state_machine.node, "grid-row"):
223+
LOGGER.warning(
224+
f"The parent of a 'grid-item' should be a 'grid-row' [{WARNING_TYPE}.grid]",
225+
location=(self.env.docname, self.lineno),
226+
type=WARNING_TYPE,
227+
subtype="grid",
228+
)
216229
column = create_component(
217230
"grid-item",
218231
[

sphinx_design/tabs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ class TabItemDirective(SphinxDirective):
8282
def run(self) -> List[nodes.Node]:
8383
"""Run the directive."""
8484
self.assert_has_content()
85+
if not is_component(self.state_machine.node, "tab-set"):
86+
LOGGER.warning(
87+
f"The parent of a 'tab-item' should be a 'tab-set' [{WARNING_TYPE}.tab]",
88+
location=(self.env.docname, self.lineno),
89+
type=WARNING_TYPE,
90+
subtype="tab",
91+
)
8592
tab_item = create_component(
8693
"tab-item",
8794
classes=["sd-tab-item"] + self.options.get("class", []),

0 commit comments

Comments
 (0)