Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions runestone/activecode/activecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def setup(app):
app.add_directive('activecode', ActiveCode)
app.add_directive('actex', ActiveExercise)
app.add_role('textfield',textfield_role)
app.add_config_value('activecode_div_class', "runestone explainer ac_section alert alert-warning", 'html')
app.add_config_value('activecode_hide_load_history', False, 'html')

app.add_stylesheet('activecode.css')

app.add_javascript('jquery.highlight.js')
Expand All @@ -59,14 +62,14 @@ def setup(app):


TEMPLATE_START = """
<div data-childcomponent="%(divid)s" class="runestone explainer ac_section alert alert-warning">
<div data-childcomponent="%(divid)s" class="%(divclass)s">
"""

TEMPLATE_END = """
<textarea data-component="activecode" id=%(divid)s data-lang="%(language)s" %(autorun)s
%(hidecode)s %(include)s %(timelimit)s %(coach)s %(codelens)s %(enabledownload)s %(chatcodes)s
data-audio='%(ctext)s' %(sourcefile)s %(datafile)s %(stdin)s
%(cargs)s %(largs)s %(rargs)s %(iargs)s %(gradebutton)s %(caption)s>
%(cargs)s %(largs)s %(rargs)s %(iargs)s %(gradebutton)s %(caption)s %(hidehistory)s>
%(initialcode)s
</textarea>
</div>
Expand Down Expand Up @@ -158,6 +161,11 @@ class ActiveCode(RunestoneIdDirective):
print("hello world")
====
print("Hidden code, such as unit tests come after the four = signs")

config values (conf.py):

- activecode_div_class - custom CSS class of the component's outermost div
- activecode_hide_load_history - if True, hide the load history button
"""
required_arguments = 1
optional_arguments = 1
Expand Down Expand Up @@ -320,6 +328,12 @@ def run(self):
else:
self.options['gradebutton'] = "data-gradebutton=true"

self.options['divclass'] = env.config.activecode_div_class
if env.config.activecode_hide_load_history:
self.options['hidehistory'] = 'data-hidehistory=true'
else:
self.options['hidehistory'] = ''

if self.content:
if '====' in self.content:
idx = self.content.index('====')
Expand Down
3 changes: 2 additions & 1 deletion runestone/activecode/js/activecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ActiveCode.prototype.init = function(opts) {
this.includes = $(orig).data('include');
this.hidecode = $(orig).data('hidecode');
this.chatcodes = $(orig).data('chatcodes');
this.hidehistory = $(orig).data('hidehistory');
this.runButton = null;
this.enabledownload = $(orig).data('enabledownload');
this.downloadButton = null;
Expand Down Expand Up @@ -178,7 +179,7 @@ ActiveCode.prototype.createControls = function () {
$(butt).attr("type","button")
}

if (! this.hidecode) {
if (!this.hidecode && !this.hidehistory) {
var butt = document.createElement("button");
$(butt).text($.i18n("msg_activecode_load_history"));
$(butt).addClass("btn btn-default");
Expand Down
3 changes: 3 additions & 0 deletions runestone/assess/assess.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def setup(app):
app.add_directive('qnum', QuestionNumber)
app.add_directive('timed', TimedDirective)

app.add_config_value('mchoice_div_class', 'runestone alert alert-warning', 'html')

#app.add_javascript('assess.js')
app.add_javascript('mchoice.js')
app.add_javascript('timedmc.js')
Expand All @@ -45,6 +47,7 @@ def setup(app):
app.add_node(FeedbackBulletList, html=(visit_feedback_bullet_node, depart_feedback_bullet_node))
app.add_node(FeedbackListItem, html=(visit_feedback_list_item, depart_feedback_list_item))




class AddButton(RunestoneIdDirective):
Expand Down
2 changes: 1 addition & 1 deletion runestone/assess/js/mchoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ MultipleChoice.prototype.createMCForm = function () {
MultipleChoice.prototype.renderMCContainer = function () {
this.containerDiv = document.createElement("div");
$(this.containerDiv).html(this.question);
$(this.containerDiv).addClass("alert alert-warning");
$(this.containerDiv).addClass(this.origElem.getAttribute("class"));
this.containerDiv.id = this.divid;
};

Expand Down
9 changes: 7 additions & 2 deletions runestone/assess/multiplechoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class MChoice(Assessment):
- ... and so on.

- Up to 26 answers and feedback pairs may be provided.

config values (conf.py):

- mchoice_div_class - custom CSS class of the component's outermost div
"""
required_arguments = 1
optional_arguments = 1
Expand Down Expand Up @@ -176,7 +180,7 @@ def run(self):
super(MChoice, self).run()

TEMPLATE_START = '''
<div class="runestone">
<div class="%(divclass)s">
<ul data-component="multiplechoice" data-multipleanswers="%(multipleAnswers)s" %(random)s id="%(divid)s">
'''

Expand All @@ -198,7 +202,8 @@ def run(self):
mcNode.template_end = TEMPLATE_END

self.state.nested_parse(self.content, self.content_offset, mcNode)

env = self.state.document.settings.env
self.options['divclass'] = env.config.mchoice_div_class
# Expected _`structure`, with assigned variable names and transformations made:
#
# .. code-block::
Expand Down
12 changes: 11 additions & 1 deletion runestone/clickableArea/clickable.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def setup(app):

app.add_node(ClickableAreaNode, html=(visit_ca_node, depart_ca_node))

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

TEMPLATE = """
<div data-component="clickablearea" class="runestone" id="%(divid)s" %(table)s %(correct)s %(incorrect)s>
<div data-component="clickablearea" class="%(divclass)s" id="%(divid)s" %(table)s %(correct)s %(incorrect)s>
<span data-question>%(question)s</span>%(feedback)s%(clickcode)s
"""
TEMPLATE_END = """
Expand Down Expand Up @@ -97,6 +98,11 @@ class ClickableArea(RunestoneIdDirective):
:incorrect: An array of the indices of the incorrect elements--same format as the correct elements.

--Content--


config values (conf.py):

- clickable_div_class - custom CSS class of the component's outermost div
"""
required_arguments = 1
optional_arguments = 0
Expand Down Expand Up @@ -151,4 +157,8 @@ def run(self):
if "iscode" not in self.options:
self.state.nested_parse(self.content, self.content_offset, clickNode)


env = self.state.document.settings.env
self.options['divclass'] = env.config.clickable_div_class

return [clickNode]
2 changes: 1 addition & 1 deletion runestone/clickableArea/js/clickable.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ClickableArea.prototype.renderNewElements = function () {
// wrapper function for generating everything
this.containerDiv = document.createElement("div");
this.containerDiv.appendChild(this.question);
$(this.containerDiv).addClass("alert alert-warning");
$(this.containerDiv).addClass(this.origElem.getAttribute("class"));

this.newDiv = document.createElement("div");
var newContent = $(this.origElem).html();
Expand Down
12 changes: 11 additions & 1 deletion runestone/codelens/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ def setup(app):
app.add_javascript('pytutor.js')
app.add_javascript('codelens.js')

app.add_config_value('codelens_div_class', "alert alert-warning cd_section", 'html')


VIS = '''
<div class="runestone" style="max-width: none;">
<div class="alert alert-warning cd_section">
<div class="%(divclass)s">
<div id="%(divid)s"></div>
<p class="cl_caption"><span class="cl_caption_text">%(caption)s (%(divid)s)</span> </p>
</div>'''
Expand Down Expand Up @@ -164,6 +166,11 @@ class Codelens(RunestoneIdDirective):
x = 0
for i in range(10):
x = x + i


config values (conf.py):

- codelens_div_class - custom CSS class of the component's outermost div
"""
required_arguments = 1
optional_arguments = 1
Expand Down Expand Up @@ -206,6 +213,9 @@ def js_var_finalizer(input_code, output_trace):

CUMULATIVE_MODE = False
self.JS_VARNAME = self.options['divid'] + '_trace'
env = self.state.document.settings.env
self.options['divclass'] = env.config.codelens_div_class

if 'showoutput' not in self.options:
self.options['embedded'] = 'true' # to set embeddedmode to true
else:
Expand Down
18 changes: 18 additions & 0 deletions runestone/common/project_template/conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,21 @@ html_show_sourcelink = False
# Output file base name for HTML help builder.
htmlhelp_basename = 'PythonCoursewareProjectdoc'

# Config values for specific Runestone components
#
#activecode_div_class = 'runestone explainer ac_section alert alert-warning'
#activecode_hide_load_history = False
#mchoice_div_class = 'runestone alert alert-warning'
#clickable_div_class = 'runestone alert alert-warning'
#codelens_div_class = 'alert alert-warning cd_section'
#dragndrop_div_class = 'runestone'
#fitb_div_class = 'runestone'
#parsons_div_class = 'runestone'
#poll_div_class = 'alert alert-warning'
#shortanswer_div_class = 'journal alert alert-warning'
#shortanswer_optional_div_class = 'journal alert alert-success'
#showeval_div_class = 'runestone explainer alert alert-warning'
#tabbed_div_class = alert alert-warning'



11 changes: 9 additions & 2 deletions runestone/dragndrop/dragndrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def setup(app):

app.add_node(DragNDropNode, html=(visit_dnd_node, depart_dnd_node))

app.add_config_value('dragndrop_div_class', 'runestone', 'html')


TEMPLATE_START = """
<div class="runestone">
<div class="%(divclass)s">
<ul data-component="dragndrop" id="%(divid)s">
<span data-component="question">%(question)s</span>
%(feedback)s
Expand Down Expand Up @@ -106,6 +108,10 @@ class DragNDrop(RunestoneIdDirective):
etc. (up to 20 matches)

The question goes here.

config values (conf.py):

- dragndrop_div_class - custom CSS class of the component's outermost div
"""
required_arguments = 1
optional_arguments = 0
Expand Down Expand Up @@ -158,7 +164,8 @@ def run(self):
source = '\n'

self.options['question'] = source

env = self.state.document.settings.env
self.options['divclass'] = env.config.dragndrop_div_class

dndNode = DragNDropNode(self.options, rawsource=self.block_text)
dndNode.source, dndNode.line = self.state_machine.get_source_and_line(self.lineno)
Expand Down
10 changes: 9 additions & 1 deletion runestone/fitb/fitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def setup(app):
app.add_node(FITBNode, html=(visit_fitb_node, depart_fitb_node))
app.add_node(BlankNode, html=(visit_blank_node, depart_blank_node))
app.add_node(FITBFeedbackNode, html=(visit_fitb_feedback_node, depart_fitb_feedback_node))
app.add_config_value('fitb_div_class', 'runestone', 'html')


class FITBNode(nodes.General, nodes.Element, RunestoneNode):
def __init__(self, content, **kwargs):
Expand Down Expand Up @@ -99,6 +101,10 @@ class FillInTheBlank(RunestoneIdDirective):
- :2: Right on! Numbers can be given in decimal, hex (0x10 == 16), octal (0o10 == 8), binary (0b10 == 2), or using scientific notation (1e1 == 10), both here and by the user when answering the question.
:2 1: Close.... (The second number is a tolerance, so this matches 1 or 3.)
:x: Nope. (As earlier, this matches anything.)

config values (conf.py):

- fitb_div_class - custom CSS class of the component's outermost div
"""
required_arguments = 1
optional_arguments = 0
Expand All @@ -121,7 +127,7 @@ def run(self):
super(FillInTheBlank, self).run()

TEMPLATE_START = '''
<div class="runestone">
<div class="%(divclass)s">
<div data-component="fillintheblank" id="%(divid)s">
'''

Expand All @@ -142,6 +148,8 @@ def run(self):
fitbNode.template_end = TEMPLATE_END

self.state.nested_parse(self.content, self.content_offset, fitbNode)
env = self.state.document.settings.env
self.options['divclass'] = env.config.fitb_div_class

# Expected _`structure`, with assigned variable names and transformations made:
#
Expand Down
8 changes: 6 additions & 2 deletions runestone/parsons/parsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def setup(app):
app.add_javascript('lib/hammer.min.js')
app.add_javascript('parsons.js')
app.add_javascript('timedparsons.js')

app.add_config_value('parsons_div_class', 'runestone', 'html')

TEMPLATE = '''
<div class="runestone" style="max-width: none;">
<div class="%(divclass)s" style="max-width: none;">
<pre data-component="parsons" id="%(divid)s" %(adaptive)s %(maxdist)s %(order)s %(noindent)s %(language)s %(numbered)s>
<span data-question>%(qnumber)s: %(instructions)s</span>%(code)s
</pre>
Expand Down Expand Up @@ -87,7 +87,9 @@ def findmax(alist):
return curmax


config values (conf.py):

- parsons_div_class - custom CSS class of the component's outermost div
"""
required_arguments = 1
optional_arguments = 1
Expand Down Expand Up @@ -139,9 +141,11 @@ def findmax(alist):
super(ParsonsProblem, self).run()
addQuestionToDB(self)

env = self.state.document.settings.env
self.options['qnumber'] = self.getNumber()
self.options['instructions'] = ""
self.options['code'] = self.content
self.options['divclass'] = env.config.parsons_div_class

if 'numbered' in self.options:
self.options['numbered'] = ' data-numbered="' + self.options['numbered'] + '"' #' data-numbered="true"'
Expand Down
2 changes: 1 addition & 1 deletion runestone/poll/js/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Poll.prototype.renderPoll = function() {
this.resultsDiv = document.createElement("div");

this.containerDiv.id = this.divid + "_container";
$(this.containerDiv).addClass("alert alert-warning");
$(this.containerDiv).addClass(this.origElem.getAttribute("class"));

$(this.pollForm).text(this.question);
$(this.pollForm).attr({
Expand Down
12 changes: 11 additions & 1 deletion runestone/poll/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def setup(app):
app.add_stylesheet('poll.css')
app.add_node(PollNode, html=(visit_poll_node, depart_poll_node))

app.add_config_value('poll_div_class', 'alert alert-warning', 'html')


TEMPLATE_START = """
<ul data-component="poll" id=%(divid)s %(comment)s>%(question)s
<ul data-component="poll" id=%(divid)s %(comment)s class='%(divclass)s'>%(question)s
"""

TEMPLATE_OPTION = """
Expand Down Expand Up @@ -88,6 +89,12 @@ class Poll(RunestoneIdDirective):
:option_1: Mode 2--Implements the "Choose one of these options" type method of poll.
:option_2: Option 2
:option_3: Option 3 ...etc...(Up to 10 options in mode 2)



config values (conf.py):

- poll_div_class - custom CSS class of the component's outermost div
"""
required_arguments = 1
optional_arguments = 0
Expand Down Expand Up @@ -136,6 +143,9 @@ def run(self):
else:
self.options["comment"] = ""

env = self.state.document.settings.env
self.options['divclass'] = env.config.poll_div_class

poll_node = PollNode(self.options, rawsource=self.block_text)
poll_node.source, poll_node.line = self.state_machine.get_source_and_line(self.lineno)
return [poll_node]
7 changes: 1 addition & 6 deletions runestone/shortanswer/js/shortanswer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ ShortAnswer.prototype.init = function (opts) {
ShortAnswer.prototype.renderHTML = function() {
this.containerDiv = document.createElement("div");
this.containerDiv.id = this.divid;
if (this.optional) {
$(this.containerDiv).addClass("journal alert alert-success");
} else {
$(this.containerDiv).addClass("journal alert alert-warning");
}

$(this.containerDiv).addClass(this.origElem.getAttribute("class"));
this.newForm = document.createElement("form");
this.newForm.id = this.divid + "_journal";
this.newForm.name = this.newForm.id;
Expand Down
Loading