blob: f27a84671d201bbc74bb95c0ca59aa0152404c3a [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 Gaynor681fca82013-12-31 14:13:39 -080026 import pdb
27 pdb.set_trace()
28
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070029 ad = make_admonition(
30 Hazmat,
31 self.name,
32 [],
33 self.options,
Alex Gaynor2724ff62013-12-20 13:51:42 -080034 nodes.paragraph("", message),
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070035 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
45class Hazmat(nodes.Admonition, nodes.Element):
46 pass
47
48
Alex Gaynor69f5ee42013-11-19 14:06:18 -080049def html_visit_hazmat_node(self, node):
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070050 return self.visit_admonition(node, "danger")
51
52
Alex Gaynor69f5ee42013-11-19 14:06:18 -080053def latex_visit_hazmat_node(self, node):
54 return self.visit_admonition(node)
55
56
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070057def depart_hazmat_node(self, node):
58 return self.depart_admonition(node)
59
60
61def setup(app):
62 app.add_node(
63 Hazmat,
Alex Gaynor69f5ee42013-11-19 14:06:18 -080064 html=(html_visit_hazmat_node, depart_hazmat_node),
65 latex=(latex_visit_hazmat_node, depart_hazmat_node),
Alex Gaynoraf82d5e2013-10-29 17:07:24 -070066 )
67 app.add_directive("hazmat", HazmatDirective)