Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ temp/
*.tiled-session

doc/api_docs/api/*.rst

# Pyenv local
.python-version
Binary file added doc/_static/checkered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions doc/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,10 @@ body:not([data-theme="light"]) .highlight .c1 {
.highlight .c1 {
color: #007507;
}

.checkered {
background-image: url(../checkered.png);
background-repeat: repeat;
margin:0px;
padding: 0px;
}
82 changes: 48 additions & 34 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
Generate HTML docs
"""

import runpy
import sys
import docutils.nodes
import os
import re
import runpy
import sphinx.ext.autodoc
import sphinx.transforms
import docutils.nodes
import sys


# --- Pre-processing Tasks

Expand Down Expand Up @@ -205,45 +207,57 @@ def warn_undocumented_members(_app, what, name, _obj, _options, lines):
))


def source_read(_app, docname, source):
def generate_color_table(filename, source):
"""This function Generates the Color tables in the docs for color and csscolor packages"""

# print(f" XXX Reading {docname}")
import os
file_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(file_path)
append_text = "\n\n.. raw:: html\n\n"
append_text += " <table class='colorTable'><tbody>\n"

filename = None
if docname == "api_docs/arcade.color":
filename = "../arcade/color/__init__.py"
elif docname == "api_docs/arcade.csscolor":
filename = "../arcade/csscolor/__init__.py"
# Will match a line containing:
# name '(?P<name>[a-z_A-Z]*)' followed by
# a Color '(?: *= *Color *\( *)' followed by
# red '(?P<red>\d*)' followed by
# green '(?P<green>\d*)' followed by
# blue '(?P<blue>\d*)' followed by
# alpha '(?P<alpha>\d*)'
color_match = re.compile(r'(?P<name>[a-z_A-Z]*)(?:[ =]*Color[ (]*)(?P<red>\d*)[ ,]*(?P<green>\d*)[ ,]*(?P<blue>\d*)[ ,]*(?P<alpha>\d*)')

if filename:
# print(f" XXX Handling color file: {filename}")
import re
p = re.compile(r"^([A-Z_]+) = (\(.*\))")
with open(filename) as color_file:
for line in color_file:

original_text = source[0]
append_text = "\n\n.. raw:: html\n\n"
append_text += " <table class='colorTable'><tbody>\n"
color_file = open(filename)
# Check if the line has a Color.
matches = color_match.match(line)
if not matches:
continue

color_rgba = f"({matches.group('red')}, {matches.group('green')}, {matches.group('blue')}, {matches.group('alpha')})"

# Generate the alpha for CSS color function
alpha = int( matches.group('alpha') ) / 255
css_rgba = f"({matches.group('red')}, {matches.group('green')}, {matches.group('blue')}, {alpha!s:.4})"

for line in color_file:
match = p.match(line)

if match:
color_variable_name = match.group(1)
color_tuple = tuple(int(num) for num in match.group(2).strip('()').split(','))
color_rgb_string = ', '.join(str(i) for i in color_tuple[:3])
append_text += " <tr>"
append_text += f"<td>{matches.group('name')}</td>"
append_text += f"<td>{color_rgba}</td>"
append_text += f"<td class='checkered'><div style='background-color:rgba{css_rgba};'>&nbsp</div></td>"
append_text += "</tr>\n"

append_text += " <tr>"
append_text += f"<td>{color_variable_name}</td>"
append_text += f"<td>{color_tuple}</td>"
append_text += f"<td style='background-color:rgba({color_rgb_string}, {color_tuple[3] / 255});'><div></div></td>"
append_text += "</tr>\n"
append_text += " </tbody></table>"
source[0] += append_text


def source_read(_app, docname, source):
"""Event handler for source-read event"""

append_text += " </tbody></table>"
source[0] = original_text + append_text
file_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(file_path)

# Transform source for arcade.color and arcade.csscolor
if docname == "api_docs/arcade.color":
generate_color_table("../arcade/color/__init__.py", source)
elif docname == "api_docs/arcade.csscolor":
generate_color_table("../arcade/csscolor/__init__.py", source)


def post_process(_app, _exception):
Expand Down