|
1
|
|
|
""" |
|
2
|
|
|
SDoc |
|
3
|
|
|
|
|
4
|
|
|
Copyright 2016 Set Based IT Consultancy |
|
5
|
|
|
|
|
6
|
|
|
Licence MIT |
|
7
|
|
|
""" |
|
8
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
9
|
|
|
import os |
|
10
|
|
|
|
|
11
|
|
|
from sdoc.helper.Html import Html |
|
12
|
|
|
from sdoc.sdoc2 import node_store |
|
13
|
|
|
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class PartHtmlFormatter(HtmlFormatter): |
|
17
|
|
|
""" |
|
18
|
|
|
HtmlFormatter for generating HTML code for parts. |
|
19
|
|
|
""" |
|
20
|
|
|
|
|
21
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
22
|
|
|
def generate(self, node, file): |
|
23
|
|
|
""" |
|
24
|
|
|
Generates the HTML code for a part node. |
|
25
|
|
|
|
|
26
|
|
|
:param sdoc.sdoc2.node.HeadingNode.HeadingNode node: The heading node. |
|
27
|
|
|
:param file file: The output file. |
|
28
|
|
|
""" |
|
29
|
|
|
if os.path.exists('output.html'): |
|
30
|
|
|
os.remove('output.html') |
|
31
|
|
|
|
|
32
|
|
|
with open('output_{0}.html'.format(node.argument), 'w') as file: |
|
33
|
|
|
file.write('<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="NL" lang="NL">') |
|
34
|
|
|
file.write('<head><meta charset="UTF-8"/><title>sdoc</title></head>') |
|
35
|
|
|
file.write('<body>') |
|
36
|
|
|
|
|
37
|
|
|
self.generate_part_node(node, file) |
|
38
|
|
|
super().generate(node, file) |
|
39
|
|
|
|
|
40
|
|
|
file.write('</body>') |
|
41
|
|
|
file.write('</html>') |
|
42
|
|
|
|
|
43
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
44
|
|
|
@staticmethod |
|
45
|
|
|
def generate_part_node(node, file): |
|
46
|
|
|
""" |
|
47
|
|
|
Generates the HTML code for part node. |
|
48
|
|
|
|
|
49
|
|
|
:param sdoc.sdoc2.node.HeadingNode.HeadingNode node: The heading node. |
|
50
|
|
|
:param file file: The output file. |
|
51
|
|
|
""" |
|
52
|
|
|
# Set id attribute to heading node. |
|
53
|
|
|
attributes = {'id': node.get_option_value('id'), 'class': 'part'} |
|
54
|
|
|
|
|
55
|
|
|
number = node.get_option_value('number') |
|
56
|
|
|
text_in_tag = '{0} {1!s}'.format('' if not number else number, node.argument) |
|
57
|
|
|
file.write(Html.generate_element('div', attributes, text_in_tag)) |
|
58
|
|
|
|
|
59
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
60
|
|
|
node_store.register_formatter('part', 'html', PartHtmlFormatter) |
|
61
|
|
|
|