Completed
Pull Request — master (#48)
by Oleg
02:35
created

IconHtmlFormatter.generate()   A

Complexity

Conditions 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 4.3145

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 1
cts 6
cp 0.1666
rs 9.4285
cc 2
crap 4.3145
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.node.IconNode import IconNode
12 1
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
13
14
15 1
class IconHtmlFormatter(HtmlFormatter):
16
    """
17
    HtmlFormatter for icons in HTML representation.
18
    """
19
20
    # ------------------------------------------------------------------------------------------------------------------
21 1
    def generate(self, node, file):
22
        """
23
        Generates the HTML code for an icon node.
24
25
        :param sdoc.sdoc2.node.IconNode.IconNode node: The icon node.
26
        :param file file: The output file.
27
        """
28
        attributes = IconNode.get_definition(node.argument)
29
30
        if attributes:
31
            img_element = Html.generate_void_element('img', attributes)
32
            file.write(img_element)
33
34
        else:
35
            NodeStore.error("There is no definition for icon with name '{}'".format(node.argument))
36
37
# ----------------------------------------------------------------------------------------------------------------------
38
NodeStore.register_formatter('icon', 'html', IconHtmlFormatter)
39