Completed
Push — master ( 6833e1...858cb4 )
by P.R.
02:43
created

PartHtmlFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
dl 0
loc 31
ccs 3
cts 9
cp 0.3333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate_part_node() 0 14 2
A generate() 0 9 1
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9 1
import os
0 ignored issues
show
Unused Code introduced by
The import os seems to be unused.
Loading history...
10
11 1
from sdoc.helper.Html import Html
12 1
from sdoc.sdoc2 import node_store
13 1
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
14
15
16 1
class PartHtmlFormatter(HtmlFormatter):
17
    """
18
    HtmlFormatter for generating HTML code for parts.
19
    """
20
21
    # ------------------------------------------------------------------------------------------------------------------
22 1
    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
        self.generate_part_node(node, file)
30
        super().generate(node, file)
31
32
    # ------------------------------------------------------------------------------------------------------------------
33 1
    @staticmethod
34
    def generate_part_node(node, file):
35
        """
36
        Generates the HTML code for part node.
37
38
        :param sdoc.sdoc2.node.HeadingNode.HeadingNode node: The heading node.
39
        :param file file: The output file.
40
        """
41
        # Set id attribute to heading node.
42
        attributes = {'id': node.get_option_value('id'), 'class': 'part'}
43
44
        number = node.get_option_value('number')
45
        text_in_tag = '{0} {1!s}'.format('' if not number else number, node.argument)
46
        file.write(Html.generate_element('div', attributes, text_in_tag))
47
48
# ----------------------------------------------------------------------------------------------------------------------
49
node_store.register_formatter('part', 'html', PartHtmlFormatter)
50