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

Commit 1cd56cc

Browse files
committed
move activecode and codelens fns to right place
1 parent e13e3fb commit 1cd56cc

File tree

5 files changed

+365
-381
lines changed

5 files changed

+365
-381
lines changed

runestone/activecode/activecode.py

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,37 @@
1919
from docutils import nodes
2020
from docutils.parsers.rst import directives
2121
from docutils.parsers.rst import Directive
22-
import json
23-
import os
2422

25-
# try:
26-
# import conf
27-
# version = conf.version
28-
# staticserver = conf.staticserver
29-
# except:
30-
# version = '2.1.0'
31-
# staticserver = 'runestonestatic.appspot.com'
3223

3324
def setup(app):
3425
app.add_directive('activecode', ActiveCode)
3526
app.add_directive('actex', ActiveExercise)
3627
app.add_stylesheet('codemirror.css')
3728
app.add_stylesheet('activecode.css')
3829

39-
app.add_javascript('jquery.highlight.js' )
40-
app.add_javascript('bookfuncs.js' )
41-
app.add_javascript('codemirror.js' )
30+
app.add_javascript('jquery.highlight.js')
31+
app.add_javascript('bookfuncs.js')
32+
app.add_javascript('codemirror.js')
4233
app.add_javascript('xml.js')
4334
app.add_javascript('css.js')
4435
app.add_javascript('htmlmixed.js')
4536
app.add_javascript('python.js')
46-
app.add_javascript('javascript.js' )
37+
app.add_javascript('javascript.js')
4738
app.add_javascript('activecode.js')
48-
app.add_javascript('skulpt.min.js' )
39+
app.add_javascript('skulpt.min.js')
4940
app.add_javascript('skulpt-stdlib.js')
5041

5142
app.add_node(ActivcodeNode, html=(visit_ac_node, depart_ac_node))
5243

53-
app.connect('doctree-resolved',process_activcode_nodes)
44+
app.connect('doctree-resolved', process_activcode_nodes)
5445
app.connect('env-purge-doc', purge_activecodes)
5546

5647

57-
5848
START = '''
5949
<div id="cont"></div>
6050
<div id="%(divid)s" lang="%(language)s" time="%(timelimit)s" class="ac_section alert alert-warning" >
6151
'''
6252

63-
6453
EDIT1 = '''
6554
</div>
6655
<br/>
@@ -76,7 +65,7 @@ def setup(app):
7665
<p class="ac_caption"><span class="ac_caption_text">%(caption)s (%(divid)s)</span> </p>
7766
'''
7867

79-
UNHIDE='''
68+
UNHIDE = '''
8069
<span class="ac_sep"></span>
8170
<button class='btn btn-default' id="%(divid)s_showb" onclick="$('#%(divid)s_code_div').toggle();cm_editors['%(divid)s_code'].refresh();$('#%(divid)s_saveb').toggle();$('#%(divid)s_loadb').toggle()">Show/Hide Code</button>
8271
'''
@@ -195,22 +184,24 @@ def setup(app):
195184
</script>
196185
'''
197186

187+
198188
class ActivcodeNode(nodes.General, nodes.Element):
199-
def __init__(self,content):
189+
def __init__(self, content):
200190
"""
201191
202192
Arguments:
203193
- `self`:
204194
- `content`:
205195
"""
206-
super(ActivcodeNode,self).__init__()
196+
super(ActivcodeNode, self).__init__()
207197
self.ac_components = content
208198

199+
209200
# self for these functions is an instance of the writer class. For example
210201
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
211202
# The node that is passed as a parameter is an instance of our node class.
212-
def visit_ac_node(self,node):
213-
#print self.settings.env.activecodecounter
203+
def visit_ac_node(self, node):
204+
# print self.settings.env.activecodecounter
214205
res = START
215206
if 'above' in node.ac_components:
216207
res += CANVAS
@@ -256,23 +247,24 @@ def visit_ac_node(self,node):
256247
res += SCRIPT
257248
res += END
258249
res = res % node.ac_components
259-
res = res.replace("u'","'") # hack: there must be a better way to include the list and avoid unicode strings
250+
res = res.replace("u'", "'") # hack: there must be a better way to include the list and avoid unicode strings
260251

261252
self.body.append(res)
262253

263-
def depart_ac_node(self,node):
254+
255+
def depart_ac_node(self, node):
264256
''' This is called at the start of processing an activecode node. If activecode had recursive nodes
265257
etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
266258
added here.
267259
'''
268260
pass
269261

270262

271-
def process_activcode_nodes(app,env,docname):
263+
def process_activcode_nodes(app, env, docname):
272264
pass
273265

274266

275-
def purge_activecodes(app,env,docname):
267+
def purge_activecodes(app, env, docname):
276268
pass
277269

278270

@@ -281,28 +273,28 @@ class ActiveCode(Directive):
281273
optional_arguments = 1
282274
has_content = True
283275
option_spec = {
284-
'nocanvas':directives.flag,
285-
'nopre':directives.flag,
286-
'above':directives.flag, # put the canvas above the code
287-
'autorun':directives.flag,
288-
'caption':directives.unchanged,
289-
'include':directives.unchanged,
290-
'hidecode':directives.flag,
291-
'language':directives.unchanged,
292-
'tour_1':directives.unchanged,
293-
'tour_2':directives.unchanged,
294-
'tour_3':directives.unchanged,
295-
'tour_4':directives.unchanged,
296-
'tour_5':directives.unchanged,
297-
'nocodelens':directives.flag,
298-
'coach':directives.flag,
299-
'timelimit':directives.unchanged
276+
'nocanvas': directives.flag,
277+
'nopre': directives.flag,
278+
'above': directives.flag, # put the canvas above the code
279+
'autorun': directives.flag,
280+
'caption': directives.unchanged,
281+
'include': directives.unchanged,
282+
'hidecode': directives.flag,
283+
'language': directives.unchanged,
284+
'tour_1': directives.unchanged,
285+
'tour_2': directives.unchanged,
286+
'tour_3': directives.unchanged,
287+
'tour_4': directives.unchanged,
288+
'tour_5': directives.unchanged,
289+
'nocodelens': directives.flag,
290+
'coach': directives.flag,
291+
'timelimit': directives.unchanged
300292
}
301293

302294
def run(self):
303295
env = self.state.document.settings.env
304296
# keep track of how many activecodes we have.... could be used to automatically make a unique id for them.
305-
if not hasattr(env,'activecodecounter'):
297+
if not hasattr(env, 'activecodecounter'):
306298
env.activecodecounter = 0
307299
env.activecodecounter += 1
308300

@@ -312,7 +304,7 @@ def run(self):
312304
if '====' in self.content:
313305
idx = self.content.index('====')
314306
source = "\n".join(self.content[:idx])
315-
suffix = "\n".join(self.content[idx+1:])
307+
suffix = "\n".join(self.content[idx + 1:])
316308
else:
317309
source = "\n".join(self.content)
318310
suffix = "\n"
@@ -322,23 +314,23 @@ def run(self):
322314

323315
self.options['initialcode'] = source
324316
self.options['suffix'] = suffix
325-
str=source.replace("\n","*nline*")
326-
str0=str.replace("\"","*doubleq*")
327-
str1=str0.replace("(","*open*")
328-
str2=str1.replace(")","*close*")
329-
str3=str2.replace("'","*singleq*")
330-
self.options['argu']=str3
331-
332-
complete=""
333-
no_of_buttons=0
317+
str = source.replace("\n", "*nline*")
318+
str0 = str.replace("\"", "*doubleq*")
319+
str1 = str0.replace("(", "*open*")
320+
str2 = str1.replace(")", "*close*")
321+
str3 = str2.replace("'", "*singleq*")
322+
self.options['argu'] = str3
323+
324+
complete = ""
325+
no_of_buttons = 0
334326
okeys = list(self.options.keys())
335327
for k in okeys:
336328
if '_' in k:
337-
x,label = k.split('_')
338-
no_of_buttons=no_of_buttons+1
339-
complete=complete+self.options[k]+"*atype*"
329+
x, label = k.split('_')
330+
no_of_buttons = no_of_buttons + 1
331+
complete = complete + self.options[k] + "*atype*"
340332

341-
newcomplete=complete.replace("\"","*doubleq*")
333+
newcomplete = complete.replace("\"", "*doubleq*")
342334
self.options['ctext'] = newcomplete
343335
self.options['no_of_buttons'] = no_of_buttons
344336

0 commit comments

Comments
 (0)