Skip to content

Commit 5e4ea4c

Browse files
gjchong25Grace Chong
andauthored
(DOP-2600) Directive for cta-banner (#380)
* (DOP-2600) Create CTA banner directive for guides * add test for cta-banner * fix formatting * add error handling and diagnostics for missing url option * make cta-banner a mdb directive * remove unnecessary diagnostic check Co-authored-by: Grace Chong <[email protected]>
1 parent 9608dc1 commit 5e4ea4c

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

snooty/rstspec.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,15 @@ example = """.. banner::
643643
${2:banner content}
644644
"""
645645

646+
[directive."mongodb:cta-banner"]
647+
content_type = "block"
648+
options.url = { type = "uri", required = true }
649+
example = """.. cta-banner::
650+
:url: https://university.mongodb.com/
651+
652+
${2:Banner Text content}
653+
"""
654+
646655
[directive."mongodb:button"]
647656
help = "Make a button."
648657
example = """.. button:: ${1: string}

snooty/test_parser.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,62 @@ def test_banner() -> None:
893893
)
894894

895895

896+
def test_cta_banner() -> None:
897+
path = ROOT_PATH.joinpath(Path("test.rst"))
898+
project_config = ProjectConfig(ROOT_PATH, "", source="./")
899+
parser = rstparser.Parser(project_config, JSONVisitor)
900+
901+
# Test valid cta-banner
902+
page, diagnostics = parse_rst(
903+
parser,
904+
path,
905+
"""
906+
.. cta-banner::
907+
:url: https://university.mongodb.com/
908+
909+
If you prefer learning through videos, try this lesson on `MongoDB University
910+
<https://university.mongodb.com/>`_
911+
""",
912+
)
913+
page.finish(diagnostics)
914+
assert diagnostics == []
915+
check_ast_testing_string(
916+
page.ast,
917+
"""<root fileid="test.rst">
918+
<directive domain="mongodb" name="cta-banner" url="https://university.mongodb.com/">
919+
<paragraph><text>If you prefer learning through videos, try this lesson on </text>
920+
<reference refuri="https://university.mongodb.com/"><text>MongoDB University</text></reference>
921+
<named_reference refname="MongoDB University" refuri="https://university.mongodb.com/"></named_reference>
922+
</paragraph>
923+
</directive></root>""",
924+
)
925+
926+
# Test cta-banner without url option specified
927+
page, diagnostics = parse_rst(
928+
parser,
929+
path,
930+
"""
931+
.. cta-banner::
932+
933+
If you prefer learning through videos, try this lesson on `MongoDB University
934+
<https://university.mongodb.com/>`_
935+
""",
936+
)
937+
page.finish(diagnostics)
938+
assert len(diagnostics) == 1
939+
assert isinstance(diagnostics[0], DocUtilsParseError)
940+
check_ast_testing_string(
941+
page.ast,
942+
"""<root fileid="test.rst">
943+
<directive domain="mongodb" name="cta-banner">
944+
<paragraph><text>If you prefer learning through videos, try this lesson on </text>
945+
<reference refuri="https://university.mongodb.com/"><text>MongoDB University</text></reference>
946+
<named_reference refname="MongoDB University" refuri="https://university.mongodb.com/"></named_reference>
947+
</paragraph>
948+
</directive></root>""",
949+
)
950+
951+
896952
def test_rst_replacement() -> None:
897953
path = ROOT_PATH.joinpath(Path("test.rst"))
898954
project_config = ProjectConfig(ROOT_PATH, "", source="./")

0 commit comments

Comments
 (0)