Skip to content

Commit 91477ca

Browse files
committed
Add warning tag support to documentation generator
1 parent 99cfec7 commit 91477ca

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

docs/ElunaDoc/parser.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def __init__(self, name, data_type, description, default_value=None):
6868

6969
class MethodDoc(object):
7070
"""The documentation data of an Eluna method."""
71-
@params(self=object, name=str, description=str, tables=[TableDict], prototypes=[str], parameters=[ParameterDoc], returned=[ParameterDoc])
72-
def __init__(self, name, description, tables, prototypes, parameters, returned):
71+
@params(self=object, name=str, description=str, tables=[TableDict], prototypes=[str], warning=[str], parameters=[ParameterDoc], returned=[ParameterDoc])
72+
def __init__(self, name, description, tables, prototypes, warning, parameters, returned):
7373
self.name = name
7474
self.prototypes = prototypes
7575
self.tables = tables
@@ -110,6 +110,9 @@ def __init__(self, name, description, tables, prototypes, parameters, returned):
110110
self.short_description = self.description.split('</p>')[0][3:]
111111
# If it has a description, it is "documented".
112112
self.documented = self.description != ''
113+
# Parse the warning as Markdown, but remote <p> tags
114+
self.warning = markdown.markdown(warning)
115+
self.warning = re.sub(r'^<p>(.*?)</p>$', r'\1', self.warning, flags=re.DOTALL)
113116

114117
"""Helper function to parse table dictionaries. Only used in Register methods for now."""
115118
def _format_dict_values(self, d):
@@ -171,6 +174,9 @@ class ClassParser(object):
171174
table_columns_regex = re.compile(r"\s*\*\s@columns\s*\[(.+)\]")
172175
table_values_regex = re.compile(r"\s*\*\s@values\s*\[(.+?)\]")
173176

177+
# Regex for catching warning tags
178+
warning_regex = re.compile(r"""\s*\*\s*@warning\s+(.+)""", re.X)
179+
174180
param_regex = re.compile(r"""\s*\*\s@param\s # The @param tag starts with opt. whitespace followed by "* @param ".
175181
([^\s]+)\s(\w+)? # The data type, a space, and the name of the param.
176182
(?:\s=\s([^\s:]+))? # The default value: a space, =, and a value that can include periods but stops at whitespace or a colon.
@@ -207,6 +213,7 @@ def reset(self):
207213

208214
# These are used to piece together the next `Method`.
209215
self.description = ''
216+
self.warning = ''
210217
self.params = []
211218
self.returned = []
212219
self.method_name = None
@@ -253,6 +260,10 @@ def handle_table_values(self, match):
253260
# Append the processed values to the last table
254261
self.tables[-1]["values"].append(processed_values)
255262

263+
def handle_warning(self, match):
264+
warning = match.group(1)
265+
self.warning += warning
266+
256267
def handle_param(self, match):
257268
data_type, name, default, description = match.group(1), match.group(2), match.group(3), match.group(4)
258269
self.params.append(ParameterDoc(name, data_type, description, default))
@@ -328,7 +339,7 @@ def make_prototype(parameters):
328339
# Format the method name into each prototype.
329340
self.prototypes = [proto.format(self.method_name) for proto in self.prototypes]
330341

331-
self.methods.append(MethodDoc(self.method_name, self.description, self.tables, self.prototypes, self.params, self.returned))
342+
self.methods.append(MethodDoc(self.method_name, self.description, self.tables, self.prototypes, self.warning, self.params, self.returned))
332343

333344
# Table of which handler is used to handle each regular expressions.
334345
regex_handlers = {
@@ -340,6 +351,7 @@ def make_prototype(parameters):
340351
table_regex: handle_table,
341352
table_columns_regex: handle_table_columns,
342353
table_values_regex: handle_table_values,
354+
warning_regex: handle_warning,
343355
param_regex: handle_param,
344356
return_regex: handle_return,
345357
proto_regex: handle_proto,
@@ -354,13 +366,14 @@ def make_prototype(parameters):
354366
class_start_regex: [class_end_regex, class_body_regex],
355367
class_body_regex: [class_end_regex, class_body_regex],
356368
class_end_regex: [],
357-
start_regex: [table_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
358-
body_regex: [table_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
359-
proto_regex: [table_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
360-
table_regex: [table_regex, table_columns_regex, param_regex, return_regex, comment_end_regex, body_regex],
361-
table_columns_regex: [table_values_regex, param_regex, return_regex, comment_end_regex, body_regex],
362-
table_values_regex: [table_values_regex, table_regex, param_regex, return_regex, comment_end_regex, body_regex],
363-
param_regex: [table_regex, param_regex, return_regex, comment_end_regex, body_regex],
369+
start_regex: [table_regex, warning_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
370+
body_regex: [table_regex, warning_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
371+
proto_regex: [table_regex, warning_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
372+
table_regex: [table_regex, table_columns_regex, warning_regex, param_regex, return_regex, comment_end_regex, body_regex],
373+
table_columns_regex: [table_values_regex, warning_regex, param_regex, return_regex, comment_end_regex, body_regex],
374+
table_values_regex: [table_values_regex, table_regex, warning_regex, param_regex, return_regex, comment_end_regex, body_regex],
375+
warning_regex: [table_values_regex, table_regex, warning_regex, param_regex, return_regex, comment_end_regex, body_regex],
376+
param_regex: [table_regex, warning_regex, param_regex, return_regex, comment_end_regex, body_regex],
364377
return_regex: [return_regex, comment_end_regex],
365378
comment_end_regex: [end_regex],
366379
end_regex: [],

docs/ElunaDoc/templates/method.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ <h2>{{ current_class.name }} Methods</h2>
3939

4040

4141
{% block content %}
42+
{%- if current_method.warning %}
43+
<div style="border: 1px solid #f44336; background-color: #fdecea; color: #b71c1c; padding: 12px; border-radius: 4px; margin: 10px 0;">
44+
<strong>Warning:</strong> {{ current_method.warning }}
45+
</div>
46+
{%- endif %}
4247
<div class='docblock'>
4348
{%- if current_method.documented %}
4449
{{ current_method.description|parse_links }}

methods/TrinityCore/GlobalMethods.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,8 @@ namespace LuaGlobalFunctions
12721272
* until not Q:NextRow()
12731273
* end
12741274
*
1275+
* @warning This method is flagged as **unsafe** and is **disabled by default**. Use with caution, or transition to Async queries.
1276+
*
12751277
* @param string sql : query to execute
12761278
* @return [ElunaQuery] results or nil if no rows found or nil if no rows found
12771279
*/
@@ -1371,6 +1373,8 @@ namespace LuaGlobalFunctions
13711373
*
13721374
* For an example see [Global:WorldDBQuery].
13731375
*
1376+
* @warning This method is flagged as **unsafe** and is **disabled by default**. Use with caution, or transition to Async queries.
1377+
*
13741378
* @param string sql : query to execute
13751379
* @return [ElunaQuery] results or nil if no rows found
13761380
*/
@@ -1462,6 +1466,8 @@ namespace LuaGlobalFunctions
14621466
*
14631467
* For an example see [Global:WorldDBQuery].
14641468
*
1469+
* @warning This method is flagged as **unsafe** and is **disabled by default**. Use with caution, or transition to Async queries.
1470+
*
14651471
* @param string sql : query to execute
14661472
* @return [ElunaQuery] results or nil if no rows found
14671473
*/

0 commit comments

Comments
 (0)