From 7197d9b39594200d5fa057d211d90832389dd4d3 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Thu, 14 Nov 2024 22:28:48 +0100 Subject: [PATCH] Add support for multiple tables per method to the documentation parser --- docs/ElunaDoc/parser.py | 50 ++++++++++++++++++----------- docs/ElunaDoc/templates/method.html | 6 ++-- methods/TrinityCore/PlayerMethods.h | 12 +++---- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/docs/ElunaDoc/parser.py b/docs/ElunaDoc/parser.py index b0b38c1f13..8f540c667d 100644 --- a/docs/ElunaDoc/parser.py +++ b/docs/ElunaDoc/parser.py @@ -68,23 +68,34 @@ def __init__(self, name, data_type, description, default_value=None): class MethodDoc(object): """The documentation data of an Eluna method.""" - @params(self=object, name=str, description=str, table=TableDict, prototypes=[str], parameters=[ParameterDoc], returned=[ParameterDoc]) - def __init__(self, name, description, table, prototypes, parameters, returned): + @params(self=object, name=str, description=str, tables=[TableDict], prototypes=[str], parameters=[ParameterDoc], returned=[ParameterDoc]) + def __init__(self, name, description, tables, prototypes, parameters, returned): self.name = name self.prototypes = prototypes - self.table = table + self.tables = tables self.parameters = parameters self.returned = returned - - if table: - # Generate Markdown Table - md_table = '| ' + ' | '.join(table['columns']) + ' |\n' # Header - md_table += '| ' + ' | '.join(['---'] * len(table['columns'])) + ' |\n' # Separator - for row in table['values']: - md_table += '| ' + ' | '.join(row) + ' |\n' # Rows + if tables: + html_tables = [] + + for table in tables: + print("-------------") + # Generate Markdown Table for each table + md_table = '| ' + ' | '.join(table['columns']) + ' |\n' # Header + md_table += '| ' + ' | '.join(['---'] * len(table['columns'])) + ' |\n' # Separator + + for row in table['values']: + md_table += '| ' + ' | '.join(row) + ' |\n' # Rows + + # Convert the generated Markdown table to HTML + html_table = markdown.markdown(md_table, extensions=['tables']) - self.table = markdown.markdown(md_table, extensions=['tables']) + # Append the HTML table to the list + html_tables.append(html_table) + + # Combine all HTML tables into a single string (separated by two newlines) + self.tables = ''.join(html_tables) # Parse the description as Markdown. self.description = markdown.markdown(description) @@ -182,7 +193,7 @@ def reset(self): self.returned = [] self.method_name = None self.prototypes = [] - self.table = {} + self.tables = [] def handle_class_body(self, match): text = match.group(1) @@ -193,19 +204,20 @@ def handle_body(self, match): self.description += text + '\n' def handle_table(self, line): - self.table = { + new_table = { "columns": [], "values": [] } + self.tables.append(new_table) def handle_table_columns(self, match): - if self.table: - self.table["columns"] = match.group(1).split(", ") + if self.tables: + self.tables[-1]["columns"] = match.group(1).split(", ") def handle_table_values(self, match): - if self.table: + if self.tables: values = re.findall(r'(?:[^,"]|"(?:\\.|[^"])*")+', match.group(1)) - self.table["values"].append([v.strip(' "') for v in values]) + self.tables[-1]["values"].append([v.strip(' "') for v in values]) def handle_param(self, match): data_type, name, default, description = match.group(1), match.group(2), match.group(3), match.group(4) @@ -282,7 +294,7 @@ def make_prototype(parameters): # Format the method name into each prototype. self.prototypes = [proto.format(self.method_name) for proto in self.prototypes] - self.methods.append(MethodDoc(self.method_name, self.description, self.table, self.prototypes, self.params, self.returned)) + self.methods.append(MethodDoc(self.method_name, self.description, self.tables, self.prototypes, self.params, self.returned)) # Table of which handler is used to handle each regular expressions. regex_handlers = { @@ -313,7 +325,7 @@ def make_prototype(parameters): proto_regex: [table_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex], table_regex: [table_regex, table_columns_regex, param_regex, return_regex, comment_end_regex, body_regex], table_columns_regex: [table_values_regex, param_regex, return_regex, comment_end_regex, body_regex], - table_values_regex: [table_values_regex, param_regex, return_regex, comment_end_regex, body_regex], + table_values_regex: [table_values_regex, table_regex, param_regex, return_regex, comment_end_regex, body_regex], param_regex: [table_regex, param_regex, return_regex, comment_end_regex, body_regex], return_regex: [return_regex, comment_end_regex], comment_end_regex: [end_regex], diff --git a/docs/ElunaDoc/templates/method.html b/docs/ElunaDoc/templates/method.html index 55671b161b..d7826d003e 100644 --- a/docs/ElunaDoc/templates/method.html +++ b/docs/ElunaDoc/templates/method.html @@ -47,11 +47,9 @@

{{ current_class.name }} Methods

For temporary documentation, please check the LuaFunctions source file.

{%- endif %} - {%- if current_method.table %} + {%- if current_method.tables %}
-

- {{ current_method.table }} -

+ {{ current_method.tables }}
{%- endif %} diff --git a/methods/TrinityCore/PlayerMethods.h b/methods/TrinityCore/PlayerMethods.h index 73404335f4..c0f2e0a3d9 100644 --- a/methods/TrinityCore/PlayerMethods.h +++ b/methods/TrinityCore/PlayerMethods.h @@ -2939,7 +2939,7 @@ namespace LuaPlayer * Equips the given item or item entry to the given slot. Returns the equipped item or nil. * * @table - * @columns [Slot, ID] + * @columns [EquipSlot, ID] * @values [EQUIPMENT_SLOT_HEAD, 0] * @values [EQUIPMENT_SLOT_NECK, 1] * @values [EQUIPMENT_SLOT_SHOULDERS, 2] @@ -2960,11 +2960,10 @@ namespace LuaPlayer * @values [EQUIPMENT_SLOT_RANGED, 17] * @values [EQUIPMENT_SLOT_TABARD, 18] * - * enum InventorySlots // 4 slots - * { - * INVENTORY_SLOT_BAG_START = 19, - * INVENTORY_SLOT_BAG_END = 23 - * }; + * @table + * @columns [BagSlot, ID] + * @values [INVENTORY_SLOT_BAG_START, 19] + * @values [INVENTORY_SLOT_BAG_END, 23] * * @proto equippedItem = (item, slot) * @proto equippedItem = (entry, slot) @@ -3859,6 +3858,7 @@ namespace LuaPlayer player->SummonPet(entry, x, y, z, o, (PetType)petType, despwtime); return 0; } + /** * Removes the [Player]'s active pet. *