Skip to content

Commit

Permalink
adding a root-dir parameter so that we can generate the output wherev…
Browse files Browse the repository at this point in the history
…er we want
  • Loading branch information
SuperFola committed Aug 1, 2021
1 parent dbdc9b9 commit 89fbc5e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
- run: pip install -r requirements.txt
- run: |
export ARKDOC_LOGLEVEL=DEBUG
python -m arkdoc 3.1.0 std-latest/ --builtins ark-latest/src/Builtins --html out || exit 1
python -m arkdoc 3.1.0 std-latest/ ark-latest/src/Builtins --html out || exit 1
23 changes: 12 additions & 11 deletions arkdoc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
def compute(args) -> bool:
global logger

if not os.path.exists(args.source_folder):
logger.error(f"Folder `${args.source_folder}` does not exists")
return False
for folder in args.source_folder:
if not os.path.exists(folder):
logger.error(f"Folder `{folder}` does not exists")
return False

if args.dry_run:
logger.level = LogLevel.DEBUG

parsers = parse_all_in(args.source_folder)
if args.builtins:
parsers += parse_all_in(args.builtins)
parsers = []
for folder in args.source_folder:
parsers += parse_all_in(folder)
for p in parsers:
logger.info(f"Parsing {p.filename}...")
p.parse()
Expand All @@ -36,7 +37,7 @@ def compute(args) -> bool:

if not args.dry_run:
if args.html:
gen = HTMLGenerator(parsers, args.html, args.ark_version)
gen = HTMLGenerator(parsers, args.html, args.ark_version, args.root_dir)
gen()
else:
logger.error("Missing generator!")
Expand All @@ -49,17 +50,17 @@ def main() -> int:
cli = argparse.ArgumentParser(description="ArkScript Documentation generator")
cli.add_argument("ark_version", type=str, help="ArkScript version number, eg 3.1.0")
cli.add_argument(
"source_folder", type=str, help="Path to the ArkScript source folder"
)
cli.add_argument(
"--builtins", type=str, help="Path to the builtins folder", default=None
"source_folder", type=str, help="Path to the ArkScript source folder", nargs="+"
)
cli.add_argument(
"--dry-run",
action="store_true",
help="Run and log everything but don't generate any file",
)
cli.add_argument("--html", type=str, help="Output folder for the HTML docs")
cli.add_argument(
"--root-dir", type=str, default="", help="The root dir for the links"
)

args = cli.parse_args()

Expand Down
4 changes: 3 additions & 1 deletion arkdoc/generator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ def __init__(
pattern: str,
output: str,
ark_version: str,
root: str,
):
self.template_folder = template_folder
self.templates = {
file.name: file.read_text("utf-8") for file in template_folder.glob(pattern)
}
self.version = ark_version
self.output_path = Path(output)
self.version = ark_version
self.output_path_ver = self.output_path / self.version
self.root = root if root and root[-1] != "/" else root[:-1]
self.list = spec.FileList([])
self._create_files_list(parsers)

Expand Down
14 changes: 8 additions & 6 deletions arkdoc/generator/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def h4(name: str) -> str:


class HTMLGenerator(Generator):
def __init__(self, parsers: List[Parser], output: str, ark_version: str):
def __init__(self, parsers: List[Parser], output: str, ark_version: str, root: str):
super().__init__(
parsers, spec.HTML_TEMPLATE_FOLDER, "*.html", output, ark_version
parsers, spec.HTML_TEMPLATE_FOLDER, "*.html", output, ark_version, root
)

self.footer = f"<i>Last generation at {datetime.now()}</i>"
Expand All @@ -111,18 +111,19 @@ def generate_index(self):
f"Welcome! This is the official documentation for ArkScript {self.version}"
+ html.ul(
[
html.a(file.path, f"/{self.version}/{file.path}.html")
html.a(file.path, f"{self.root}/{self.version}/{file.path}.html")
for file in self.list.files
]
),
)

content = self.templates["index.html"]
content = content.format(
root=self.root,
page_title=f"ArkScript {self.version} documentation",
home_link=f"/{self.version}",
home_link=f"{self.root}/{self.version}",
has_banner="has-banner",
banner=self.templates["banner.html"],
banner=self.templates["banner.html"].format(root=self.root),
table_of_content="",
navigation_links="",
sections=sections,
Expand Down Expand Up @@ -180,8 +181,9 @@ def generate_one(self, path: str, functions: List[spec.Function]):

content = self.templates["index.html"]
content = content.format(
root=self.root,
page_title=f"{path} - ArkScript {self.version} documentation",
home_link=f"/{self.version}",
home_link=f"{self.root}/{self.version}",
has_banner="",
banner="",
table_of_content=table_of_content,
Expand Down
2 changes: 1 addition & 1 deletion templates/banner.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<section class="navbar-center">
<div class="banner-center">
<figure class="figure">
<img class="img-responsive" src="/assets/images/Ark-slim.png" alt="ArkScript">
<img class="img-responsive" src="{root}/assets/images/Ark-slim.png" alt="ArkScript">
<figcaption class="figure-caption navbar-brand">ArkScript</figcaption>
</figure>
</div>
Expand Down
16 changes: 8 additions & 8 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<title>{page_title}</title>
<link rel="stylesheet" href="/assets/css/spectre.min.css" type="text/css">
<link rel="stylesheet" href="/assets/css/spectre-exp.min.css" type="text/css">
<link rel="stylesheet" href="/assets/css/spectre-icons.min.css" type="text/css">
<link rel="stylesheet" href="/assets/css/rainbowjs-theme.css" type="text/css">
<link rel="stylesheet" href="/assets/css/main.css" type="text/css">
<link rel="stylesheet" href="{root}/assets/css/spectre.min.css" type="text/css">
<link rel="stylesheet" href="{root}/assets/css/spectre-exp.min.css" type="text/css">
<link rel="stylesheet" href="{root}/assets/css/spectre-icons.min.css" type="text/css">
<link rel="stylesheet" href="{root}/assets/css/rainbowjs-theme.css" type="text/css">
<link rel="stylesheet" href="{root}/assets/css/main.css" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
Expand All @@ -27,7 +27,7 @@
<a href="https://discord.gg/YT5yDwn" target="_blank" class="btn btn-link">Discord</a>
</section>
<section class="navbar-section logo">
<a href="/" class="hide"><img src="/assets/images/Ark-slim.png" alt="ArkScript"></a>
<a href="{root}/" class="hide"><img src="{root}/assets/images/Ark-slim.png" alt="ArkScript"></a>
</section>
</header>

Expand Down Expand Up @@ -60,8 +60,8 @@
</footer>

<!-- Rainbow.js for syntax coloring -->
<script src="/assets/js/rainbow.min.js"></script>
<script src="/assets/js/languages/arkscript.js"></script>
<script src="{root}/assets/js/rainbow.min.js"></script>
<script src="{root}/assets/js/languages/arkscript.js"></script>
</body>

</html>

0 comments on commit 89fbc5e

Please sign in to comment.