]> AND Public Git Repository - simgrid.git/blobdiff - docs/source/_ext/showfile.py
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics: fix "Malformed whitespace in C++" spotted by codefactor.io.
[simgrid.git] / docs / source / _ext / showfile.py
index 39790a0cdd936fdf9c51d73f62947b0985ea0f2b..98579ffab6478d886152ddb668168c6ddd6b7dad 100644 (file)
@@ -10,6 +10,9 @@ from docutils.statemachine import StringList
 from sphinx.util.osutil import copyfile
 from sphinx.util import logging
 
+CSS_FILE = 'showfile.css'
+JS_FILE = 'showfile.js'
+
 class ShowFileDirective(Directive):
     """
     Show a file or propose it to download.
@@ -18,7 +21,7 @@ class ShowFileDirective(Directive):
     has_content = False
     optional_arguments = 1
     option_spec = {
-      'language': directives.unchanged
+        'language': directives.unchanged
     }
 
     def run(self):
@@ -105,7 +108,56 @@ class ExampleTabDirective(Directive):
         self.state.nested_parse(self.content, self.content_offset, node)
         return node.children
 
+class ToggleDirective(Directive):
+    has_content = True
+    option_spec = {
+        'header': directives.unchanged,
+        'show': directives.flag
+    }
+    optional_arguments = 1
+
+    def run(self):
+        node = nodes.container()
+        node['classes'].append('toggle-content')
+        if "show" not in self.options:
+            # This :show: thing is not working, and I fail to see why.
+            # Only the hidden-content class gets a call to hide() in the Javascript,
+            # and :show:n block# still get hidden when I load the page.
+            # No idea what's going on (Mt)
+            node['classes'].append('hidden-content')
+
+        par = nodes.container()
+        par['classes'].append('toggle-header')
+        if self.arguments and self.arguments[0]:
+            par['classes'].append(self.arguments[0])
+
+        self.state.nested_parse(StringList([self.options["header"]]), self.content_offset, par)
+        self.state.nested_parse(self.content, self.content_offset, node)
+
+        return [par, node]
+
+def add_assets(app):
+    app.add_stylesheet(CSS_FILE)
+    app.add_javascript(JS_FILE)
+
+
+def copy_assets(app, exception):
+    if app.builder.name not in ['html', 'readthedocs'] or exception:
+        return
+    logger = logging.getLogger(__name__)
+    logger.info('Copying showfile stylesheet/javascript... ', nonl=True)
+    dest = os.path.join(app.builder.outdir, '_static', CSS_FILE)
+    source = os.path.join(os.path.abspath(os.path.dirname(__file__)), CSS_FILE)
+    copyfile(source, dest)
+    dest = os.path.join(app.builder.outdir, '_static', JS_FILE)
+    source = os.path.join(os.path.abspath(os.path.dirname(__file__)), JS_FILE)
+    copyfile(source, dest)
+    logger.info('done')
+
 def setup(app):
+    app.add_directive('toggle-header', ToggleDirective)
     app.add_directive('showfile', ShowFileDirective)
     app.add_directive('example-tab', ExampleTabDirective)
 
+    app.connect('builder-inited', add_assets)
+    app.connect('build-finished', copy_assets)