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

write_into_file()   A

Complexity

Conditions 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 10
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 UnknownHtmlFormatter(HtmlFormatter):
15
    """
16
    HtmlFormatter for generating HTML code for paragraph.
17
    """
18
19
    # ------------------------------------------------------------------------------------------------------------------
20
    def generate(self, node, file):
21
        """
22
        Generates the HTML code for a paragraph node.
23
24
        :param sdoc.sdoc2.node.ParagraphNode.ParagraphNode node: The paragraph node.
25
        :param file file: The output file.
26
        """
27
        self.write_into_file(node, file)
28
29
    # ------------------------------------------------------------------------------------------------------------------
30
    def generate_chapter(self, node, file):
31
        """
32
        Generates the HTML code for a paragraph node.
33
34
        :param sdoc.sdoc2.node.ParagraphNode.ParagraphNode node: The paragraph node.
35
        :param file file: The output file.
36
        """
37
        if file:
38
            self.write_into_file(node, file)
39
40
    # ------------------------------------------------------------------------------------------------------------------
41
    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...
42
        """
43
        Writes into opened file.
44
45
        :param sdoc.sdoc2.node.ParagraphNode.ParagraphNode node: The paragraph node.
46
        :param file file: The output file.
47
        """
48
        html = 'Unknown SDoc2 command <span style="font-weight:bold">{0!s}</span> at {1!s}'.format(
49
            Html.escape(node.name), Html.escape(str(node.position)))
50
        file.write(Html.generate_element('span', {'style': 'color:red'}, html, True))
51
52
53
# ----------------------------------------------------------------------------------------------------------------------
54
node_store.register_formatter('unknown', 'html', UnknownHtmlFormatter)
55