Permalink
Browse files

generalize the toggle directive and fix some docs

  • Loading branch information...
1 parent 5157f91 commit d13037aa14961efa192dc56ddd761ff4c5e2ca95 @vrabaud vrabaud committed Apr 19, 2012
Showing with 47 additions and 23 deletions.
  1. +5 −5 doc/source/dependencies.rst
  2. +4 −4 doc/source/overview/cells.rst
  3. +38 −14 python/ecto/sphinx/ToggleDirective.py
@@ -67,8 +67,8 @@ Additional Ubuntu Packages
On ubuntu platforms, for the build that includes ros, you want the
following packages::
-ros-electric-desktop-full
-ros-electric-perception-pcl-addons
-libopencv2.3-dev
-openni-dev (or ros-electric-openni-kinect)
-python-argparse
+ ros-electric-desktop-full
+ ros-electric-perception-pcl-addons
+ libopencv2.3-dev
+ openni-dev (or ros-electric-openni-kinect)
+ python-argparse
@@ -111,7 +111,7 @@ A peek under the covers
-- Egon
-You might be thinking these kinds of things... Well the registration with ecto occurs in the macro :cmacro:`ECTO_CELL`.
+You might be thinking these kinds of things... Well the registration with ecto occurs in the macro :c:macro:`ECTO_CELL`.
This macro
does some amount of extra fanciness, but in the end it takes your struct and does something similar
to the following simplified example:
@@ -153,7 +153,7 @@ to the following simplified example:
The real implementation uses `SFINAE`_ to enable
optional implementation of the interface functions.
-The macro :cmacro:`ECTO_CELL` also constructs python
+The macro :c:macro:`ECTO_CELL` also constructs python
bindings for your cell, and
generates RST formated doc strings from the
static declaration parameter and io functions.
@@ -174,8 +174,8 @@ script demonstrates the python interface of our cell that ecto provides for free
The script, when run will give the following output:
-.. program-output:: overview/cell01.py
- :in_srcdirs:
+.. program-output:: ./cell01.py
+ :in_srcdir:
Doc Generation
^^^^^^^^^^^^^^
@@ -1,48 +1,72 @@
-# Directive that shows a toggle link between two sections
+# Directive that shows a toggle link between sections.
+# Those sections cannot contain titles
# The first one is initially showed. Here is the syntax:
-# .. toggle1:: click here for ROS instructions
+# .. toggle_table::
+# :arg1: text in button 1
+# :arg2: text in button 2
+#
+# .. toggle:: text in button 1
#
# some RST text
#
-#.. toggle2:: click here for non-ROS instructions
+#.. toggle:: text in button 2
#
# some more RST text
import docutils
from docutils import nodes
from docutils.parsers.rst import directives, roles, states
def setup(app):
- app.add_directive('toggle1', ToggleDirective1)
- app.add_directive('toggle2', ToggleDirective2)
+ app.add_directive('toggle', ToggleDirective)
+ app.add_directive('toggle_table', ToggleTableDirective)
class ToggleDirective(docutils.parsers.rst.Directive):
"""
Base class that will be used by the two toggle directives
- """
+ """
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
option_spec = {}
has_content = True
node_class = nodes.container
- def run_help(self, id):
+ def run(self):
self.assert_has_content()
text = '\n'.join(self.content)
# Create the node, to be populated by `nested_parse`.
node = self.node_class(rawsource=text)
- node += nodes.raw(self.arguments[0], '<a class="toggleable_link_%s" href="javascript:toggle();">%s</a>' % (id, self.arguments[0]), format="html")
- node += nodes.raw(self.arguments[0], '<div class="toggleable_div_%s">' % id, format="html")
+ label = self.arguments[0]
+ label_strip = label.replace(' ', '')
+ node += nodes.raw(self.arguments[0], '<div class="toggleable_div label_%s">' % label_strip, format="html")
# Parse the directive contents.
self.state.nested_parse(self.content, self.content_offset, node)
node += nodes.raw(self.arguments[0], '</div>', format="html")
return [node]
-class ToggleDirective1(ToggleDirective):
- def run(self):
- return self.run_help(1)
+class ToggleTableDirective(docutils.parsers.rst.Directive):
+ """
+ Class used to create a set of buttons to toggle different sections
+ """
+ required_arguments = 0
+ optional_arguments = 10
+ final_argument_whitespace = True
+ option_spec = {}
+ for i in xrange(0, 100):
+ option_spec['arg' + str(i)] = str
+ has_content = True
+ node_class = nodes.container
-class ToggleDirective2(ToggleDirective):
def run(self):
- return self.run_help(2)
+ # Create the node, to be populated by `nested_parse`.
+ node = self.node_class()
+ for key in self.options.iterkeys():
+ if key not in self.option_spec:
+ raise RuntimeError(key + ' not in the contructor of ToggleTableDirective, use arg0 to arg99')
+ label = self.options[key]
+ label_strip = label.replace(' ', '')
+ node += nodes.raw(key, '<button class="toggleable_button label_%s" onClick="javascript:toggle(\'%s\');">%s</button>' %
+ (label_strip, label_strip, label), format="html")
+
+ return [node]

0 comments on commit d13037a

Please sign in to comment.