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

Commit 53ec301

Browse files
committed
Fix: make Khanex and Quizly use new path to books
1 parent 12ae330 commit 53ec301

File tree

2 files changed

+56
-41
lines changed

2 files changed

+56
-41
lines changed

runestone/khanex/khanex.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from runestone.server.componentdb import addQuestionToDB, addHTMLToDB
3030
from runestone.common import RunestoneIdDirective, RunestoneIdNode
3131
from docutils import nodes
32+
3233
__author__ = "rmorelli"
3334

3435
# Debug flags
@@ -53,12 +54,14 @@ def setup(app):
5354
app.add_directive("khanex", Khanex)
5455
app.add_node(KhanexNode, html=(visit_khanex_html, depart_khanex_html))
5556

57+
5658
# The only content needed from khanex.py is the exercise name
5759

5860

5961
class KhanexNode(nodes.General, nodes.Element, RunestoneIdNode):
6062
pass
6163

64+
6265
# self for these functions is an instance of the writer class. For example
6366
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
6467
# The node that is passed as a parameter is an instance of our node class.
@@ -69,28 +72,30 @@ def visit_khanex_html(self, node):
6972
node["delimiter"] = "_start__{}_".format(node["runestone_options"]["divid"])
7073
self.body.append(node["delimiter"])
7174

72-
print('DEBUG: visit_khanex_html exername = ' + node["exername"]) if DEBUG else None
73-
print('DEBUG: visit_khanex_html template = ' + node["template"]) if DEBUG else None
74-
print('DEBUG: visit_khanex_html options = '
75-
+ str(node["runestone_options"])) if DEBUG else None
75+
print("DEBUG: visit_khanex_html exername = " + node["exername"]) if DEBUG else None
76+
print("DEBUG: visit_khanex_html template = " + node["template"]) if DEBUG else None
77+
print(
78+
"DEBUG: visit_khanex_html options = " + str(node["runestone_options"])
79+
) if DEBUG else None
7680

7781
res = node["template"] % (node["runestone_options"])
78-
print('DEBUG: visit_khanex_html res = ' + res) if DEBUG else None
82+
print("DEBUG: visit_khanex_html res = " + res) if DEBUG else None
7983
self.body.append(res)
8084

8185

8286
def depart_khanex_html(self, node):
83-
""" This is called at the start of processing an activecode node. If activecode had recursive nodes
84-
etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
85-
added here.
87+
"""This is called at the start of processing an activecode node. If activecode had recursive nodes
88+
etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
89+
added here.
8690
"""
87-
print('DEBUG: depart_khanex_html') if DEBUG else None
91+
print("DEBUG: depart_khanex_html") if DEBUG else None
8892
bc = node["runestone_options"]["basecourse"]
8993
addHTMLToDB(
9094
node["runestone_options"]["divid"],
9195
bc,
92-
"".join(self.body[self.body.index(node["delimiter"]) + 1 :])
93-
.replace("../_static", f"/runestone/books/published/{bc}/_static"),
96+
"".join(self.body[self.body.index(node["delimiter"]) + 1 :]).replace(
97+
"../_static", f"/ns/books/published/{bc}/_static"
98+
),
9499
)
95100
self.body.remove(node["delimiter"])
96101
pass
@@ -110,20 +115,21 @@ class Khanex(RunestoneIdDirective):
110115
"""
111116
.. khanex:: some_unique_id, e.g., ex1
112117
113-
:exercise: unique-ex-name:
118+
:exercise: unique-ex-name:
114119
"""
120+
115121
required_arguments = 1
116122
optional_arguments = 0
117-
has_content = True
123+
has_content = True
118124
option_spec = RunestoneIdDirective.option_spec.copy()
119-
option_spec.update( {} )
125+
option_spec.update({})
120126

121127
# This invokes the rendering code in js/khanex.js
122128
def run(self):
123129
super(Khanex, self).run()
124-
print('DEBUG; Khanex.run()') if DEBUG else None
130+
print("DEBUG; Khanex.run()") if DEBUG else None
125131

126-
addQuestionToDB(self) # Not sure whether this works?
132+
addQuestionToDB(self) # Not sure whether this works?
127133
document = self.state.document
128134
rel_filename, filename = document.settings.env.relfn2path(self.arguments[0])
129135

@@ -136,12 +142,14 @@ def run(self):
136142

137143
khanex_node = KhanexNode()
138144
khanex_node["runestone_options"] = self.options
139-
khanex_node["exername"] = str(self.options['controls'][0])
145+
khanex_node["exername"] = str(self.options["controls"][0])
140146
khanex_node["exername"] = str.strip(khanex_node["exername"][10:])
141147
khanex_node["template"] = KHANEX_TEMPLATE.replace(
142-
'###', khanex_node["exername"])
143-
144-
khanex_node["source"], khanex_node["line"] = self.state_machine.get_source_and_line(
145-
self.lineno
148+
"###", khanex_node["exername"]
146149
)
150+
151+
(
152+
khanex_node["source"],
153+
khanex_node["line"],
154+
) = self.state_machine.get_source_and_line(self.lineno)
147155
return [khanex_node]

runestone/quizly/quizly.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from runestone.server.componentdb import addQuestionToDB, addHTMLToDB
3131
from runestone.common import RunestoneIdDirective, RunestoneIdNode
3232
from docutils import nodes
33+
3334
__author__ = "rmorelli"
3435

3536
# Debug flags
@@ -55,6 +56,7 @@ def setup(app):
5556
app.add_directive("quizly", Quizly)
5657
app.add_node(QuizlyNode, html=(visit_quizly_html, depart_quizly_html))
5758

59+
5860
# The only content needed from quizly.py is the quizname
5961

6062

@@ -72,28 +74,30 @@ def visit_quizly_html(self, node):
7274
node["delimiter"] = "_start__{}_".format(node["runestone_options"]["divid"])
7375
self.body.append(node["delimiter"])
7476

75-
print('DEBUG: visit_quizly_html quizname = ' + node["quizname"]) if DEBUG else None
76-
print('DEBUG: visit_quizly_html template = ' + node["template"]) if DEBUG else None
77-
print('DEBUG: visit_quizly_html options = '
78-
+ str(node["runestone_options"])) if DEBUG else None
77+
print("DEBUG: visit_quizly_html quizname = " + node["quizname"]) if DEBUG else None
78+
print("DEBUG: visit_quizly_html template = " + node["template"]) if DEBUG else None
79+
print(
80+
"DEBUG: visit_quizly_html options = " + str(node["runestone_options"])
81+
) if DEBUG else None
7982

8083
res = node["template"] % (node["runestone_options"])
81-
print('DEBUG: visit_quizly_html res = ' + res) if DEBUG else None
84+
print("DEBUG: visit_quizly_html res = " + res) if DEBUG else None
8285
self.body.append(res)
8386

8487

8588
def depart_quizly_html(self, node):
86-
""" This is called at the start of processing an activecode node. If activecode had recursive nodes
87-
etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
88-
added here.
89+
"""This is called at the start of processing an activecode node. If activecode had recursive nodes
90+
etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
91+
added here.
8992
"""
90-
print('DEBUG: depart_quizly_html') if DEBUG else None
93+
print("DEBUG: depart_quizly_html") if DEBUG else None
9194
bc = node["runestone_options"]["basecourse"]
9295
addHTMLToDB(
9396
node["runestone_options"]["divid"],
9497
bc,
95-
"".join(self.body[self.body.index(node["delimiter"]) + 1 :])
96-
.replace("../_static", f"/runestone/books/published/{bc}/_static"),
98+
"".join(self.body[self.body.index(node["delimiter"]) + 1 :]).replace(
99+
"../_static", f"/ns/books/published/{bc}/_static"
100+
),
97101
)
98102
self.body.remove(node["delimiter"])
99103

@@ -114,6 +118,7 @@ class Quizly(RunestoneIdDirective):
114118
115119
:quizname: quiz_eval_expression
116120
"""
121+
117122
required_arguments = 1
118123
optional_arguments = 0
119124
has_content = True
@@ -122,9 +127,9 @@ class Quizly(RunestoneIdDirective):
122127

123128
def run(self):
124129
super(Quizly, self).run()
125-
print('DEBUG; Quizly.run()') if DEBUG else None
130+
print("DEBUG; Quizly.run()") if DEBUG else None
126131

127-
addQuestionToDB(self) # Not sure whether this works?
132+
addQuestionToDB(self) # Not sure whether this works?
128133
document = self.state.document
129134
rel_filename, filename = document.settings.env.relfn2path(self.arguments[0])
130135

@@ -137,14 +142,16 @@ def run(self):
137142

138143
quizly_node = QuizlyNode()
139144
quizly_node["runestone_options"] = self.options
140-
quizly_node["quizname"] = str(self.options['controls'][0])
145+
quizly_node["quizname"] = str(self.options["controls"][0])
141146
quizly_node["quizname"] = str.strip(quizly_node["quizname"][10:])
142147
quizly_node["template"] = QUIZLY_TEMPLATE.replace(
143-
'###', quizly_node["quizname"])
144-
145-
quizly_node["source"], quizly_node["line"] = self.state_machine.get_source_and_line(
146-
self.lineno
148+
"###", quizly_node["quizname"]
147149
)
148-
print('DEBUG: run() self.content = ' + str(self.content)) if DEBUG else None
149-
print('DEBUG: run() quizly_node = ' + str(quizly_node)) if DEBUG else None
150+
151+
(
152+
quizly_node["source"],
153+
quizly_node["line"],
154+
) = self.state_machine.get_source_and_line(self.lineno)
155+
print("DEBUG: run() self.content = " + str(self.content)) if DEBUG else None
156+
print("DEBUG: run() quizly_node = " + str(quizly_node)) if DEBUG else None
150157
return [quizly_node]

0 commit comments

Comments
 (0)