Skip to content
Snippets Groups Projects
Commit 54489ae3 authored by Dhruva Gowda Storz's avatar Dhruva Gowda Storz
Browse files

Added Chemical Bistables section to tutorials. Rest incoming

parent 7c64228c
No related branches found
No related tags found
2 merge requests!233Documentation update 2,!225Documentation update #1
Showing
with 1522 additions and 1 deletion
"""Simple, inelegant Sphinx extension which adds a directive for a
highlighted code-block that may be toggled hidden and shown in HTML.
This is possibly useful for teaching courses.
The directive, like the standard code-block directive, takes
a language argument and an optional linenos parameter. The
hidden-code-block adds starthidden and label as optional
parameters.
Examples:
.. hidden-code-block:: python
:starthidden: False
a = 10
b = a + 5
.. hidden-code-block:: python
:label: --- SHOW/HIDE ---
x = 10
y = x + 5
Thanks to http://www.javascriptkit.com/javatutors/dom3.shtml for
inspiration on the javascript.
Thanks to Milad 'animal' Fatenejad for suggesting this extension
in the first place.
Written by Anthony 'el Scopz' Scopatz, January 2012.
Released under the WTFPL (http://sam.zoy.org/wtfpl/).
"""
from docutils import nodes
from docutils.parsers.rst import directives
from sphinx.directives.code import CodeBlock
from sphinx.util.compat import make_admonition
HCB_COUNTER = 0
js_showhide = """\
<script type="text/javascript">
function showhide(element){
if (!document.getElementById)
return
if (element.style.display == "block")
element.style.display = "none"
else
element.style.display = "block"
};
</script>
"""
def nice_bool(arg):
tvalues = ('true', 't', 'yes', 'y')
fvalues = ('false', 'f', 'no', 'n')
arg = directives.choice(arg, tvalues + fvalues)
return arg in tvalues
class hidden_code_block(nodes.General, nodes.FixedTextElement):
pass
class HiddenCodeBlock(CodeBlock):
"""Hidden code block is Hidden"""
option_spec = dict(starthidden=nice_bool,
label=str,
**CodeBlock.option_spec)
def run(self):
# Body of the method is more or less copied from CodeBlock
code = u'\n'.join(self.content)
hcb = hidden_code_block(code, code)
hcb['language'] = self.arguments[0]
hcb['linenos'] = 'linenos' in self.options
hcb['starthidden'] = self.options.get('starthidden', True)
hcb['label'] = self.options.get('label', '+ show/hide code')
hcb.line = self.lineno
return [hcb]
def visit_hcb_html(self, node):
"""Visit hidden code block"""
global HCB_COUNTER
HCB_COUNTER += 1
# We want to use the original highlighter so that we don't
# have to reimplement it. However it raises a SkipNode
# error at the end of the function call. Thus we intercept
# it and raise it again later.
try:
self.visit_literal_block(node)
except nodes.SkipNode:
pass
# The last element of the body should be the literal code
# block that was just made.
code_block = self.body[-1]
fill_header = {'divname': 'hiddencodeblock{0}'.format(HCB_COUNTER),
'startdisplay': 'none' if node['starthidden'] else 'block',
'label': node.get('label'),
}
divheader = ("""<a href="javascript:showhide(document.getElementById('{divname}'))">"""
"""{label}</a><br />"""
'''<div id="{divname}" style="display: {startdisplay}">'''
).format(**fill_header)
code_block = js_showhide + divheader + code_block + "</div>"
# reassign and exit
self.body[-1] = code_block
raise nodes.SkipNode
def depart_hcb_html(self, node):
"""Depart hidden code block"""
# Stub because of SkipNode in visit
def setup(app):
app.add_directive('hidden-code-block', HiddenCodeBlock)
app.add_node(hidden_code_block, html=(visit_hcb_html, depart_hcb_html))
File added
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
# All configuration values have a default; values that are commented out # All configuration values have a default; values that are commented out
# serve to show the default. # serve to show the default.
#Workaround to fix bug where extensions werent added
from docutils.parsers.rst.directives.admonitions import BaseAdmonition
from sphinx.util import compat
compat.make_admonition = BaseAdmonition
import subprocess import subprocess
import os import os
import sys import sys
...@@ -21,13 +26,13 @@ import mock ...@@ -21,13 +26,13 @@ import mock
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here. # documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../python')) sys.path.insert(0, os.path.abspath('../python'))
sys.path.insert(0, os.path.abspath('./Extensions'))
sys.path.append(os.path.abspath('../../moose-examples/snippets')) sys.path.append(os.path.abspath('../../moose-examples/snippets'))
sys.path.append(os.path.abspath('../../moose-examples/tutorials/ChemicalOscillators')) sys.path.append(os.path.abspath('../../moose-examples/tutorials/ChemicalOscillators'))
sys.path.append(os.path.abspath('../../moose-examples/tutorials/ChemicalBistables')) sys.path.append(os.path.abspath('../../moose-examples/tutorials/ChemicalBistables'))
sys.path.append(os.path.abspath('../../moose-examples/tutorials/ExcInhNet')) sys.path.append(os.path.abspath('../../moose-examples/tutorials/ExcInhNet'))
sys.path.append(os.path.abspath('../../moose-examples/neuroml/lobster_pyloric')) sys.path.append(os.path.abspath('../../moose-examples/neuroml/lobster_pyloric'))
sys.path.append(os.path.abspath('../../moose-examples/tutorials/ExcInhNetCaPlasticity')) sys.path.append(os.path.abspath('../../moose-examples/tutorials/ExcInhNetCaPlasticity'))
sys.path.append('../../docproj/ext/breathe/')
# -- General configuration ----------------------------------------------------- # -- General configuration -----------------------------------------------------
...@@ -42,6 +47,7 @@ extensions = ['sphinx.ext.autodoc', ...@@ -42,6 +47,7 @@ extensions = ['sphinx.ext.autodoc',
'sphinx.ext.autosummary', 'sphinx.ext.autosummary',
'sphinx.ext.todo', 'sphinx.ext.todo',
'sphinx.ext.viewcode', 'sphinx.ext.viewcode',
'hidden_code_block'
] ]
todo_include_todos = True todo_include_todos = True
......
docs/source/images/doseR.png

10.6 KiB

docs/source/images/findS.png

27.5 KiB

docs/source/images/mapkFB.png

152 KiB

docs/source/images/mapkFB2.png

92.3 KiB

docs/source/images/propBis.gif

838 KiB

docs/source/images/propBis.png

31.8 KiB

docs/source/images/sV1.png

9.49 KiB

docs/source/images/sV2.png

10.7 KiB

docs/source/images/sV3.png

13.4 KiB

docs/source/images/sV4.png

14.8 KiB

docs/source/images/sV5.png

13.2 KiB

docs/source/images/sV6.png

24.7 KiB

docs/source/images/sV7.png

19.1 KiB

docs/source/images/simpleB.png

9.52 KiB

docs/source/images/strongB.png

89.9 KiB

docs/source/images/strongBis.png

27.5 KiB

This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment