Passed
Push — master ( 1ac98c...ed1e15 )
by P.R.
01:49
created

ReferenceHtmlFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
dl 0
loc 43
ccs 9
cts 9
cp 1
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_html() 0 14 1
A write_into_file() 0 9 1
A generate() 0 10 1
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.NodeStore import NodeStore
11 1
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
12
13
14 1
class ReferenceHtmlFormatter(HtmlFormatter):
15
    """
16
    HtmlFormatter for generating HTML code for references.
17
    """
18
19
    # ------------------------------------------------------------------------------------------------------------------
20 1
    def generate(self, node, file):
21
        """
22
        Generates the HTML code for a reference node.
23
24
        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
25
        :param file file: The output file.
26
        """
27 1
        self.write_into_file(node, file)
28
29 1
        HtmlFormatter.generate(self, node, file)
30
31
    # ------------------------------------------------------------------------------------------------------------------
32 1
    @staticmethod
33
    def write_into_file(node, file):
34
        """
35
        Writes data into opened file.
36
37
        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
38
        :param file file: The output file.
39
        """
40 1
        file.write(ReferenceHtmlFormatter.get_html(node))
41
42
    # ------------------------------------------------------------------------------------------------------------------
43 1
    @staticmethod
44
    def get_html(node):
45
        """
46
        Returns string with generated HTML tag.
47
48
        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
49
50
        :rtype: str
51
        """
52 1
        attributes = {'class': node.get_option_value('class'),
53
                      'href':  node.get_option_value('href'),
54
                      'title': node.get_option_value('title')}
55
56 1
        return Html.generate_element('a', attributes, str(node.text))
57
58
59
# ----------------------------------------------------------------------------------------------------------------------
60
NodeStore.register_formatter('ref', 'html', ReferenceHtmlFormatter)
61