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

Commit b0e8ef2

Browse files
committed
progress on xml
1 parent eb8b23c commit b0e8ef2

File tree

3 files changed

+72
-27
lines changed

3 files changed

+72
-27
lines changed

runestone/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def rs2ptx(course, sourcedir, outdir):
321321
"""
322322
os.chdir(findProjectRoot())
323323
sys.path.insert(0, os.getcwd())
324+
del os.environ["DBURL"]
324325
try:
325326
import pavement
326327
except:

runestone/activecode/activecode.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ def setup(app):
6060
app.connect("env-purge-doc", purge_activecodes)
6161

6262

63+
XML_START = """
64+
<listing xml:id="{divid}">
65+
<caption>{caption}</caption>
66+
<program xml:id="{divid}_editor" interactive='yes' language="{language}">
67+
<input>
68+
{initialcode}
69+
</input>
70+
</program>
71+
</listing>
72+
73+
"""
74+
6375
TEMPLATE_START = """
6476
<div class="%(divclass)s">
6577
<div data-component="activecode" id=%(divid)s data-question_label="%(question_label)s">
@@ -85,18 +97,18 @@ class ActivecodeNode(nodes.General, nodes.Element, RunestoneIdNode):
8597

8698

8799
def visit_ac_xml(self, node):
88-
res = TEMPLATE_START % node["runestone_options"]
100+
res = XML_START.format(**node["runestone_options"])
89101
self.output.append(res)
90102

91103

92104
def depart_ac_xml(self, node):
93-
res = TEMPLATE_END % node["runestone_options"]
94-
self.output.append(res)
95-
105+
pass
96106

97107
# self for these functions is an instance of the writer class. For example
98108
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
99109
# The node that is passed as a parameter is an instance of our node class.
110+
111+
100112
def visit_ac_html(self, node):
101113
# print self.settings.env.activecodecounter
102114

runestone/mchoice/multiplechoice.py

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,49 @@ class MChoiceNode(nodes.General, nodes.Element, RunestoneIdNode):
3535
pass
3636

3737

38+
XML_START = """
39+
<exercise xml:id="{divid}">
40+
<statement>
41+
42+
"""
43+
44+
XML_START_END = """
45+
</statement>
46+
<choices>
47+
"""
48+
49+
XML_OPTION = """
50+
<choice {is_correct}>
51+
<statement>
52+
<p>{atext}</p>
53+
</statement>
54+
<feedback>
55+
<p>Incorrect: green means "go!".</p>
56+
</feedback>
57+
</choice>
58+
"""
59+
60+
XML_END = """
61+
</choices>
62+
</exercise>
63+
"""
64+
65+
TEMPLATE_START = """
66+
<div class="{divclass}">
67+
<ul data-component="multiplechoice" data-question_label="{question_label}" data-multipleanswers="{multipleAnswers}" {random} id="{divid}" {optional} style="visibility: hidden;">
68+
"""
69+
70+
OPTION = """
71+
<li data-component="answer" {is_correct} id="{divid}_opt_{alabel}">{atext}</li><li data-component="feedback">{feedtext}</li>
72+
"""
73+
74+
TEMPLATE_END = """
75+
76+
</ul>
77+
</div>
78+
"""
79+
80+
3881
def visit_mc_common(self, node):
3982

4083
res = ""
@@ -49,7 +92,7 @@ def visit_mc_common(self, node):
4992
node["runestone_options"]["multipleAnswers"] = "true"
5093
else:
5194
node["runestone_options"]["multipleAnswers"] = "false"
52-
res = node["template_start"] % node["runestone_options"]
95+
res = node["template_start"].format(**node["runestone_options"])
5396

5497
return res
5598

@@ -73,19 +116,23 @@ def depart_mc_common(self, node):
73116
node["runestone_options"]["is_correct"] = "data-correct"
74117
else:
75118
node["runestone_options"]["is_correct"] = ""
76-
res += node["template_option"] % node["runestone_options"]
119+
res += node["template_option"].format(**node["runestone_options"])
77120

78-
res += node["template_end"] % node["runestone_options"]
121+
res += node["template_end"].format(**node["runestone_options"])
79122
return res
80123

81124

82125
def visit_mc_xml(self, node):
83-
126+
node["template_start"] = XML_START
127+
node["template_end"] = XML_END
128+
node["template_option"] = XML_OPTION
129+
pdb.set_trace()
84130
res = visit_mc_common(self, node)
85131
self.output.append(res)
86132

87133

88134
def depart_mc_xml(self, node):
135+
self.output.append(XML_START_END)
89136
res = depart_mc_common(self, node)
90137
self.output.append(res)
91138

@@ -207,24 +254,9 @@ def run(self):
207254

208255
super(MChoice, self).run()
209256

210-
TEMPLATE_START = """
211-
<div class="%(divclass)s">
212-
<ul data-component="multiplechoice" data-question_label="%(question_label)s" data-multipleanswers="%(multipleAnswers)s" %(random)s id="%(divid)s" %(optional)s style="visibility: hidden;">
213-
"""
214-
215-
OPTION = """
216-
<li data-component="answer" %(is_correct)s id="%(divid)s_opt_%(alabel)s">%(atext)s</li><li data-component="feedback">%(feedtext)s</li>
217-
"""
218-
219-
TEMPLATE_END = """
220-
221-
</ul>
222-
</div>
223-
"""
224257
addQuestionToDB(self)
225258

226259
mcNode = MChoiceNode()
227-
# This is maybe a hack or maybe the new right way to do this...
228260
mcNode["runestone_options"] = self.options
229261
mcNode["source"], mcNode["line"] = self.state_machine.get_source_and_line(
230262
self.lineno)
@@ -386,8 +418,8 @@ def visit_answer_list_item(self, node):
386418

387419
# Format the HTML.
388420
self.body.append(
389-
'<li data-component="answer" %(is_correct)s id="%(divid)s_opt_%(alabel)s">'
390-
% mc_node["runestone_options"]
421+
'<li data-component="answer" {is_correct} id="{divid}_opt_{alabel}">'.format(
422+
**mc_node["runestone_options"])
391423
)
392424

393425

@@ -413,8 +445,8 @@ def visit_feedback_list_item(self, node):
413445
label = chr(answer_list_item.parent.index(answer_list_item) + ord("a"))
414446
mc_node["runestone_options"]["alabel"] = label
415447
self.body.append(
416-
'</li><li data-component="feedback" id="%(divid)s_opt_%(alabel)s">\n'
417-
% mc_node["runestone_options"]
448+
'</li><li data-component="feedback" id="{divid}_opt_{alabel}">\n'.format(
449+
**mc_node["runestone_options"])
418450
)
419451

420452

0 commit comments

Comments
 (0)