Total Complexity | 2 |
Total Lines | 33 |
Duplicated Lines | 60.61 % |
Coverage | 61.53% |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | 1 | from typing import Any |
|
2 | |||
3 | 1 | from sdoc.helper.Html import Html |
|
4 | 1 | from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter |
|
5 | 1 | from sdoc.sdoc2.node.IconNode import IconNode |
|
6 | 1 | from sdoc.sdoc2.NodeStore import NodeStore |
|
7 | |||
8 | |||
9 | 1 | View Code Duplication | class IconHtmlFormatter(HtmlFormatter): |
|
|||
10 | """ |
||
11 | HtmlFormatter for icons in HTML representation. |
||
12 | """ |
||
13 | |||
14 | # ------------------------------------------------------------------------------------------------------------------ |
||
15 | 1 | def generate(self, node: IconNode, file: Any) -> None: |
|
16 | """ |
||
17 | Generates the HTML code for an icon node. |
||
18 | |||
19 | :param IconNode node: The icon node. |
||
20 | :param any file: The output file. |
||
21 | """ |
||
22 | attributes = IconNode.get_definition(node.argument) |
||
23 | |||
24 | if attributes: |
||
25 | img_element = Html.generate_void_element('img', attributes) |
||
26 | file.write(img_element) |
||
27 | else: |
||
28 | NodeStore.error("There is no definition for icon with name '{}'".format(node.argument), node) |
||
29 | |||
30 | |||
31 | # ---------------------------------------------------------------------------------------------------------------------- |
||
32 | NodeStore.register_formatter('icon', 'html', IconHtmlFormatter) |
||
33 |