Skip to content

Commit

Permalink
Add a custom role for inline '$ gel ..' commands
Browse files Browse the repository at this point in the history
  • Loading branch information
1st1 committed Feb 14, 2025
1 parent 10968b9 commit 696acdd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/intro/instances.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
Instances
=========

test |gelcmd|

test2 :gelcmd:`migrate --help`


Let's get to the good stuff. You can spin up an Gel instance with a single
command.

Expand Down
29 changes: 26 additions & 3 deletions edb/tools/docs/edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,38 @@ def apply(self):
nt = node.astext()
if nt in {"Gel", "EdgeDB", "gelcmd", ".gel", "gel.toml"}:
if builder_name in {"xml", "edge-xml"}:
sub = d_nodes.inline(
nt, nt, **{"edb-substitution": "true"}
)
if nt == "gelcmd":
sub = d_nodes.literal(
'gel', 'gel',
**{
"edb-gelcmd": "true",
"edb-gelcmd-top": "true",
"edb-substitution": "true",
}
)
else:
sub = d_nodes.inline(
nt, nt, **{"edb-substitution": "true"}
)
node.replace_self(sub)
else:
node.replace_self(d_nodes.Text(nt))

class GelCmdRole:

def __call__(
self, role, rawtext, text, lineno, inliner, options=None, content=None
):
text = f'gel {text.strip()}'
node = d_nodes.literal(text, text)
node["edb-gelcmd"] = "true"
node["edb-gelcmd-top"] = "false"
node["edb-substitution"] = "true"
return [node], []


def setup_domain(app):
app.add_role('gelcmd', GelCmdRole())
app.add_domain(GelDomain)
app.add_transform(GelSubstitutionTransform)

Expand Down
34 changes: 33 additions & 1 deletion tests/test_docs_sphinx_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,6 @@ def test_sphinx_edb_brand_name_01(self):
'''

out = self.build(src, format='xml')
print(out, '\n')
x = requests_xml.XML(xml=out)

self.assertEqual(
Expand All @@ -967,3 +966,36 @@ def test_sphinx_edb_brand_name_01(self):


print(x)

def test_sphinx_edb_brand_name_02(self):
src = '''
blah |gelcmd|
blah 2 :gelcmd:`migrate --help`
DONE
'''

out = self.build(src, format='xml')
x = requests_xml.XML(xml=out)

self.assertEqual(
x.xpath('''
//paragraph/literal
[@edb-substitution="true"]
[@edb-gelcmd="true"]
[@edb-gelcmd-top="true"]
/ text()
'''),
['gel'])

self.assertEqual(
x.xpath('''
//paragraph/literal
[@edb-substitution="true"]
[@edb-gelcmd="true"]
[@edb-gelcmd-top="false"]
/ text()
'''),
['gel migrate --help'])

0 comments on commit 696acdd

Please sign in to comment.