summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2018-01-03 16:18:58 +0100
committerDave Andreoli <dave@gurumeditation.it>2018-01-03 16:54:51 +0100
commit2f69ba27d3438f811f0e5d79562c5f96a2a3f69d (patch)
tree1e9cd5b8d54b7334fe73bddbb9cdf86b3710e2ae
parentd280ab7410498159c262c3a2c308b2e14e9d07fd (diff)
Put in a new (experimental) doc generator built only by templates
This is (in my mind) meant to replace the current elua generator. Currently the generated output is pratically identical to the elua one, just some little difference here and there, some for thecnical reasons and some just for my preference. I consider this work just a starting point, extending the templates we can now easily improve our docs. Whithout the need to touch a single line of code. Really I think this is a great improvements, and this are some numbers to prove it: Current elua implementation: 4185 lines of code in 7 lua files generation time: ~ 7 seconds New generator: 115 lines of python + 513 lines of templates generation time: ~ 8 seconds (can be optimizd ALOT) To generate the full Efl.* docs just run "./gendoc.py -v" in this folder. ...will wait for reviews (in particular from @andy and @q66)
-rw-r--r--src/scripts/gendoc/doc_alias.template24
-rw-r--r--src/scripts/gendoc/doc_class.template106
-rw-r--r--src/scripts/gendoc/doc_enum.template39
-rw-r--r--src/scripts/gendoc/doc_macros.include253
-rw-r--r--src/scripts/gendoc/doc_start.template52
-rw-r--r--src/scripts/gendoc/doc_struct.template39
-rwxr-xr-xsrc/scripts/gendoc/gendoc.py115
7 files changed, 628 insertions, 0 deletions
diff --git a/src/scripts/gendoc/doc_alias.template b/src/scripts/gendoc/doc_alias.template
new file mode 100644
index 0000000000..c0d5fa7a3d
--- /dev/null
+++ b/src/scripts/gendoc/doc_alias.template
@@ -0,0 +1,24 @@
1<!--(include)-->doc_macros.include<!--(end)-->#!
2~~Title: ${alias.full_name}$~~
3====== ${alias.full_name}$ (alias) ======
4
5${BEST_SUMMARY(obj=alias)}$
6
7${BEST_DESCRIPTION(obj=alias)}$
8
9${BEST_SINCE(obj=alias)}$
10
11${OBJECT_STATIC_CONTENT(obj=alias, section='description')}$
12
13===== Signature =====
14
15<code>
16TODO
17</code>
18
19===== C signature =====
20
21<code>
22TODO
23</code>
24
diff --git a/src/scripts/gendoc/doc_class.template b/src/scripts/gendoc/doc_class.template
new file mode 100644
index 0000000000..60f6779af1
--- /dev/null
+++ b/src/scripts/gendoc/doc_class.template
@@ -0,0 +1,106 @@
1<!--(include)-->doc_macros.include<!--(end)-->#!
2~~Title: ${cls.full_name}$~~
3====== ${cls.full_name}$ (${CLS_TYPE}$) ======
4
5${BEST_SUMMARY(obj=cls)}$
6
7${BEST_DESCRIPTION(obj=cls)}$
8
9${BEST_SINCE(obj=cls)}$
10
11${OBJECT_STATIC_CONTENT(obj=cls, section='description')}$
12
13<!--(if len(list(cls.inherits)) > 0)-->
14===== Inheritance =====
15
16 <!--(for inherit in cls.hierarchy)-->
17 => ${CLS_LINK(cls=inherit)}$#!
18 <!--(end)-->
19
20++++ Full hierarchy |
21
22 <!--(for inherit in cls.inherits)-->
23 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
24 <!--(for inherit in inherit.inherits)-->
25 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
26 <!--(for inherit in inherit.inherits)-->
27 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
28 <!--(for inherit in inherit.inherits)-->
29 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
30 <!--(for inherit in inherit.inherits)-->
31 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
32 <!--(for inherit in inherit.inherits)-->
33 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
34 <!--(for inherit in inherit.inherits)-->
35 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
36 <!--(for inherit in inherit.inherits)-->
37 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
38 <!--(for inherit in inherit.inherits)-->
39 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
40 <!--(for inherit in inherit.inherits)-->
41 * ${CLS_LINK(cls=inherit)}$ //(${CLS_TYPE(cls=inherit)}$)//
42 <!--(end)-->
43 <!--(end)-->
44 <!--(end)-->
45 <!--(end)-->
46 <!--(end)-->
47 <!--(end)-->
48 <!--(end)-->
49 <!--(end)-->
50 <!--(end)-->
51 <!--(end)-->
52
53++++
54<!--(end)-->
55
56===== Properties =====
57
58<!--(for impl in cls.implements)-->
59 <!--(if impl.is_property)-->
60${IMPLEMENT_FULL(impl=impl, cls=cls)}$
61\\
62 <!--(end)-->
63<!--(else)-->
64No properties defined in this class.
65<!--(end)-->
66
67===== Methods =====
68
69<!--(for impl in cls.implements)-->
70 <!--(if impl.is_method)-->
71${IMPLEMENT_FULL(impl=impl, cls=cls)}$
72\\
73 <!--(end)-->
74<!--(else)-->
75No Methods defined in this class.
76<!--(end)-->
77
78===== Inherited members =====
79
80<!--(for cls2 in cls.inherits_full)-->
81^ ${CLS_LINK(cls=cls2)}$ //(${CLS_TYPE(cls=cls2)}$)//^^^
82 <!--(for impl in cls2.implements)-->
83| ${FUNC_SCOPE(func=impl.function)}$ #!
84| **${FUNC_LINK(func=impl.function)}$** #!
85| ${BEST_SUMMARY(obj=impl)}$ |
86 <!--(end)-->
87<!--(else)-->
88No inherits defined in this class.
89<!--(end)-->
90
91===== Events =====
92
93<!--(for i, ev in enumerate(cls.events))-->
94 <!--(if i == 0)-->
95^ Local implemented ^^ event info ^
96 <!--(end)-->
97| ''${ev.name}$'' | ${BEST_SUMMARY(obj=ev)}$ ${OBJECT_SCOPE(obj=ev)}$ ${EVENT_TAGS}$| ${TYPE_LINK(type=ev.type) if ev.type else 'None'}$ |
98<!--(end)-->
99<!--(for cls2 in cls.inherits_full)-->
100 <!--(for i, ev in enumerate(cls2.events))-->
101 <!--(if i == 0)-->
102^ Inherited from ${CLS_LINK(cls=cls2)}$ //(${CLS_TYPE(cls=cls2)}$)// ^^ event info ^
103 <!--(end)-->
104| ''${ev.name}$'' | ${BEST_SUMMARY(obj=ev)}$ ${OBJECT_SCOPE(obj=ev)}$ ${EVENT_TAGS}$ | ${TYPE_LINK(type=ev.type) if ev.type else 'None'}$ |
105 <!--(end)-->
106<!--(end)-->
diff --git a/src/scripts/gendoc/doc_enum.template b/src/scripts/gendoc/doc_enum.template
new file mode 100644
index 0000000000..03f6cd62cd
--- /dev/null
+++ b/src/scripts/gendoc/doc_enum.template
@@ -0,0 +1,39 @@
1<!--(include)-->doc_macros.include<!--(end)-->#!
2~~Title: ${enum.full_name}$~~
3====== ${enum.full_name}$ (enum) ======
4
5${BEST_SUMMARY(obj=enum)}$
6
7${BEST_DESCRIPTION(obj=enum)}$
8
9${BEST_SINCE(obj=enum)}$
10
11${OBJECT_STATIC_CONTENT(obj=enum, section='description')}$
12
13===== Fields =====
14
15${OBJECT_STATIC_CONTENT(obj=enum, section='fields')}$
16
17<!--(for field in enum.enum_fields)-->
18 * **${field.name}$** - ${BEST_SUMMARY(obj=field)}$
19<!--(end)-->
20
21===== Signature =====
22
23<code>
24enum {
25<!--(for field in enum.enum_fields)-->
26 ${field.name}$: ${field.value.serialize}$,
27<!--(end)-->
28}
29</code>
30
31===== C Signature =====
32
33<code>
34typedef enum {
35<!--(for field in enum.enum_fields)-->
36 ${field.c_name}$ = ${field.value.serialize}$,
37<!--(end)-->
38} ${enum.full_name.replace('.', '_')}$;
39</code>
diff --git a/src/scripts/gendoc/doc_macros.include b/src/scripts/gendoc/doc_macros.include
new file mode 100644
index 0000000000..ac01b99722
--- /dev/null
+++ b/src/scripts/gendoc/doc_macros.include
@@ -0,0 +1,253 @@
1#!##############################################################################
2#!#### BEST_SUMMARY(obj) #####################################################
3#!##############################################################################
4<!--(macro BEST_SUMMARY)-->
5 <!--(if isinstance(obj, Implement))-->
6 <!--(if obj.documentation_get(obj.function.type))-->
7${UNTOKENIZE(tokens=obj.documentation_get(obj.function.type).summary_tokens)}$#!
8 <!--(else)-->
9 <!--(for parent_impl in obj.class_.implements)-->
10 <!--(if parent_impl.function.name == obj.function.name)-->
11 <!--(if parent_impl.documentation_get(parent_impl.function.type))-->
12${UNTOKENIZE(tokens=parent_impl.documentation_get(parent_impl.function.type).summary_tokens)}$#!
13 <!--(end)-->
14 <!--(end)-->
15 <!--(end)-->
16 <!--(end)-->
17 <!--(elif obj.documentation)-->
18${UNTOKENIZE(tokens=obj.documentation.summary_tokens)}$#!
19 <!--(else)-->
20**MISSING DOCS !!!!!**#!
21 <!--(end)-->
22<!--(end)-->
23#!##############################################################################
24#!#### BEST_DESCRIPTION(obj) #################################################
25#!##############################################################################
26<!--(macro BEST_DESCRIPTION)-->
27 <!--(if isinstance(obj, Implement))-->
28 <!--(if obj.documentation_get(obj.function.type))-->
29${UNTOKENIZE(tokens=obj.documentation_get(obj.function.type).description_tokens)}$#!
30 <!--(else)-->
31 <!--(for parent_impl in obj.class_.implements)-->
32 <!--(if parent_impl.function.name == obj.function.name)-->
33 <!--(if parent_impl.documentation_get(parent_impl.function.type))-->
34${UNTOKENIZE(tokens=parent_impl.documentation_get(parent_impl.function.type).description_tokens)}$#!
35 <!--(end)-->
36 <!--(end)-->
37 <!--(end)-->
38 <!--(end)-->
39 <!--(elif obj.documentation)-->
40${UNTOKENIZE(tokens=obj.documentation.description_tokens)}$#!
41 <!--(else)-->
42**MISSING DOCS !!!!!**#!
43 <!--(end)-->
44<!--(end)-->
45#!##############################################################################
46#!#### BEST_SINCE(obj) #######################################################
47#!##############################################################################
48<!--(macro BEST_SINCE)-->
49 <!--(if obj.documentation and obj.documentation.since)-->
50//Since ${obj.documentation.since}$//
51 <!--(end)-->
52<!--(end)-->
53#!##############################################################################
54#!#### UNTOKENIZE(tokens) ####################################################
55#!##############################################################################
56<!--(macro UNTOKENIZE)-->
57 <!--(for i, paragraph in enumerate(tokens))-->
58${'\n\n' if i else ''}$#!
59 <!--(for token in paragraph)-->
60 <!--(if token.type == Eolian_Doc_Token_Type.TEXT)-->
61%%${token.text}$%%#!
62 <!--(elif token.type == Eolian_Doc_Token_Type.REF)-->
63**REF ${token.text}$ ${token.ref}$ ??**#!
64 <!--(elif token.type == Eolian_Doc_Token_Type.MARKUP_MONOSPACE)-->
65''${token.text}$''#!
66 <!--(elif token.type == Eolian_Doc_Token_Type.MARK_NOTE)-->
67<note>
68${token.text}$
69</note>
70 <!--(elif token.type == Eolian_Doc_Token_Type.MARK_WARNING)-->
71<note warning>
72${token.text}$
73</note>
74 <!--(elif token.type == Eolian_Doc_Token_Type.MARK_REMARK)-->
75<note tip>
76${token.text}$
77</note>
78 <!--(elif token.type == Eolian_Doc_Token_Type.MARK_TODO)-->
79<note>
80**TODO:** ${token.text}$
81</note>
82 <!--(else)-->
83**USUPPORTED TOKEN TYPE ${token}$**
84 <!--(end)-->
85 <!--(end)-->
86 <!--(end)-->
87<!--(end)-->
88#!##############################################################################
89#!#### CLS_TYPE(cls) #########################################################
90#!##############################################################################
91<!--(macro CLS_TYPE)-->
92 <!--(if cls.type == Eolian_Class_Type.REGULAR)-->
93class#!
94 <!--(elif cls.type == Eolian_Class_Type.ABSTRACT)-->
95class#!
96 <!--(elif cls.type == Eolian_Class_Type.MIXIN)-->
97mixin#!
98 <!--(elif cls.type == Eolian_Class_Type.INTERFACE)-->
99interface#!
100 <!--(end)-->
101<!--(end)-->
102#!##############################################################################
103#!#### CLS_LINK(cls) #########################################################
104#!##############################################################################
105<!--(macro CLS_LINK)-->
106[[:develop:api#!
107 <!--(for n in cls.namespaces)-->
108:${n.lower()}$#!
109 <!--(end)-->
110:${cls.name.lower()}$|${cls.full_name}$]]
111<!--(end)-->
112#!##############################################################################
113#!#### EVENT_LINK(cls, ev) ###################################################
114#!##############################################################################
115<!--(macro EVENT_LINK)-->
116[[:develop:api#!
117 <!--(for n in cls.namespaces)-->
118:${n.lower()}$#!
119 <!--(end)-->
120:${cls.name.lower()}$#!
121:event#!
122:${ev.name.lower().replace(',','_')}$|${ev.name}$]]
123<!--(end)-->
124#!##############################################################################
125#!#### TYPEDECL_LINK(typedecl) ###############################################
126#!##############################################################################
127<!--(macro TYPEDECL_LINK)-->
128[[:develop:api#!
129 <!--(for n in typedecl.namespaces)-->
130:${n.lower()}$#!
131 <!--(end)-->
132:${typedecl.name.lower()}$|${typedecl.full_name}$]]
133<!--(end)-->
134#!##############################################################################
135#!#### TYPE_LINK(type) #######################################################
136#!##############################################################################
137<!--(macro TYPE_LINK)-->
138[[:develop:api#!
139 <!--(for n in type.namespaces)-->
140:${n.lower()}$#!
141 <!--(end)-->
142:${type.name.lower()}$|${type.full_name}$]]
143<!--(end)-->
144#!##############################################################################
145#!#### FUNC_LINK(func) #######################################################
146#!##############################################################################
147<!--(macro FUNC_LINK)-->
148[[:develop:api#!
149 <!--(for n in func.class_.namespaces)-->
150:${n.lower()}$#!
151 <!--(end)-->
152 <!--(if func.type == Eolian_Function_Type.METHOD)-->
153:method#!
154 <!--(else)-->
155:property#!
156 <!--(end)-->
157:${func.name}$|${func.name}$]]
158<!--(end)-->
159#!##############################################################################
160#!#### FUNC_SCOPE(func) ######################################################
161#!##############################################################################
162<!--(macro FUNC_SCOPE)-->
163 <!--(if func.is_class)-->
164 ''class method'' #!
165 <!--(end)-->
166 <!--(if func.type == Eolian_Function_Type.PROPERTY)-->
167 <!--(if func.getter_scope == Eolian_Object_Scope.PROTECTED)-->
168 ''protected get'' #!
169 <!--(elif func.getter_scope == Eolian_Object_Scope.PRIVATE)-->
170 ''private get'' #!
171 <!--(end)-->
172 <!--(if func.setter_scope == Eolian_Object_Scope.PROTECTED)-->
173 ''protected set'' #!
174 <!--(elif func.setter_scope == Eolian_Object_Scope.PRIVATE)-->
175 ''private set'' #!
176 <!--(end)-->
177 <!--(elif func.type == Eolian_Function_Type.METHOD)-->
178 <!--(if func.method_scope == Eolian_Object_Scope.PROTECTED)-->
179 ''protected'' #!
180 <!--(elif func.method_scope == Eolian_Object_Scope.PRIVATE)-->
181 ''private'' #!
182 <!--(end)-->
183 <!--(end)-->
184<!--(end)-->
185#!##############################################################################
186#!#### OBJECT_SCOPE(obj) #####################################################
187#!##############################################################################
188<!--(macro OBJECT_SCOPE)-->
189 <!--(if obj.scope == Eolian_Object_Scope.PROTECTED)-->
190 ''private'' #!
191 <!--(elif obj.scope == Eolian_Object_Scope.PRIVATE)-->
192 ''protected'' #!
193 <!--(end)-->
194<!--(end)-->
195#!##############################################################################
196#!#### EVENT_TAGS(ev) ########################################################
197#!##############################################################################
198<!--(macro EVENT_TAGS)-->
199 <!--(if ev.is_hot)-->
200 ''hot'' #!
201 <!--(elif ev.is_restart)-->
202 ''restart'' #!
203 <!--(end)-->
204<!--(end)-->
205#!##############################################################################
206#!#### IMPLEMENT_FULL(impl, cls) #############################################
207#!##############################################################################
208<!--(macro IMPLEMENT_FULL)-->
209**${FUNC_LINK(func=impl.function)}$** #!
210(#!
211 <!--(if impl.is_property)-->
212 <!--(for i, val in enumerate(impl.function.getter_values or impl.function.setter_values))-->
213${', ' if i else ''}$${val.type.name}$#!
214 <!--(end)-->
215 <!--(elif impl.is_method)-->
216 <!--(for i, param in enumerate(impl.function.parameters))-->
217${', ' if i else ''}$#!
218//${param.type.name}$// ''${param.direction.name.lower()}$'' **${param.name}$**#!
219 <!--(end)-->
220 <!--(end)-->
221)#!
222 <!--(if impl.is_prop_get and impl.is_prop_set)-->
223 ''rw'' #!
224 <!--(elif impl.is_prop_get)-->
225 ''read only'' #!
226 <!--(elif impl.is_prop_set)-->
227 ''write only'' #!
228 <!--(elif impl.is_method)-->
229 <!--(if impl.function.method_return_type)-->
230 => //${impl.function.method_return_type.name}$// #!
231 <!--(else)-->
232 => //None// #!
233 <!--(end)-->
234 <!--(end)-->
235${FUNC_SCOPE(func=impl.function)}$#!
236 <!--(if impl.class_ != cls)-->
237//[Overridden from ${CLS_LINK(cls=impl.class_)}$]// #!
238 <!--(end)-->
239\\
240> ${BEST_SUMMARY(obj=impl)}$
241<!--(end)-->
242#!##############################################################################
243#!#### OBJECT_STATIC_CONTENT(obj, section) ###################################
244#!##############################################################################
245<!--(macro OBJECT_STATIC_CONTENT)-->
246{{page>:develop:api-include#!
247 <!--(for ns in obj.namespaces)-->
248:${ns.lower()}$#!
249 <!--(end)-->
250:${obj.name.lower()}$#!
251:{section}#!
252&nouser&nolink&nodate}}
253<!--(end)-->
diff --git a/src/scripts/gendoc/doc_start.template b/src/scripts/gendoc/doc_start.template
new file mode 100644
index 0000000000..640f805d9d
--- /dev/null
+++ b/src/scripts/gendoc/doc_start.template
@@ -0,0 +1,52 @@
1<!--(include)-->doc_macros.include<!--(end)-->#!
2~~Title: EFL Reference~~
3{{page>:develop:api-include:reference:general&nouser&nolink&nodate}}
4
5<!--(for ns in nspaces)-->
6 <!--(if ns.name.startswith('Efl'))-->
7===== ${ns.name}$ =====
8
9 <!--(for i, cls in enumerate(ns.regulars))-->
10 <!--(if i == 0)-->
11^ Classes ^^
12 <!--(end)-->
13| ${CLS_LINK}$ | ${BEST_SUMMARY(obj=cls)}$ |
14 <!--(end)-->
15#!
16 <!--(for i, cls in enumerate(ns.interfaces))-->
17 <!--(if i == 0)-->
18^ Interfaces ^^
19 <!--(end)-->
20| ${CLS_LINK}$ | ${BEST_SUMMARY(obj=cls)}$ |
21 <!--(end)-->
22#!
23 <!--(for i, cls in enumerate(ns.mixins))-->
24 <!--(if i == 0)-->
25^ Mixins ^^
26 <!--(end)-->
27| ${CLS_LINK}$ | ${BEST_SUMMARY(obj=cls)}$ |
28 <!--(end)-->
29#!
30 <!--(for i, typedecl in enumerate(ns.aliases))-->
31 <!--(if i == 0)-->
32^ Aliases ^^
33 <!--(end)-->
34| ${TYPEDECL_LINK}$ | ${BEST_SUMMARY(obj=typedecl)}$ |
35 <!--(end)-->
36#!
37 <!--(for i, typedecl in enumerate(ns.structs))-->
38 <!--(if i == 0)-->
39^ Structures ^^
40 <!--(end)-->
41| ${TYPEDECL_LINK}$ | ${BEST_SUMMARY(obj=typedecl)}$ |
42 <!--(end)-->
43#!
44 <!--(for i, typedecl in enumerate(ns.enums))-->
45 <!--(if i == 0)-->
46^ Enumerations ^^
47 <!--(end)-->
48| ${TYPEDECL_LINK}$ | ${BEST_SUMMARY(obj=typedecl)}$ |
49 <!--(end)-->
50
51 <!--(end)-->
52<!--(end)-->
diff --git a/src/scripts/gendoc/doc_struct.template b/src/scripts/gendoc/doc_struct.template
new file mode 100644
index 0000000000..370e9be6e9
--- /dev/null
+++ b/src/scripts/gendoc/doc_struct.template
@@ -0,0 +1,39 @@
1<!--(include)-->doc_macros.include<!--(end)-->#!
2~~Title: ${struct.full_name}$~~
3====== ${struct.full_name}$ (struct) ======
4
5${BEST_SUMMARY(obj=struct)}$
6
7${BEST_DESCRIPTION(obj=struct)}$
8
9${BEST_SINCE(obj=struct)}$
10
11${OBJECT_STATIC_CONTENT(obj=struct, section='description')}$
12
13===== Fields =====
14
15${OBJECT_STATIC_CONTENT(obj=struct, section='fields')}$
16
17<!--(for field in struct.struct_fields)-->
18 * **${field.name}$** - ${BEST_SUMMARY(obj=field)}$
19<!--(end)-->
20
21===== Signature =====
22
23<code>
24struct ${struct.full_name}$ {
25<!--(for field in struct.struct_fields)-->
26 ${field.name}$: ${field.type.name}$,
27<!--(end)-->
28}
29</code>
30
31===== C Signature =====
32
33<code>
34typedef struct _${struct.full_name.replace('.', '_')}$ {
35<!--(for field in struct.struct_fields)-->
36 ${field.name}$: **TODO (issue with Typedecl.c_type need Unit)**,
37<!--(end)-->
38} ${struct.full_name.replace('.', '_')}$;
39</code>
diff --git a/src/scripts/gendoc/gendoc.py b/src/scripts/gendoc/gendoc.py
new file mode 100755
index 0000000000..394c641f44
--- /dev/null
+++ b/src/scripts/gendoc/gendoc.py
@@ -0,0 +1,115 @@
1#!/usr/bin/env python3
2# encoding: utf-8
3"""
4Efl documentation generator
5
6Use this script without arguments to generate the full documentation of the Efl
7namespace in a folder called 'dokuwiki' (-v to see all generated files)
8
9 --help to see all other options
10
11"""
12import os
13import sys
14import argparse
15import atexit
16
17
18# Use .eo files from the source tree (not the installed ones)
19script_path = os.path.dirname(os.path.realpath(__file__))
20root_path = os.path.abspath(os.path.join(script_path, '..', '..', '..'))
21SCAN_FOLDER = os.path.join(root_path, 'src', 'lib')
22
23
24# Use pyolian from source (not installed)
25pyolian_path = os.path.join(root_path, 'src', 'scripts')
26sys.path.insert(0, pyolian_path)
27from pyolian import eolian
28from pyolian.generator import Template
29
30
31# parse args
32parser = argparse.ArgumentParser(description='Pyolian DocuWiki generator.')
33parser.add_argument('--root-path', '-r', metavar='FOLDER', default='dokuwiki',
34 help='where to write files to (root of dokuwiki) '
35 'default to: "./dokuwiki"')
36parser.add_argument('--verbose', '-v', action='store_true',
37 help='print a line for each rendered file')
38parser.add_argument('--namespace', '-n', metavar='ROOT', default='Efl',
39 help='root namespace of the docs. (default to "Efl")')
40_choices = ['start', 'classes', 'enums', 'structs', 'aliases']
41parser.add_argument('--step', '-s', metavar='STEP', default=None,
42 choices=_choices,
43 help='A single step to run (default to all), '
44 'valid choises: '+ ', '.join(_choices))
45args = parser.parse_args()
46
47
48# load the whole eolian db (from .eo files in source tree)
49eolian_db = eolian.Eolian()
50if not isinstance(eolian_db, eolian.Eolian):
51 raise(RuntimeError('Eolian, failed to create Eolian state'))
52
53if not eolian_db.directory_scan(SCAN_FOLDER):
54 raise(RuntimeError('Eolian, failed to scan source directory'))
55
56if not eolian_db.all_eot_files_parse():
57 raise(RuntimeError('Eolian, failed to parse all EOT files'))
58
59if not eolian_db.all_eo_files_parse():
60 raise(RuntimeError('Eolian, failed to parse all EO files'))
61
62
63# cleanup the database on exit
64def cleanup_db():
65 global eolian_db
66 del eolian_db
67atexit.register(cleanup_db)
68
69
70# calculate the full path for the txt page of the given object
71def page_path_for_object(obj):
72 path = ['data', 'pages', 'develop', 'api']
73 for ns in obj.namespaces:
74 path.append(ns.lower())
75 output_file = obj.name.lower() + '.txt'
76 return os.path.join(args.root_path, *path, output_file)
77
78
79# render the main start.txt page
80if args.step in ('start', None):
81 t = Template('doc_start.template')
82 output_file = os.path.join(args.root_path,'data','pages','develop','api','start.txt')
83 t.render(output_file, args.verbose, nspaces=eolian_db.all_namespaces)
84
85# render a page for each Class
86if args.step in ('classes', None):
87 t = Template('doc_class.template')
88 for cls in eolian_db.all_classes:
89 if cls.full_name.startswith(args.namespace):
90 output_file = page_path_for_object(cls)
91 t.render(output_file, args.verbose, cls=cls.full_name)
92
93# render a page for each Enum
94if args.step in ('enums', None):
95 t = Template('doc_enum.template')
96 for enum in eolian_db.typedecl_all_enums:
97 if enum.full_name.startswith(args.namespace):
98 output_file = page_path_for_object(enum)
99 t.render(output_file, args.verbose, enum=enum.full_name)
100
101# render a page for each Struct
102if args.step in ('structs', None):
103 t = Template('doc_struct.template')
104 for struct in eolian_db.typedecl_all_structs:
105 if struct.full_name.startswith(args.namespace):
106 output_file = page_path_for_object(struct)
107 t.render(output_file, args.verbose, struct=struct.full_name)
108
109# render a page for each Alias
110if args.step in ('aliases', None):
111 t = Template('doc_alias.template')
112 for alias in eolian_db.typedecl_all_aliases:
113 if alias.full_name.startswith(args.namespace):
114 output_file = page_path_for_object(alias)
115 t.render(output_file, args.verbose, alias=alias.full_name)