Completed
Pull Request — master (#22)
by Oleg
01:36
created

write_into_file()   A

Complexity

Conditions 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 11
rs 9.4285
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
class ReferenceHtmlFormatter(HtmlFormatter):
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))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _argument was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
56
57
58
# ----------------------------------------------------------------------------------------------------------------------
59
node_store.register_formatter('ref', 'html', ReferenceHtmlFormatter)
60