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

write_into_file()   A

Complexity

Conditions 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 20
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 FigureHtmlFormatter(HtmlFormatter):
15
    """
16
    HtmlFormatter for generating HTML code for figures.
17
    """
18
    # ------------------------------------------------------------------------------------------------------------------
19
    def generate(self, node, file):
20
        """
21
        Generates the HTML code for a figure node.
22
23
        :param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node.
24
        :param file file: The output file.
25
        """
26
        self.write_into_file(node, file)
27
28
        super().generate(node, file)
29
30
    # ------------------------------------------------------------------------------------------------------------------
31
    def generate_chapter(self, node, file):
32
        """
33
        Generates the HTML code for a figure node.
34
35
        :param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node.
36
        :param file file: The output file.
37
        """
38
        if file:
39
            self.write_into_file(node, file)
40
41
        super().generate_chapter(node, file)
42
43
    # ------------------------------------------------------------------------------------------------------------------
44
    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...
45
        """
46
        Writes data into opened HTML file.
47
48
        :param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node.
49
        :param file file: The output file.
50
        """
51
        # Creating dicts with attributes for each type of element.
52
        img_attributes = {'src': node.get_option_value('filename'),
53
                          'width': node.get_option_value('width'),
54
                          'height': node.get_option_value('height'),
55
                          'alt': node.get_option_value('caption')}
56
        div_attributes = {'class': node.get_option_value('class')}
57
58
        # Creating elements.
59
        img_element = Html.generate_void_element('img', img_attributes)
60
        div_img_element = Html.generate_element('div', div_attributes, img_element, True)
61
62
        # Write elements into html file.
63
        file.write(div_img_element)
64
65
66
# ----------------------------------------------------------------------------------------------------------------------
67
node_store.register_formatter('figure', 'html', FigureHtmlFormatter)
68