1616# You should have received a copy of the GNU General Public License
1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818#
19- from __future__ import print_function
20-
2119__author__ = "bmiller"
2220
2321from docutils import nodes
3432 RunestoneIdNode ,
3533)
3634
37- try :
38- from html import escape # py3
39- except ImportError :
40- from cgi import escape # py2
41-
42-
4335def setup (app ):
4436 app .add_directive ("hparsons" , HParsonsDirective )
45- app .add_node (HParsonsNode , html = (visit_ac_node , depart_ac_node ))
37+ app .add_node (HParsonsNode , html = (visit_hp_node , depart_hp_node ))
4638
4739
4840TEMPLATE_START = """
4941<div>
50- <div data-component="hparsons" id=%(divid)s data-question_label="%(question_label)s">
51- <div id=%(divid)s_question class="ac_question col-md-12">
42+ <div data-component="hparsons" id=%(divid)s data-question_label="%(question_label)s" class="alert alert-warning hparsons_section" >
43+ <div class="hp_question col-md-12">
5244"""
5345
5446TEMPLATE_END = """
5547</div>
5648<div class='hparsons'></div>
57- <textarea data-lang="%(language)s" id="%(divid)s_editor"
49+ <textarea data-lang="%(language)s"
5850 %(optional)s
5951 %(dburl)s
52+ %(textentry)s
6053 style="visibility: hidden;">
61- %(initialcode )s
54+ %(initialsetting )s
6255</textarea>
6356</div>
6457</div>
@@ -74,10 +67,7 @@ def __init__(self, options, **kwargs):
7467# self for these functions is an instance of the writer class. For example
7568# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
7669# The node that is passed as a parameter is an instance of our node class.
77- def visit_ac_node (self , node ):
78- # print self.settings.env.activecodecounter
79-
80- # todo: handle above in node.runestone_options
70+ def visit_hp_node (self , node ):
8171
8272 node .delimiter = "_start__{}_" .format (node .runestone_options ["divid" ])
8373
@@ -87,11 +77,7 @@ def visit_ac_node(self, node):
8777 self .body .append (res )
8878
8979
90- def depart_ac_node (self , node ):
91- """This is called at the start of processing an activecode node. If activecode had recursive nodes
92- etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
93- added here.
94- """
80+ def depart_hp_node (self , node ):
9581 res = TEMPLATE_END % node .runestone_options
9682 self .body .append (res )
9783
@@ -104,37 +90,28 @@ def depart_ac_node(self, node):
10490 self .body .remove (node .delimiter )
10591
10692
107- def process_activcode_nodes (app , env , docname ):
108- pass
109-
110-
111- def purge_activecodes (app , env , docname ):
112- pass
113-
114-
11593class HParsonsDirective (RunestoneIdDirective ):
11694 # only keep: language, autograde, dburl
11795 """
118- .. activecode:: uniqueid
119- :autograde: unittest
120- :language: python, html, javascript, java, python2, python3
121- :dburl: url to load database for sql mode
122- :showlastsql: -- Only show the last sql result in output
123-
124- If this is a homework problem instead of an example in the text
125- then the assignment text should go here. The assignment text ends with
126- the line containing four tilde ~
127- ~~~~
128- print("Hidden code before students code - good for scaffolding")
129- ^^^^
130- print("hello world")
131- ====
132- print("Hidden code, such as unit tests come after the four = signs")
96+ .. hparsons:: uniqueid
97+ :language: sql, regex
98+ :dburl: only for sql -- url to load database
13399
134- config values (conf.py):
100+ :textentry: if you will use text entry instead of horizontal parsons
135101
136- - activecode_div_class - custom CSS class of the component's outermost div
137- - activecode_hide_load_history - if True, hide the load history button
102+ Here is the problem description. It must ends with the tildes.
103+ Make sure you use the correct delimitier for each section below.
104+ ~~~~
105+ --blocks--
106+ block 1
107+ block 2
108+ --explanations--
109+ explanations for block 1
110+ explanations for block 2
111+ --unittest--
112+ assert 1,1 == world
113+ assert 0,1 == hello
114+ assert 2,1 == 42
138115 """
139116
140117 required_arguments = 1
@@ -143,22 +120,21 @@ class HParsonsDirective(RunestoneIdDirective):
143120 option_spec = RunestoneIdDirective .option_spec .copy ()
144121 option_spec .update (
145122 {
146- "language" : directives .unchanged ,
147123 "dburl" : directives .unchanged ,
148- "showlastsql" : directives .flag ,
124+ "language" : directives .unchanged ,
125+ "textentry" : directives .flag ,
149126 }
150127 )
151128
152129 def run (self ):
153130 super (HParsonsDirective , self ).run ()
154131
155132 env = self .state .document .settings .env
156- # keep track of how many activecodes we have....
157- # could be used to automatically make a unique id for them.
158- if not hasattr (env , "activecodecounter" ):
159- env .activecodecounter = 0
160- env .activecodecounter += 1
161- self .options ["name" ] = self .arguments [0 ].strip ()
133+
134+ if "textentry" in self .options :
135+ self .options ['textentry' ] = ' data-textentry="true"'
136+ else :
137+ self .options ['textentry' ] = ''
162138
163139 explain_text = None
164140 if self .content :
@@ -173,14 +149,9 @@ def run(self):
173149 self .explain_text = explain_text or ["Not an Exercise" ]
174150 addQuestionToDB (self )
175151
176- self .options ["initialcode" ] = source
177- str = source .replace ("\n " , "*nline*" )
178- str0 = str .replace ('"' , "*doubleq*" )
179- str1 = str0 .replace ("(" , "*open*" )
180- str2 = str1 .replace (")" , "*close*" )
181- str3 = str2 .replace ("'" , "*singleq*" )
182- self .options ["argu" ] = str3
152+ self .options ["initialsetting" ] = source
183153
154+ # TODO: change this
184155 if "language" not in self .options :
185156 self .options ["language" ] = "python"
186157
@@ -234,6 +205,7 @@ def run(self):
234205
235206 maybeAddToAssignment (self )
236207 if explain_text :
208+ self .updateContent ()
237209 self .state .nested_parse (explain_text , self .content_offset , acnode )
238210
239211 return [acnode ]
0 commit comments