Completed
Pull Request — master (#17)
by
unknown
01:20
created

generate()   A

Complexity

Conditions 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 12
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
        attributes = {'href': node.get_option_value('href')}
28
29
        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...
30
31
        super().generate(node, file)
32
33
# ----------------------------------------------------------------------------------------------------------------------
34
node_store.register_formatter('ref', 'html', ReferenceHtmlFormatter)
35