Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 1 | from docutils import nodes |
| 2 | |
| 3 | from sphinx.util.compat import Directive, make_admonition |
| 4 | |
| 5 | |
| 6 | DANGER_MESSAGE = """ |
| 7 | This is a "Hazardous Materials" module. You should **ONLY** use it if you're |
| 8 | 100% absolutely sure that you know what you're doing because this module is |
Alex Gaynor | 2724ff6 | 2013-12-20 13:51:42 -0800 | [diff] [blame] | 9 | full of land mines, dragons, and dinosaurs with laser guns. |
| 10 | """ |
| 11 | |
| 12 | DANGER_ALTERNATE = """ |
| 13 | |
| 14 | You may instead be interested in :doc:`{alternate}`. |
| 15 | """ |
| 16 | |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 17 | |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 18 | class HazmatDirective(Directive): |
Alex Gaynor | 2724ff6 | 2013-12-20 13:51:42 -0800 | [diff] [blame] | 19 | has_content = True |
| 20 | |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 21 | def run(self): |
Alex Gaynor | 2724ff6 | 2013-12-20 13:51:42 -0800 | [diff] [blame] | 22 | message = DANGER_MESSAGE |
| 23 | if self.content: |
| 24 | message += DANGER_ALTERNATE.format(alternate=self.content[0]) |
| 25 | |
Alex Gaynor | 681fca8 | 2013-12-31 14:13:39 -0800 | [diff] [blame^] | 26 | import pdb |
| 27 | pdb.set_trace() |
| 28 | |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 29 | ad = make_admonition( |
| 30 | Hazmat, |
| 31 | self.name, |
| 32 | [], |
| 33 | self.options, |
Alex Gaynor | 2724ff6 | 2013-12-20 13:51:42 -0800 | [diff] [blame] | 34 | nodes.paragraph("", message), |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 35 | self.lineno, |
| 36 | self.content_offset, |
| 37 | self.block_text, |
| 38 | self.state, |
| 39 | self.state_machine |
| 40 | ) |
| 41 | ad[0].line = self.lineno |
| 42 | return ad |
| 43 | |
| 44 | |
| 45 | class Hazmat(nodes.Admonition, nodes.Element): |
| 46 | pass |
| 47 | |
| 48 | |
Alex Gaynor | 69f5ee4 | 2013-11-19 14:06:18 -0800 | [diff] [blame] | 49 | def html_visit_hazmat_node(self, node): |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 50 | return self.visit_admonition(node, "danger") |
| 51 | |
| 52 | |
Alex Gaynor | 69f5ee4 | 2013-11-19 14:06:18 -0800 | [diff] [blame] | 53 | def latex_visit_hazmat_node(self, node): |
| 54 | return self.visit_admonition(node) |
| 55 | |
| 56 | |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 57 | def depart_hazmat_node(self, node): |
| 58 | return self.depart_admonition(node) |
| 59 | |
| 60 | |
| 61 | def setup(app): |
| 62 | app.add_node( |
| 63 | Hazmat, |
Alex Gaynor | 69f5ee4 | 2013-11-19 14:06:18 -0800 | [diff] [blame] | 64 | html=(html_visit_hazmat_node, depart_hazmat_node), |
| 65 | latex=(latex_visit_hazmat_node, depart_hazmat_node), |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 66 | ) |
| 67 | app.add_directive("hazmat", HazmatDirective) |