Completed
Push — master ( 9e402b...ef0f01 )
by P.R.
02:03
created

DocumentHtmlFormatter.generate_document_node()   B

Complexity

Conditions 6

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
rs 7.5384
ccs 0
cts 0
cp 0
cc 6
crap 42
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