blob: 0252d69316faef32048850a965498ae4321ee44a [file] [log] [blame]
Alex Gaynoraf82d5e2013-10-29 17:07:24 -07001from docutils import nodes
2
3from sphinx.util.compat import Directive, make_admonition
4
5
6DANGER_MESSAGE = """
7This is a "Hazardous Materials" module. You should **ONLY** use it if you're
8100% absolutely sure that you know what you're doing because this module is
Alex Gaynor2724ff62013-12-20 13:51:42 -08009full of land mines, dragons, and dinosaurs with laser guns.
10"""
11
12DANGER_ALTERNATE = """
13
14You may instead be interested in :doc:`{alternate}`.
15"""
16
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070017
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070018class HazmatDirective(Directive):
Alex Gaynor2724ff62013-12-20 13:51:42 -080019 has_content = True
20
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070021 def run(self):
Alex Gaynor2724ff62013-12-20 13:51:42 -080022 message = DANGER_MESSAGE
23 if self.content:
24 message += DANGER_ALTERNATE.format(alternate=self.content[0])
25
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070026 ad = make_admonition(
27 Hazmat,
28 self.name,
29 [],
30 self.options,
Alex Gaynor2724ff62013-12-20 13:51:42 -080031 nodes.paragraph("", message),
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070032 self.lineno,
33 self.content_offset,
34 self.block_text,
35 self.state,
36 self.state_machine
37 )
38 ad[0].line = self.lineno
39 return ad
40
41
42class Hazmat(nodes.Admonition, nodes.Element):
43 pass
44
45
Alex Gaynor69f5ee42013-11-19 14:06:18 -080046def html_visit_hazmat_node(self, node):
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070047 return self.visit_admonition(node, "danger")
48
49
Alex Gaynor69f5ee42013-11-19 14:06:18 -080050def latex_visit_hazmat_node(self, node):
51 return self.visit_admonition(node)
52
53
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070054def depart_hazmat_node(self, node):
55 return self.depart_admonition(node)
56
57
58def setup(app):
59 app.add_node(
60 Hazmat,
Alex Gaynor69f5ee42013-11-19 14:06:18 -080061 html=(html_visit_hazmat_node, depart_hazmat_node),
62 latex=(latex_visit_hazmat_node, depart_hazmat_node),
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070063 )
64 app.add_directive("hazmat", HazmatDirective)