Skip to content

Commit 1207ced

Browse files
committed
formatting code
1 parent d6ca692 commit 1207ced

File tree

4 files changed

+49
-33
lines changed

4 files changed

+49
-33
lines changed

arkdoc/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .logger_utils import Logger, LogLevel
44

55
import os
6+
67
logger = Logger("ArkDoc", level=LogLevel[os.environ.get("ARKDOC_LOGLEVEL", "INFO")])
78

89
from .parser import Parser

arkdoc/__main__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def compute(args) -> bool:
4747

4848
def main() -> int:
4949
cli = argparse.ArgumentParser(description="ArkScript Documentation generator")
50-
cli.add_argument(
51-
"ark_version", type=str, help="ArkScript version number, eg 3.1.0"
52-
)
50+
cli.add_argument("ark_version", type=str, help="ArkScript version number, eg 3.1.0")
5351
cli.add_argument(
5452
"source_folder", type=str, help="Path to the ArkScript source folder"
5553
)

arkdoc/generator/base.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212

1313

1414
class Generator:
15-
def __init__(self, parsers: List[Parser], template_folder: Path, pattern: str, output: str, ark_version: str):
15+
def __init__(
16+
self,
17+
parsers: List[Parser],
18+
template_folder: Path,
19+
pattern: str,
20+
output: str,
21+
ark_version: str,
22+
):
1623
self.template_folder = template_folder
1724
self.templates = {
18-
file.name: file.read_text("utf-8")
19-
for file in template_folder.glob(pattern)
25+
file.name: file.read_text("utf-8") for file in template_folder.glob(pattern)
2026
}
2127
self.version = ark_version
2228
self.output_path = Path(output)
@@ -57,6 +63,8 @@ def __call__(self):
5763
self.generate_index()
5864

5965
for file in self.list.files:
60-
logger.info(f"Generating {file.path} documentation... found {len(file.functions)} functions")
66+
logger.info(
67+
f"Generating {file.path} documentation... found {len(file.functions)} functions"
68+
)
6169

6270
self.generate_one(file.path, file.functions)

arkdoc/generator/html.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def plural(name: str, qu: int) -> str:
1919

2020
@staticmethod
2121
def nav_link(name: str, path: str) -> str:
22-
return f"<a href=\"{path}\" class=\"btn btn-link\">{name}</a>"
22+
return f'<a href="{path}" class="btn btn-link">{name}</a>'
2323

2424
@staticmethod
2525
def anchorize(name: str) -> str:
@@ -33,7 +33,7 @@ def nav_item(name: str, anchor: str) -> str:
3333

3434
@staticmethod
3535
def a(name: str, path: str) -> str:
36-
return f"<a href=\"{path}\">{name}</a>"
36+
return f'<a href="{path}">{name}</a>'
3737

3838
@staticmethod
3939
def b(content: str) -> str:
@@ -52,7 +52,7 @@ def code(content: str) -> str:
5252
</pre>"""
5353

5454
@staticmethod
55-
def section(title: str, content: str, anchor: str="") -> str:
55+
def section(title: str, content: str, anchor: str = "") -> str:
5656
return f"""<section {f'id="{anchor}"' if anchor else ''}>
5757
<h2>{title}</h2>
5858
@@ -91,7 +91,9 @@ def h4(name: str) -> str:
9191

9292
class HTMLGenerator(Generator):
9393
def __init__(self, parsers: List[Parser], output: str, ark_version: str):
94-
super().__init__(parsers, spec.HTML_TEMPLATE_FOLDER, "*.html", output, ark_version)
94+
super().__init__(
95+
parsers, spec.HTML_TEMPLATE_FOLDER, "*.html", output, ark_version
96+
)
9597

9698
self.footer = f"<i>Last generation at {datetime.now()}</i>"
9799

@@ -100,12 +102,19 @@ def create_dir(self, name: str):
100102

101103
def generate_index(self):
102104
if not (self.output_path / "assets").exists():
103-
shutil.copytree(str(self.template_folder / "assets"), str(self.output_path / "assets"))
105+
shutil.copytree(
106+
str(self.template_folder / "assets"), str(self.output_path / "assets")
107+
)
104108

105109
sections = html.section(
106110
f"ArkScript {self.version} documentation",
107-
f"Welcome! This is the official documentation for ArkScript {self.version}" +
108-
html.ul([html.a(file.path, f"/{self.version}/{file.path}.html") for file in self.list.files])
111+
f"Welcome! This is the official documentation for ArkScript {self.version}"
112+
+ html.ul(
113+
[
114+
html.a(file.path, f"/{self.version}/{file.path}.html")
115+
for file in self.list.files
116+
]
117+
),
109118
)
110119

111120
content = self.templates["index.html"]
@@ -117,7 +126,7 @@ def generate_index(self):
117126
table_of_content="",
118127
navigation_links="",
119128
sections=sections,
120-
footer=self.footer
129+
footer=self.footer,
121130
)
122131

123132
(self.output_path_ver / "index.html").write_text(content)
@@ -131,31 +140,31 @@ def generate_one(self, path: str, functions: List[spec.Function]):
131140
for func in functions:
132141
links += html.nav_item(func.name, html.anchorize(func.name))
133142
content = html.div(
134-
html.inline_code(func.signature), "<br>",
143+
html.inline_code(func.signature),
144+
"<br>",
135145
html.div(func.desc.brief),
136-
html.div(
137-
html.b("Note"), ": ",
138-
func.desc.details
139-
),
146+
html.div(html.b("Note"), ": ", func.desc.details),
140147
html.div(
141148
html.h4(html.plural("Parameter", len(func.desc.params))),
142-
html.ul([
143-
f"{html.inline_code(p.name)}: {p.desc}" for p in func.desc.params
144-
])
149+
html.ul(
150+
[
151+
f"{html.inline_code(p.name)}: {p.desc}"
152+
for p in func.desc.params
153+
]
154+
),
145155
),
146156
html.div(
147157
html.h4(html.plural("Author", len(func.desc.authors))),
148-
", ".join([
149-
html.a(f"@{a.split('/')[-1]}", a) for a in func.desc.authors
150-
])
151-
)
158+
", ".join(
159+
[html.a(f"@{a.split('/')[-1]}", a) for a in func.desc.authors]
160+
),
161+
),
152162
)
153163
if func.desc.code:
154-
content += html.div(
155-
html.h4("Example"),
156-
html.code(func.desc.code)
157-
)
158-
sections += html.section(func.name, content, anchor=html.anchorize(func.name))
164+
content += html.div(html.h4("Example"), html.code(func.desc.code))
165+
sections += html.section(
166+
func.name, content, anchor=html.anchorize(func.name)
167+
)
159168

160169
table_of_content = table_of_content.format(table_of_content_links=links)
161170

@@ -168,7 +177,7 @@ def generate_one(self, path: str, functions: List[spec.Function]):
168177
table_of_content=table_of_content,
169178
navigation_links="",
170179
sections=sections,
171-
footer=self.footer
180+
footer=self.footer,
172181
)
173182

174183
(self.output_path_ver / f"{path}.html").write_text(content)

0 commit comments

Comments
 (0)