Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 3c975c9

Browse files
committed
Convert all directives to dict style nodes
1 parent 1712a26 commit 3c975c9

File tree

31 files changed

+612
-628
lines changed

31 files changed

+612
-628
lines changed

runestone/activecode/activecode.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def setup(app):
5353
app.add_config_value("activecode_hide_load_history", False, "html")
5454
app.add_config_value("wasm_uri", "/_static", "html")
5555

56-
app.add_node(ActivecodeNode, html=(visit_ac_node, depart_ac_node),
56+
app.add_node(ActivecodeNode, html=(visit_ac_html, depart_ac_html),
5757
xml=(visit_ac_xml, depart_ac_xml))
5858

5959
app.connect("doctree-resolved", process_activcode_nodes)
@@ -97,13 +97,9 @@ def depart_ac_xml(self, node):
9797
# self for these functions is an instance of the writer class. For example
9898
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
9999
# The node that is passed as a parameter is an instance of our node class.
100-
def visit_ac_node(self, node):
100+
def visit_ac_html(self, node):
101101
# print self.settings.env.activecodecounter
102102

103-
# todo: handle above in node["runestone_options"]
104-
# todo handle 'hidecode' not in node["runestone_options"]:
105-
# todo: handle if 'gradebutton' in node["runestone_options"]: res += GRADES
106-
107103
node["delimiter"] = "_start__{}_".format(node["runestone_options"]["divid"])
108104

109105
self.body.append(node["delimiter"])
@@ -112,9 +108,9 @@ def visit_ac_node(self, node):
112108
self.body.append(res)
113109

114110

115-
def depart_ac_node(self, node):
111+
def depart_ac_html(self, node):
116112
"""This is called at the start of processing an activecode node. If activecode had recursive nodes
117-
etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
113+
etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
118114
added here.
119115
"""
120116
res = TEMPLATE_END % node["runestone_options"]
@@ -451,7 +447,7 @@ def run(self):
451447
"This should only affect the grading interface. Everything else should be fine."
452448
)
453449

454-
acnode = ActivecodeNode(self.options, rawsource=self.block_text)
450+
acnode = ActivecodeNode()
455451
acnode["runestone_options"] = self.options
456452
acnode["source"], acnode["line"] = self.state_machine.get_source_and_line(
457453
self.lineno)

runestone/assignment/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
def setup(app):
3838
app.add_directive("assignment", Assignment)
39-
app.add_node(AssignmentNode, html=(visit_a_node, depart_a_node))
39+
app.add_node(AssignmentNode, html=(visit_a_html, depart_a_html))
4040

4141
app.connect("doctree-resolved", process_nodes)
4242
app.connect("env-purge-doc", purge)
@@ -54,13 +54,13 @@ def __init__(self, content, **kwargs):
5454
self.a_components = content
5555

5656

57-
def visit_a_node(self, node):
57+
def visit_a_html(self, node):
5858
pass
5959

6060

61-
def depart_a_node(self, node):
62-
question_ids = node.a_components["question_ids"]
63-
basecourse = node.a_components["basecourse"]
61+
def depart_a_html(self, node):
62+
question_ids = node["a_components"]["question_ids"]
63+
basecourse = node["a_components"]["basecourse"]
6464
for q_id in question_ids:
6565
src = get_HTML_from_DB(q_id, basecourse)
6666
if src:

runestone/blockly/blockly.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
def setup(app):
3434
app.add_directive("blockly", Blockly)
3535

36-
app.add_node(BlocklyNode, html=(visit_block_node, depart_block_node))
36+
app.add_node(BlocklyNode, html=(visit_block_html, depart_block_html))
3737

3838
app.connect("doctree-resolved", process_activcode_nodes)
3939
app.connect("env-purge-doc", purge_activecodes)
@@ -154,10 +154,12 @@ def __init__(self, content, **kwargs):
154154
# self for these functions is an instance of the writer class. For example
155155
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
156156
# The node that is passed as a parameter is an instance of our node class.
157-
def visit_block_node(self, node):
158-
res = START % (node.runestone_options)
157+
158+
159+
def visit_block_html(self, node):
160+
res = START % (node["runestone_options"])
159161
res += CTRL_START
160-
for ctrl in node.runestone_options["controls"]:
162+
for ctrl in node["runestone_options"]["controls"]:
161163
if ctrl == "variables":
162164
res += '<category name="Variables" custom="VARIABLE"></category>'
163165
elif ctrl == "":
@@ -169,11 +171,11 @@ def visit_block_node(self, node):
169171
else:
170172
res += '<block type="%s"></block>\n' % (ctrl)
171173
res += CTRL_END
172-
res += END % (node.runestone_options)
174+
res += END % (node["runestone_options"])
173175
path = os.path.join(
174-
node.runestone_options["blocklyHomePrefix"],
176+
node["runestone_options"]["blocklyHomePrefix"],
175177
"_static",
176-
node.runestone_options["divid"] + ".html",
178+
node["runestone_options"]["divid"] + ".html",
177179
)
178180
final = (
179181
'<iframe class="blk-iframe" seamless src="%s" width="600" '
@@ -185,9 +187,9 @@ def visit_block_node(self, node):
185187
self.body.append(final)
186188

187189

188-
def depart_block_node(self, node):
190+
def depart_block_html(self, node):
189191
""" This is called at the start of processing an activecode node. If activecode had recursive nodes
190-
etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
192+
etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
191193
added here.
192194
"""
193195
pass

runestone/cellbotics/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BlePairNode(nodes.General, nodes.Element):
3131
pass
3232

3333

34-
def visit_ble_pair_node(self, node):
34+
def visit_ble_pair_html(self, node):
3535
self.body.append(
3636
'<div data-component="ble">\n'
3737
' <script>runestone_import("ble");</script>\n'
@@ -41,7 +41,7 @@ def visit_ble_pair_node(self, node):
4141
)
4242

4343

44-
def depart_ble_pair_node(self, node):
44+
def depart_ble_pair_html(self, node):
4545
pass
4646

4747

@@ -57,5 +57,5 @@ def run(self):
5757

5858
def setup(app):
5959
# Add the Pair button directive.
60-
app.add_node(BlePairNode, html=(visit_ble_pair_node, depart_ble_pair_node))
60+
app.add_node(BlePairNode, html=(visit_ble_pair_html, depart_ble_pair_html))
6161
app.add_directive('ble-pair-button', BlePairDirective)

runestone/clickableArea/clickable.py

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
def setup(app):
3030
app.add_directive("clickablearea", ClickableArea)
3131

32-
app.add_node(ClickableAreaNode, html=(visit_ca_node, depart_ca_node))
32+
app.add_node(ClickableAreaNode, html=(visit_ca_html, depart_ca_html))
3333

3434
app.add_config_value("clickable_div_class", "runestone alert alert-warning", "html")
3535

@@ -46,60 +46,53 @@ def setup(app):
4646

4747

4848
class ClickableAreaNode(nodes.General, nodes.Element, RunestoneIdNode):
49-
def __init__(self, content, **kwargs):
50-
"""
51-
Arguments:
52-
- `self`:
53-
- `content`:
54-
"""
55-
super(ClickableAreaNode, self).__init__(**kwargs)
56-
self.runestone_options = content
49+
pass
5750

5851

5952
# self for these functions is an instance of the writer class. For example
6053
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
6154
# The node that is passed as a parameter is an instance of our node class.
62-
def visit_ca_node(self, node):
55+
def visit_ca_html(self, node):
6356
res = TEMPLATE
6457

65-
node.delimiter = "_start__{}_".format(node.runestone_options["divid"])
66-
self.body.append(node.delimiter)
58+
node["delimiter"] = "_start__{}_".format(node["runestone_options"]["divid"])
59+
self.body.append(node["delimiter"])
6760

68-
if "feedback" in node.runestone_options:
69-
node.runestone_options["feedback"] = (
70-
"<span data-feedback>" + node.runestone_options["feedback"] + "</span>"
61+
if "feedback" in node["runestone_options"]:
62+
node["runestone_options"]["feedback"] = (
63+
"<span data-feedback>" + node["runestone_options"]["feedback"] + "</span>"
7164
)
7265
else:
73-
node.runestone_options["feedback"] = ""
66+
node["runestone_options"]["feedback"] = ""
7467

75-
if "iscode" not in node.runestone_options:
76-
node.runestone_options["correct"] = (
77-
"data-cc=" + '"' + node.runestone_options["correct"] + '"'
68+
if "iscode" not in node["runestone_options"]:
69+
node["runestone_options"]["correct"] = (
70+
"data-cc=" + '"' + node["runestone_options"]["correct"] + '"'
7871
)
79-
node.runestone_options["incorrect"] = (
80-
"data-ci=" + '"' + node.runestone_options["incorrect"] + '"'
72+
node["runestone_options"]["incorrect"] = (
73+
"data-ci=" + '"' + node["runestone_options"]["incorrect"] + '"'
8174
)
8275
else:
83-
node.runestone_options["correct"] = ""
84-
node.runestone_options["incorrect"] = ""
76+
node["runestone_options"]["correct"] = ""
77+
node["runestone_options"]["incorrect"] = ""
8578

86-
res = res % node.runestone_options
79+
res = res % node["runestone_options"]
8780

8881
self.body.append(res)
8982

9083

91-
def depart_ca_node(self, node):
84+
def depart_ca_html(self, node):
9285
res = ""
93-
res = TEMPLATE_END % node.runestone_options
86+
res = TEMPLATE_END % node["runestone_options"]
9487
self.body.append(res)
9588

9689
addHTMLToDB(
97-
node.runestone_options["divid"],
98-
node.runestone_options["basecourse"],
99-
"".join(self.body[self.body.index(node.delimiter) + 1 :]),
90+
node["runestone_options"]["divid"],
91+
node["runestone_options"]["basecourse"],
92+
"".join(self.body[self.body.index(node["delimiter"]) + 1 :]),
10093
)
10194

102-
self.body.remove(node.delimiter)
95+
self.body.remove(node["delimiter"])
10396

10497

10598
class ClickableArea(RunestoneIdDirective):
@@ -166,11 +159,12 @@ def run(self):
166159
self.options["clickcode"] = source
167160
else:
168161
self.options["clickcode"] = ""
169-
clickNode = ClickableAreaNode(self.options, rawsource=self.block_text)
170-
clickNode.source, clickNode.line = self.state_machine.get_source_and_line(
162+
clickNode = ClickableAreaNode()
163+
clickNode["runestone_options"] = self.options
164+
clickNode["source"], clickNode["line"] = self.state_machine.get_source_and_line(
171165
self.lineno
172166
)
173-
clickNode.template_start = TEMPLATE
167+
clickNode["template_start"] = TEMPLATE
174168

175169
if "table" in self.options:
176170
self.options["table"] = "data-table"

runestone/codelens/visualizer.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def setup(app):
3131

3232
app.add_config_value("codelens_div_class", "alert alert-warning cd_section", "html")
3333
app.add_config_value("trace_url", "http://tracer.runestone.academy:5000", "html")
34-
app.add_node(CodeLensNode, html=(visit_codelens_node, depart_codelens_node))
34+
app.add_node(CodeLensNode, html=(visit_codelens_html, depart_codelens_html))
3535

3636

3737
# data-tracefile="pytutor-embed-demo/java.json"
@@ -62,28 +62,26 @@ def setup(app):
6262

6363

6464
class CodeLensNode(nodes.General, nodes.Element, RunestoneIdNode):
65-
def __init__(self, content, **kwargs):
66-
super().__init__(**kwargs)
67-
self.runestone_options = content
65+
pass
6866

6967

70-
def visit_codelens_node(self, node):
68+
def visit_codelens_html(self, node):
7169
html = VIS
72-
if "caption" not in node.runestone_options:
73-
node.runestone_options["caption"] = node.runestone_options["question_label"]
74-
if "tracedata" in node.runestone_options:
70+
if "caption" not in node["runestone_options"]:
71+
node["runestone_options"]["caption"] = node["runestone_options"]["question_label"]
72+
if "tracedata" in node["runestone_options"]:
7573
html += DATA
7674
else:
7775
html += "</div>"
78-
html = html % node.runestone_options
76+
html = html % node["runestone_options"]
7977

8078
self.body.append(html)
8179
addHTMLToDB(
82-
node.runestone_options["divid"], node.runestone_options["basecourse"], html
80+
node["runestone_options"]["divid"], node["runestone_options"]["basecourse"], html
8381
)
8482

8583

86-
def depart_codelens_node(self, node):
84+
def depart_codelens_html(self, node):
8785
pass
8886

8987

@@ -227,8 +225,9 @@ def js_var_finalizer(input_code, output_trace):
227225
else:
228226
raise ValueError("language not supported")
229227

230-
cl_node = CodeLensNode(self.options, rawsource=self.block_text)
231-
cl_node.source, cl_node.line = self.state_machine.get_source_and_line(
228+
cl_node = CodeLensNode()
229+
cl_node["runestone_options"] = self.options
230+
cl_node["source"], cl_node["line"] = self.state_machine.get_source_and_line(
232231
self.lineno
233232
)
234233
return [cl_node]

runestone/common/question_number.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# After the section numbers are available from the TOC tree, determine the section number for each Runestone component with an ID.
1919
def _insert_qnum(app, doctree, docname):
2020
toc = app.env.toc_secnumbers.get(docname, {})
21-
pdb.set_trace()
2221
# Return the section number tuple for the given ``section_ref`` if it exists, or None if not.
2322

2423
def get_secnum_tuple(section_ref):
@@ -49,9 +48,12 @@ def get_secnum_tuple(section_ref):
4948
question_number_str = ".".join(map(str, question_number_tuple))
5049
# Update the database.
5150
addQNumberToDB(app, node, question_number_str)
52-
pdb.set_trace()
53-
div_id = node["runestone_options"]["divid"]
54-
node["runestone_options"]["question_label"] = question_number_str
51+
try:
52+
div_id = node["runestone_options"]["divid"]
53+
node["runestone_options"]["question_label"] = question_number_str
54+
except:
55+
div_id = node.runestone_options["divid"]
56+
node.runestone_options["question_label"] = question_number_str
5557
# Prepare to number the next question.
5658
current_question_number += 1
5759
else:

0 commit comments

Comments
 (0)