Skip to content

Commit

Permalink
Add support for multiple tables per method to the documentation parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Nov 14, 2024
1 parent ec7d2bb commit 7197d9b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
50 changes: 31 additions & 19 deletions docs/ElunaDoc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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],
Expand Down
6 changes: 2 additions & 4 deletions docs/ElunaDoc/templates/method.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ <h2>{{ current_class.name }} Methods</h2>
<p>For temporary documentation, please check the <a href="https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp">LuaFunctions</a> source file.</p>
{%- endif %}

{%- if current_method.table %}
{%- if current_method.tables %}
<div class="table-container">
<p>
{{ current_method.table }}
</p>
{{ current_method.tables }}
</div>
{%- endif %}

Expand Down
12 changes: 6 additions & 6 deletions methods/TrinityCore/PlayerMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down Expand Up @@ -3859,6 +3858,7 @@ namespace LuaPlayer
player->SummonPet(entry, x, y, z, o, (PetType)petType, despwtime);
return 0;
}

/**
* Removes the [Player]'s active pet.
*
Expand Down

0 comments on commit 7197d9b

Please sign in to comment.