Passed
Push — master ( 8ff2fc...2dab2b )
by P.R.
04:18 queued 10s
created

IconHtmlFormatter.generate()   A

Complexity

Conditions 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 1
CRAP Score 4.3145

Importance

Changes 0
Metric Value
eloc 6
dl 14
loc 14
ccs 1
cts 6
cp 0.1666
rs 10
c 0
b 0
f 0
cc 2
nop 3
crap 4.3145
1 1
from typing import Any
2
3 1
from sdoc.helper.Html import Html
4 1
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
5 1
from sdoc.sdoc2.node.IconNode import IconNode
6 1
from sdoc.sdoc2.NodeStore import NodeStore
7
8
9 1 View Code Duplication
class IconHtmlFormatter(HtmlFormatter):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10
    """
11
    HtmlFormatter for icons in HTML representation.
12
    """
13
14
    # ------------------------------------------------------------------------------------------------------------------
15 1
    def generate(self, node: IconNode, file: Any) -> None:
16
        """
17
        Generates the HTML code for an icon node.
18
19
        :param IconNode node: The icon node.
20
        :param any file: The output file.
21
        """
22
        attributes = IconNode.get_definition(node.argument)
23
24
        if attributes:
25
            img_element = Html.generate_void_element('img', attributes)
26
            file.write(img_element)
27
        else:
28
            NodeStore.error("There is no definition for icon with name '{}'".format(node.argument), node)
29
30
31
# ----------------------------------------------------------------------------------------------------------------------
32
NodeStore.register_formatter('icon', 'html', IconHtmlFormatter)
33