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

IconHtmlFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
dl 0
loc 21
ccs 2
cts 7
cp 0.2857
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 15 2
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