|
1
|
|
|
""" |
|
2
|
|
|
SDoc |
|
3
|
|
|
|
|
4
|
|
|
Copyright 2016 Set Based IT Consultancy |
|
5
|
|
|
|
|
6
|
|
|
Licence MIT |
|
7
|
|
|
""" |
|
8
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
9
|
1 |
|
from sdoc.helper.Html import Html |
|
10
|
1 |
|
from sdoc.sdoc2 import in_scope, out_scope |
|
11
|
|
|
from sdoc.sdoc2.NodeStore import NodeStore |
|
12
|
|
|
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter |
|
13
|
1 |
|
|
|
14
|
|
|
|
|
15
|
|
|
class DocumentHtmlFormatter(HtmlFormatter): |
|
16
|
|
|
""" |
|
17
|
|
|
HtmlFormatter for generating HTML code for document. |
|
18
|
|
|
""" |
|
19
|
1 |
|
|
|
20
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
21
|
|
|
def generate(self, node, file): |
|
22
|
|
|
""" |
|
23
|
|
|
Generates the HTML code for a document node. |
|
24
|
|
|
|
|
25
|
|
|
:param sdoc.sdoc2.node.DocumentNode.DocumentNode node: The document node. |
|
26
|
1 |
|
:param file file: The output file. |
|
27
|
|
|
""" |
|
28
|
|
|
self.generate_document_node(node, file) |
|
29
|
|
|
|
|
30
|
1 |
|
HtmlFormatter.generate(self, node, file) |
|
31
|
|
|
|
|
32
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
33
|
|
|
@staticmethod |
|
34
|
|
|
def generate_document_node(node, file): |
|
35
|
|
|
""" |
|
36
|
|
|
Generates the HTML code for heading node. |
|
37
|
|
|
|
|
38
|
|
|
:param sdoc.sdoc2.node.DocumentNode.DocumentNode node: The document node. |
|
39
|
|
|
:param file file: The output file. |
|
40
|
|
|
""" |
|
41
|
|
|
file.write('<div class="sdoc-document-title-outer">') |
|
42
|
|
|
if node.title_node_id: |
|
43
|
|
|
title_node = in_scope(node.title_node_id) |
|
44
|
|
|
file.write(Html.generate_element('h1', {}, title_node.argument)) |
|
45
|
|
|
out_scope(title_node) |
|
46
|
|
|
|
|
47
|
|
|
file.write('<div class="sdoc-document-title-inner">') |
|
48
|
|
|
|
|
49
|
|
|
if node.date_node_id: |
|
50
|
|
|
date_node = in_scope(node.date_node_id) |
|
51
|
|
|
if date_node.argument: |
|
52
|
|
|
file.write(Html.generate_element('span', {'class': 'sdoc-document-date'}, date_node.argument)) |
|
53
|
|
|
out_scope(date_node) |
|
54
|
|
|
|
|
55
|
|
|
if node.version_node_id: |
|
56
|
|
|
version_node = in_scope(node.version_node_id) |
|
57
|
|
|
if version_node.argument: |
|
58
|
|
|
file.write(Html.generate_element('span', {'class': 'sdoc-document-version'}, version_node.argument)) |
|
59
|
|
|
out_scope(version_node) |
|
60
|
|
|
|
|
61
|
|
|
file.write('</div>') |
|
62
|
|
|
file.write('</div>') |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
66
|
|
|
NodeStore.register_formatter('document', 'html', DocumentHtmlFormatter) |
|
67
|
|
|
|