|
1
|
|
|
""" |
|
2
|
|
|
SDoc |
|
3
|
|
|
|
|
4
|
|
|
Copyright 2016 Set Based IT Consultancy |
|
5
|
|
|
|
|
6
|
|
|
Licence MIT |
|
7
|
|
|
""" |
|
8
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
9
|
|
|
import abc |
|
10
|
|
|
|
|
11
|
|
|
from sdoc.sdoc2 import node_store, in_scope, out_scope |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class Formatter: |
|
15
|
|
|
""" |
|
16
|
|
|
Abstract parent class for all formatters for generating the output of nodes in a requested format. |
|
17
|
|
|
""" |
|
18
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
19
|
|
|
@abc.abstractmethod |
|
20
|
|
|
def generate(self, node, file): |
|
21
|
|
|
""" |
|
22
|
|
|
Generates the representation of a node is the requested output format. |
|
23
|
|
|
|
|
24
|
|
|
:param sdoc.sdoc2.node.Node.Node node: The node for which the output must be generated. |
|
25
|
|
|
:param file file: The output file. |
|
26
|
|
|
""" |
|
27
|
|
|
for node_id in node.child_nodes: # @todo fix access |
|
28
|
|
|
child_node = in_scope(node_id) |
|
29
|
|
|
|
|
30
|
|
|
formatter = node_store.create_formatter(child_node.get_command(), self) |
|
31
|
|
|
formatter.generate(child_node, file) |
|
32
|
|
|
|
|
33
|
|
|
out_scope(child_node) |
|
34
|
|
|
|
|
35
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
36
|
|
|
@abc.abstractmethod |
|
37
|
|
|
def generate_chapter(self, node, file): |
|
38
|
|
|
""" |
|
39
|
|
|
Generates the representation of a node is the requested output format. |
|
40
|
|
|
|
|
41
|
|
|
:param sdoc.sdoc2.node.Node.Node node: The node for which the output must be generated. |
|
42
|
|
|
:param file file: The output file. |
|
43
|
|
|
""" |
|
44
|
|
|
for node_id in node.child_nodes: # @todo fix access |
|
45
|
|
|
child_node = in_scope(node_id) |
|
46
|
|
|
|
|
47
|
|
|
formatter = node_store.create_formatter(child_node.get_command(), self) |
|
48
|
|
|
formatter.generate_chapter(child_node, file) |
|
49
|
|
|
|
|
50
|
|
|
out_scope(child_node) |
|
51
|
|
|
|
|
52
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
53
|
|
|
|