Completed
Push — master ( de796b...225b7c )
by P.R.
02:21
created

IconNode.is_phrasing()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 1
cts 2
cp 0.5
rs 9.4285
cc 1
crap 1.125
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9 1
from sdoc.sdoc2.NodeStore import NodeStore
10 1
from sdoc.sdoc2.node.Node import Node
11
12
13 1
class IconNode(Node):
14
    """
15
    Node for icons (i.e. small inline images).
16
    """
17
    # ------------------------------------------------------------------------------------------------------------------
18 1
    _definitions = {}
19
    """
20
    The icon definitions. Map from ion name ot attributes.
21
22
    :type: dict[str,dict[str,str]]
23
    """
24
25
    # ------------------------------------------------------------------------------------------------------------------
26 1
    def __init__(self, io, options, argument):
27
        """
28
        Object constructor.
29
30
        :param None|cleo.styles.output_style.OutputStyle io: The IO object.
31
        :param dict[str,str] options: The options of this figure.
32
        :param str argument: Not used.
33
        """
34
        super().__init__(io, 'icon', options, argument)
35
36
    # ------------------------------------------------------------------------------------------------------------------
37 1
    def get_command(self):
38
        """
39
        Returns the command of this node, i.e. icon.
40
41
        :rtype: str
42
        """
43
        return 'icon'
44
45
    # ------------------------------------------------------------------------------------------------------------------
46 1
    def is_block_command(self):
47
        """
48
        Returns False.
49
50
        :rtype: bool
51
        """
52
        return False
53
54
    # ------------------------------------------------------------------------------------------------------------------
55 1
    def is_inline_command(self):
56
        """
57
        Returns True.
58
59
        :rtype: bool
60
        """
61
        return True
62
63
    # ------------------------------------------------------------------------------------------------------------------
64 1
    def is_phrasing(self):
65
        """
66
        Returns True if this node is a phrasing node, i.e. is a part of a paragraph. Otherwise returns False.
67
68
        :rtype: bool
69
        """
70
        return True
71
72
    # ------------------------------------------------------------------------------------------------------------------
73 1
    @staticmethod
74
    def add_definition(name, attributes):
75
        """
76
        Adds the definition of an icon to the icon definitions.
77
78
        :param str name: The name of a reference to icon definition.
79
        :param dict[str,dict[str,str]] attributes: The attributes.
80
        """
81
        IconNode._definitions[name] = attributes
82
83
    # ------------------------------------------------------------------------------------------------------------------
84 1
    @staticmethod
85
    def get_definition(name):
86
        """
87
        Returns the attributes of a definition, if name of definition is exists.
88
89
        :param str name: The name of a definition
90
91
        :rtype: dict[str,str]|None
92
        """
93
        if name in IconNode._definitions:
94
            return IconNode._definitions[name]
95
        else:
96
            return None
97
98
99
# ----------------------------------------------------------------------------------------------------------------------
100
NodeStore.register_inline_command('icon', IconNode)
101