-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new question type for DoenetML #458
Draft
jaltekruse
wants to merge
8
commits into
RunestoneInteractive:main
Choose a base branch
from
jaltekruse:doenet-question-type-squashed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a63dc1
Add new question type for DoenetML
jaltekruse a88496a
Merge branch 'better-dev-env-dstart-with-nginx' into doenet-question-…
jaltekruse f8f26b6
Remove some copy/paste
jaltekruse e7e0b2b
I think this stuff is all safe to remove
jaltekruse 50e1ef5
Merge commit 'e3ea6f6caf024abbebbcac32ca3687a58332fa6b' into doenet-q…
jaltekruse 1d9780f
Merge commit '54a34f2c1fb1cbdabd9fa5d397a8bd27556171da' into doenet-q…
jaltekruse 4b318d0
maybe unused imports?
jaltekruse daf30f0
Merge branch 'main' into doenet-question-type-squashed
jaltekruse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .doenet import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
|
||
# ********* | ||
# |docname| | ||
# ********* | ||
# Copyright (C) 2011 Bradley N. Miller | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
__author__ = "jaltekruse" | ||
|
||
from docutils import nodes | ||
from docutils.parsers.rst import directives | ||
from sqlalchemy import Table | ||
from runestone.server.componentdb import ( | ||
addQuestionToDB, | ||
addHTMLToDB, | ||
maybeAddToAssignment, | ||
) | ||
from runestone.common.runestonedirective import ( | ||
RunestoneIdDirective, | ||
RunestoneIdNode, | ||
) | ||
|
||
|
||
def setup(app): | ||
app.add_directive("doenet", DoenetDirective) | ||
app.add_node(DoenetNode, html=(visit_hp_html, depart_hp_html)) | ||
|
||
|
||
TEMPLATE_START = """ | ||
<div class="runestone"> | ||
<div data-component="hparsons" id=%(divid)s data-question_label="%(question_label)s" class="alert alert-warning hparsons_section"> | ||
<div class="hp_question"> | ||
""" | ||
|
||
TEMPLATE_END = """ | ||
</div> | ||
<div class='hparsons'></div> | ||
<textarea | ||
%(language)s | ||
%(optional)s | ||
%(dburl)s | ||
%(reuse)s | ||
%(randomize)s | ||
%(blockanswer)s | ||
style="visibility: hidden;"> | ||
%(initialsetting)s | ||
</textarea> | ||
</div> | ||
</div> | ||
""" | ||
|
||
|
||
class DoenetNode(nodes.General, nodes.Element, RunestoneIdNode): | ||
pass | ||
|
||
|
||
# self for these functions is an instance of the writer class. For example | ||
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator | ||
# The node that is passed as a parameter is an instance of our node class. | ||
def visit_hp_html(self, node): | ||
|
||
node["delimiter"] = "_start__{}_".format(node["runestone_options"]["divid"]) | ||
|
||
self.body.append(node["delimiter"]) | ||
|
||
res = TEMPLATE_START % node["runestone_options"] | ||
self.body.append(res) | ||
|
||
|
||
def depart_hp_html(self, node): | ||
res = TEMPLATE_END % node["runestone_options"] | ||
self.body.append(res) | ||
|
||
addHTMLToDB( | ||
node["runestone_options"]["divid"], | ||
node["runestone_options"]["basecourse"], | ||
"".join(self.body[self.body.index(node["delimiter"]) + 1 :]), | ||
) | ||
|
||
self.body.remove(node["delimiter"]) | ||
|
||
|
||
class DoenetDirective(RunestoneIdDirective): | ||
""" | ||
<!-- .. doenet:: doenet-1 | ||
--> | ||
1+3000=<answer>4</answer> | ||
""" | ||
|
||
required_arguments = 1 | ||
optional_arguments = 1 | ||
has_content = True | ||
option_spec = RunestoneIdDirective.option_spec.copy() | ||
option_spec.update( | ||
{ | ||
"dburl": directives.unchanged, | ||
"language": directives.unchanged, | ||
"reuse": directives.flag, | ||
"randomize": directives.flag, | ||
"blockanswer": directives.unchanged, | ||
} | ||
) | ||
|
||
def run(self): | ||
super(DoenetDirective, self).run() | ||
addQuestionToDB(self) | ||
|
||
env = self.state.document.settings.env | ||
|
||
if "language" in self.options: | ||
self.options["language"] = "data-language='{}'".format( | ||
self.options["language"] | ||
) | ||
else: | ||
self.options["language"] = "" | ||
|
||
if "reuse" in self.options: | ||
self.options["reuse"] = ' data-reuse="true"' | ||
else: | ||
self.options["reuse"] = "" | ||
|
||
if "randomize" in self.options: | ||
self.options["randomize"] = ' data-randomize="true"' | ||
else: | ||
self.options["randomize"] = "" | ||
|
||
if "blockanswer" in self.options: | ||
self.options["blockanswer"] = "data-blockanswer='{}'".format( | ||
self.options["blockanswer"] | ||
) | ||
else: | ||
self.options["blockanswer"] = "" | ||
|
||
explain_text = None | ||
if self.content: | ||
if "~~~~" in self.content: | ||
idx = self.content.index("~~~~") | ||
explain_text = self.content[:idx] | ||
self.content = self.content[idx + 1 :] | ||
source = "\n".join(self.content) | ||
else: | ||
source = "\n" | ||
|
||
self.explain_text = explain_text or ["Not an Exercise"] | ||
|
||
self.options["initialsetting"] = source | ||
|
||
# SQL Options | ||
if "dburl" in self.options: | ||
self.options["dburl"] = "data-dburl='{}'".format(self.options["dburl"]) | ||
else: | ||
self.options["dburl"] = "" | ||
|
||
course_name = env.config.html_context["course_id"] | ||
divid = self.options["divid"] | ||
|
||
hpnode = DoenetNode() | ||
hpnode["runestone_options"] = self.options | ||
hpnode["source"], hpnode["line"] = self.state_machine.get_source_and_line( | ||
self.lineno | ||
) | ||
self.add_name(hpnode) # make this divid available as a target for :ref: | ||
|
||
maybeAddToAssignment(self) | ||
if explain_text: | ||
self.updateContent() | ||
self.state.nested_parse(explain_text, self.content_offset, hpnode) | ||
|
||
return [hpnode] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, should probably rename all "hp" and "hparsons" references.