Completed
Push — master ( 57e7bf...8a74a7 )
by P.R.
01:36
created

ReferenceHtmlFormatter.write_into_file()   A

Complexity

Conditions 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %
Metric Value
dl 11
loc 11
rs 9.4285
cc 1
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9
from sdoc.helper.Html import Html
10
from sdoc.sdoc2 import node_store
11
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
12
13
14 View Code Duplication
class ReferenceHtmlFormatter(HtmlFormatter):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
    """
16
    HtmlFormatter for generating HTML code for references.
17
    """
18
19
    # ------------------------------------------------------------------------------------------------------------------
20
    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
        self.write_into_file(node, file)
28
29
        super().generate(node, file)
30
31
    # ------------------------------------------------------------------------------------------------------------------
32
    def generate_chapter(self, node, file):
33
        """
34
        Generates the HTML code for a reference node.
35
36
        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
37
        :param file file: The output file.
38
        """
39
        if file:
40
            self.write_into_file(node, file)
41
42
        super().generate_chapter(node, file)
43
44
    # ------------------------------------------------------------------------------------------------------------------
45
    def write_into_file(self, node, file):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
46
        """
47
        Writes data into opened file.
48
49
        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
50
        :param file file: The output file.
51
        """
52
        attributes = {'class': node.get_option_value('class'),
53
                      'href': node.get_option_value('href')}
54
55
        file.write(Html.generate_element('a', attributes, node.argument))
56
57
58
# ----------------------------------------------------------------------------------------------------------------------
59
node_store.register_formatter('ref', 'html', ReferenceHtmlFormatter)
60