Redid Docs Generation

This commit is contained in:
Ben C 2022-03-02 23:24:17 -05:00
parent be71162d24
commit 290a7d54c9
33 changed files with 262 additions and 196 deletions

View File

@ -70,8 +70,8 @@
"angle": { "angle": {
"type": "number", "type": "number",
"default": 0, "default": 0,
"min": 0, "minimum": 0,
"max": 360 "maximum": 360
}, },
"curve": { "curve": {
"type": "array", "type": "array",
@ -104,7 +104,7 @@
} }
} }
}, },
"title": "Planet", "title": "Body",
"description": "A planet or body to generate", "description": "A planet or body to generate",
"type": "object", "type": "object",
"required": [ "required": [
@ -627,7 +627,7 @@
"shipSpawnPoint": { "shipSpawnPoint": {
"$ref": "#/$defs/vector3" "$ref": "#/$defs/vector3"
}, },
"starWithSuit": { "startWithSuit": {
"type": "boolean", "type": "boolean",
"default": false "default": false
} }

View File

@ -1,6 +1,7 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object", "type": "object",
"title": "Star System",
"description": "Configuration for a specific star system", "description": "Configuration for a specific star system",
"properties": { "properties": {
"canEnterViaWarpDrive": { "canEnterViaWarpDrive": {

View File

@ -6,6 +6,7 @@ name = "pypi"
[packages] [packages]
jinja2 = "*" jinja2 = "*"
json-schema-for-humans = "*" json-schema-for-humans = "*"
markdown = "*"
[dev-packages] [dev-packages]

10
docs/Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "b4acdc18f2bf25fdf7a2448229884300b7e3ec47731a49ad482b21d32c627370" "sha256": "600dddfc39d9e9ca825fd1870bfa2094e3124c7d1759be513936f1d0d842cd5c"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -85,6 +85,14 @@
"index": "pypi", "index": "pypi",
"version": "==0.40" "version": "==0.40"
}, },
"markdown": {
"hashes": [
"sha256:76df8ae32294ec39dcf89340382882dfa12975f87f45c3ed1ecdb1e8cefc7006",
"sha256:9923332318f843411e9932237530df53162e29dc7a4e2b91e35764583c46c9a3"
],
"index": "pypi",
"version": "==3.3.6"
},
"markdown2": { "markdown2": {
"hashes": [ "hashes": [
"sha256:8f4ac8d9a124ab408c67361090ed512deda746c04362c36c2ec16190c720c2b0", "sha256:8f4ac8d9a124ab408c67361090ed512deda746c04362c36c2ec16190c720c2b0",

View File

@ -1,3 +1,9 @@
{% if dumb %}
{% from 'macros.jinja2' import external_link, is_active_page, nav_item with context %}
{% else %}
{% from 'base/macros.jinja2' import external_link, is_active_page, nav_item with context %}
{% endif %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -18,7 +24,7 @@
<header> <header>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-2"> <nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-2">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="/">New Horizons</a> <a class="navbar-brand" href="{{ 'home'|route }}">New Horizons</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation"> aria-expanded="false" aria-label="Toggle navigation">
@ -26,32 +32,28 @@
</button> </button>
<div class="collapse navbar-collapse" id="navbarSupportedContent"> <div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0"> <ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item"> {% for nav_page in pages %}
<a class="nav-link active" aria-current="page" href="/">Home</a> {{ nav_item(nav_page.title|title, nav_page.title|route) }}
</li> {% endfor %}
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" <a class="nav-link {% if page in schemas %}active{% endif %} dropdown-toggle" {% if page in schemas %}aria-current="page"{% endif %} href="#" id="navbarDropdown" role="button"
data-bs-toggle="dropdown" aria-expanded="false"> data-bs-toggle="dropdown" aria-expanded="false">
Schemas Schemas
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for schema in schemas %} {% for schema in schemas %}
<li><a class="dropdown-item" <li><a class="dropdown-item"
href="/schemas/{{ schema.out_name }}.html">{{ schema.title|title }}</a></li> href="{{ schema.title|route }}">{{ schema.title|title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</li> </li>
</ul> </ul>
<ul class="navbar-nav mb-2 mb-lg-0"> <ul class="navbar-nav mb-2 ms-md-auto mb-lg-0">
<li class="nav-item me-2"> <li class="nav-item me-2">
<a class="link-light" href="https://github.com/xen-42/outer-wilds-new-horizons"> {{ external_link("<i class=\"bi-github\"></i><small class=\"d-lg-none ms-2\">GitHub</small>", "https://github.com/xen-42/outer-wilds-new-horizons", "nav-link p-2 fs-5") }}
<i class="bi-github"></i>
</a>
</li> </li>
<li class="nav-item me-2"> <li class="nav-item me-2">
<a class="link-light" href="https://github.com/xen-42/outer-wilds-new-horizons"> {{ external_link("<i class=\"bi-discord\"></i><small class=\"d-lg-none ms-2\">Discord</small>", "https://discord.gg/9vE5aHxcF9", "nav-link p-2 fs-5") }}
<i class="bi-discord"></i>
</a>
</li> </li>
</ul> </ul>
</div> </div>
@ -59,7 +61,7 @@
</nav> </nav>
</header> </header>
<main> <main>
<div class="container-fluid"> <div class="container-lg">
{% block content %} {% endblock %} {% block content %} {% endblock %}
</div> </div>
</main> </main>

View File

@ -0,0 +1,13 @@
<div class="breadcrumbs">
{% for node in schema.nodes_from_root %}
{% if loop.first %}
Root
{% else %}
<a href="#{{ node.html_id }}"
onclick="anchorLink('{{ node.html_id }}')">{{ node.name_for_breadcrumbs | upper_first }}</a>
{% endif %}
{% if not loop.last %}
<i class="bi-arrow-right-short"></i>
{% endif %}
{% endfor %}
</div>

View File

@ -52,7 +52,7 @@
{{ content(schema.kw_any_of.array_items[0]) }} {{ content(schema.kw_any_of.array_items[0]) }}
{% else %} {% else %}
{% if schema.explicit_no_additional_properties %} {% if schema.explicit_no_additional_properties %}
{{ " " }}<span class="badge badge-info no-additional">No Additional Properties</span> {{ " " }}<span class="badge bg-info no-additional">No Additional Properties</span>
{% endif %} {% endif %}
{# Combining: allOf, anyOf, oneOf, not #} {# Combining: allOf, anyOf, oneOf, not #}

View File

@ -0,0 +1,11 @@
{% macro external_link(display_name, link, class) %}
<a class="{{ class|default("") }}" target="_blank" rel="noopener" href="{{ link }}">{{ display_name|safe }}</a>
{% endmacro %}
{% macro is_active_page(title) %}{% if title == page.title %}active{% endif %}{% endmacro %}
{% macro nav_item(title, href) %}
<li class="nav-item">
<a href="{{ href }}" class="nav-link {% if title == page.title %}active{% endif %}" {% if title == page.title %}aria-current="page"{% endif %}>{{ title|title }}</a>
</li>
{% endmacro %}

View File

@ -0,0 +1,16 @@
{% extends "base/base.jinja2" %}
{% block resources %}
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/styles/github-dark-dimmed.min.css">
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
{% endblock %}
{% block content %}
<div class="row">
<div class="col">
{{ content|markdown }}
</div>
</div>
{% endblock %}

View File

@ -1,21 +1,21 @@
{%- if schema.kw_min_items -%} {% if schema.kw_min_items %}
{{ restriction("Must contain a minimum of <code>" ~ schema.kw_min_items.literal ~ "</code> items", "min-items", schema.kw_min_items.html_id) }} {{ restriction("Must contain a minimum of <code>" ~ schema.kw_min_items.literal ~ "</code> Items", "min-items", schema.kw_min_items.html_id) }}
{%- endif -%} {% endif %}
{%- if schema.kw_max_items -%} {% if schema.kw_max_items %}
{{ restriction("Must contain a maximum of <code>" ~ schema.kw_max_items.literal ~ "</code> items", "max-items", schema.kw_max_items.html_id) }} {{ restriction("Must contain a maximum of <code>" ~ schema.kw_max_items.literal ~ "</code> Items", "max-items", schema.kw_max_items.html_id) }}
{%- endif -%} {% endif %}
{%- if schema.kw_unique_items and schema.kw_unique_items.literal == True -%} {% if schema.kw_unique_items and schema.kw_unique_items.literal == True %}
{{ restriction("All items must be unique", "unique-items", schema.kw_unique_items.html_id) }} {{ restriction("All items must be unique", "unique-items", schema.kw_unique_items.html_id) }}
{%- endif -%} {% endif %}
{%- if schema.array_items_def -%} {% if schema.array_items_def %}
<h4>Each item of this array must be:</h4> <h4>Each item of this array must be:</h4>
<div class="card"> <div class="card">
<div class="card-body items-definition" id="{{ schema.array_items_def.html_id }}"> <div class="card-body items-definition" id="{{ schema.array_items_def.html_id }}">
{{ content(schema.array_items_def) }} {{ content(schema.array_items_def) }}
</div> </div>
</div> </div>
{%- endif -%} {% endif %}
{%- if schema.tuple_validation_items -%} {% if schema.tuple_validation_items %}
<h4>Tuple Validation</h4> <h4>Tuple Validation</h4>
{% for item in schema.tuple_validation_items %} {% for item in schema.tuple_validation_items %}
<h5>Item at {{ loop.index }} must be:</h5> <h5>Item at {{ loop.index }} must be:</h5>
@ -25,12 +25,12 @@
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{%- endif -%} {% endif %}
{%- if schema.kw_contains and schema.kw_contains.literal != {} -%} {% if schema.kw_contains and schema.kw_contains.literal != {} %}
<h4>At least one of the items must be:</h4> <h4>At least one of the items must be:</h4>
<div class="card"> <div class="card">
<div class="card-body items-contain-definition" id="{{ schema.kw_contains.html_id }}"> <div class="card-body items-contain-definition" id="{{ schema.kw_contains.html_id }}">
{{ content(schema.kw_contains) }} {{ content(schema.kw_contains) }}
</div> </div>
</div> </div>
{%- endif -%} {% endif %}

View File

@ -1,5 +1,5 @@
<h2 class="handle"> <h2 class="handle">
<label>Conditional Subschema</label> <label>Conditional Sub-schema</label>
</h2> </h2>
<p>If the conditions in the "If" tab are respected, then the conditions in the "Then" tab should be respected. <p>If the conditions in the "If" tab are respected, then the conditions in the "Then" tab should be respected.
Otherwise, the conditions in the "Else" tab should be respected.</p> Otherwise, the conditions in the "Else" tab should be respected.</p>

View File

@ -2,17 +2,17 @@
<div class="badge badge-secondary">Example{% if examples|length > 1 %}s{% endif %}:</div> <div class="badge badge-secondary">Example{% if examples|length > 1 %}s{% endif %}:</div>
<br/> <br/>
{%- for example in examples -%} {% for example in examples %}
{%- set example_id = schema.html_id ~ "_ex" ~ loop.index -%} {% set example_id = schema.html_id ~ "_ex" ~ loop.index %}
{%- set example_is_long = example is not description_short -%} {% set example_is_long = example is not description_short %}
{%- if example_is_long -%} {% if example_is_long %}
<button class="btn btn-light example-show collapsed" data-toggle="collapse" data-target="#{{ example_id }}" aria-controls="{{ example_id }}"></button> <button class="btn btn-light example-show collapsed" data-toggle="collapse" data-target="#{{ example_id }}" aria-controls="{{ example_id }}"></button>
{%- endif -%} {% endif %}
<div id="{{ example_id }}" class="{% if example_is_long %}collapse {% endif %}jumbotron examples"> <div id="{{ example_id }}" class="{% if example_is_long %}collapse {% endif %}jumbotron examples">
{%- if not examples_as_yaml -%} {% if not examples_as_yaml %}
{{ example | highlight_json_example }} {{ example | highlight_json_example }}
{%- else -%} {% else %}
{{ example | highlight_yaml_example }} {{ example | highlight_yaml_example }}
{%- endif -%} {% endif %}
</div> </div>
{%- endfor -%} {% endfor %}

View File

@ -13,7 +13,7 @@
{% if sub_property.is_additional_properties %} {% if sub_property.is_additional_properties %}
<em> <em>
{% endif %} {% endif %}
<span class="property-nam align-middle pb-1">{{ sub_property.property_display_name | lowerfirst | escape }}</span> <span class="property-nam align-middle pb-1">{{ sub_property.property_display_name | upper_first | escape }}</span>
{% if sub_property.is_additional_properties %} {% if sub_property.is_additional_properties %}
</em> </em>
{% endif %} {% endif %}

View File

@ -0,0 +1,11 @@
{% set undocumented_required_properties = schema | get_undocumented_required_properties %}
{% if undocumented_required_properties %}
<div class="enum-value">
<h4>The following properties are required:</h4>
<ul class="list-group">
{% for required_property in undocumented_required_properties %}
<li class="list-group-item required-property">{{ required_property }}</li>
{% endfor %}
</ul>
</div>
{% endif %}

View File

@ -1,25 +1,25 @@
<h2 class="handle"> <h2 class="handle">
<label>{% if operator == "allOf" -%}All of{% elif operator == "anyOf" -%}Any of{% elif operator == "oneOf" -%}One of{% endif -%}</label> <label>{% if operator == "allOf" %}All of{% elif operator == "anyOf" %}Any of{% elif operator == "oneOf" %}One of{% endif %}</label>
</h2> </h2>
{%- set tab_label = "Option" -%} {% set tab_label = "Option" %}
{%- if operator == "allOf" -%} {% if operator == "allOf" %}
{%- set tab_label = "Requirement" -%} {% set tab_label = "Requirement" %}
{%- endif -%} {% endif %}
<ul class="nav nav-tabs" id="tabs{{ current_node.html_id }}_{{ operator }}" role="tablist"> <ul class="nav nav-tabs" id="tabs{{ current_node.html_id }}_{{ operator }}" role="tablist">
{%- for node in current_node.array_items -%} {% for node in current_node.array_items %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {% if loop.index == 1 -%}active {% endif -%} {{ operator }}-option" <a class="nav-link {% if loop.index == 1 %}active {% endif %} {{ operator }}-option"
id="{{ node.html_id }}" data-toggle="tab" href="#tab-pane_{{ node.html_id }}" role="tab" id="{{ node.html_id }}" data-toggle="tab" href="#tab-pane_{{ node.html_id }}" role="tab"
onclick="setAnchor('#{{ node.html_id }}')" onclick="setAnchor('#{{ node.html_id }}')"
>{{ node.definition_name or tab_label ~ " " ~ loop.index }}</a> >{{ node.definition_name or tab_label ~ " " ~ loop.index }}</a>
</li> </li>
{%- endfor -%} {% endfor %}
</ul> </ul>
<div class="tab-content card"> <div class="tab-content card">
{%- for node in current_node.array_items -%} {% for node in current_node.array_items %}
<div class="tab-pane fade card-body {% if loop.index == 1 -%}active show{% endif -%}" <div class="tab-pane fade card-body {% if loop.index == 1 %}active show{% endif %}"
id="tab-pane_{{ node.html_id }}" role="tabpanel"> id="tab-pane_{{ node.html_id }}" role="tabpanel">
{{ content(node) }} {{ content(node) }}
</div> </div>
{%- endfor -%} {% endfor %}
</div> </div>

View File

@ -0,0 +1,21 @@
Title: Home
Out-File: index
Sort-Priority: 100
![New Horizons Logo]({{ 'images/home/home_logo.png'|static }})
# Welcome!
This is the official documentation for [New Horizons](https://github.com/xen-42/outer-wilds-new-horizons)
## Getting Started
There is a template [here](https://github.com/xen-42/ow-new-horizons-config-template) if you want to release your own planet mod using configs. You can learn how the configs work by picking apart the [Real Solar System](https://github.com/xen-42/outer-wilds-real-solar-system) mod or the [New Horizons Examples](https://github.com/xen-42/ow-new-horizons-examples) mod.
Planets are created using a JSON file format structure, and placed in a folder called planets (or in any subdirectory of it) in the location where New Horizons is installed (by default this folder doesn't exist, you have to create it within the xen.NewHorizons directory).
To locate this directory, click the "⋮" symbol next to "New Horizons" in the Outer Wilds Mod Manager and then click "show in explorer" in the pop-up.
![Click the three dots in the mod manager]({{ 'images/home/mod_manager_dots.png'|static }})
![Create a new folder named "planets"]({{ 'images/home/create_planets.png'|static }})

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 558 KiB

After

Width:  |  Height:  |  Size: 558 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -1,17 +0,0 @@
<div class="breadcrumbs">
{%- for node in schema.nodes_from_root -%}
{%- if loop.first -%}
root
{%- else -%}
<a href="#{{ node.html_id }}" onclick="anchorLink('{{ node.html_id }}')">{{ node.name_for_breadcrumbs | lowerfirst }}</a>
{%- endif -%}
{%- if not loop.last %}
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-arrow-right-short" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path
fill-rule="evenodd"
d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"
/>
</svg>
{% endif -%}
{%- endfor -%}
</div>

View File

@ -1,46 +0,0 @@
{% extends "base.jinja2" %}
{% block content %}
<div class="row mb-3">
<div class="col text-center">
<img class="img-fluid" src="/images/home/home_logo.png" alt="New Horizons Logo"/>
</div>
</div>
<div class="row">
<div class="col">
<h1>Welcome!</h1>
</div>
</div>
<div class="row">
<div class="col">
<p>This is the official documentation for <a target="_blank" rel="noopener" href="https://github.com/xen-42/outer-wilds-new-horizons">New Horizons</a></p>
</div>
</div>
<div class="row">
<div class="col">
<h2>Getting Started</h2>
</div>
</div>
<div class="row">
<div class="col">
<p>There is a template <a href="https://github.com/xen-42/ow-new-horizons-config-template" rel="noopener" target="_blank">here</a> if you want to release your own planet mod using configs. You can learn how the configs work by picking apart the <a href="https://github.com/xen-42/outer-wilds-real-solar-system" rel="noopener" target="_blank">Real Solar System</a> mod or the <a href="https://github.com/xen-42/ow-new-horizons-examples" rel="noopener" target="_blank">New Horizons Examples mod</a>.</p>
<p>Planets are created using a JSON file format structure, and placed in a folder called planets (or in any sub-directory of it) in the location where New Horizons is installed (by default this folder doesn't exist, you have to create it within the xen.NewHorizons directory).</p>
<p>To locate this directory, click the "⋮" symbol next to "New Horizons" in the Outer Wilds Mod Manager and then click "show in explorer" in the pop-up.</p>
</div>
</div>
<div class="row">
<div class="col">
<figure class="figure">
<img src="/images/home/mod_manager_dots.png" class="figure-img img-fluid rounded" alt="Click the three dots in the mod manager">
<figcaption class="figure-caption text-end">Click the ⋮</figcaption>
</figure>
</div>
<div class="col">
<figure class="figure">
<img src="/images/home/create_planets.png" class="figure-img img-fluid rounded" alt="Create a new folder named &quot;planets&quot;">
<figcaption class="figure-caption text-end">Create a new folder named "planets"</figcaption>
</figure>
</div>
</div>
{% endblock %}

View File

@ -1,11 +0,0 @@
{%- set undocumented_required_properties = schema | get_undocumented_required_properties -%}
{%- if undocumented_required_properties-%}
<div class="enum-value">
<h4>The following properties are required:</h4>
<ul class="list-group">
{%- for required_property in undocumented_required_properties -%}
<li class="list-group-item required-property">{{ required_property }}</li>
{%- endfor -%}
</ul>
</div>
{%- endif -%}

View File

@ -1,88 +1,62 @@
import os import os
from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from shutil import copytree, rmtree
from jinja2 import Environment, PackageLoader, select_autoescape from jinja2 import Environment, select_autoescape, FileSystemLoader
from json_schema_for_humans.schema.schema_importer import get_schemas_to_render from markupsafe import Markup
from json_schema_for_humans.generate import generate_from_filename, GenerationConfiguration, generate_schemas_doc, \ from json_schema_for_humans.generate import GenerationConfiguration
copy_additional_files_to_target from markdown import Markdown
from json_schema_for_humans.template_renderer import TemplateRenderer, _minify
from lib.Schema import Schema
from lib.Page import Page
OUT_DIR = os.getenv("OUT_DIR", "/")
env = Environment( env = Environment(
loader=PackageLoader('docs_templates', 'templates'), loader=FileSystemLoader("content"),
autoescape=select_autoescape(['jinja2']) autoescape=select_autoescape(['jinja2'])
) )
env.filters["lowerfirst"] = lambda x: x[0].lower() + x[1:] markdown_settings = {
'extensions': ['extra', 'meta']
}
home = env.get_template("base.jinja2") schema_settings = GenerationConfiguration(custom_template_path="content/base/schema_base.jinja2")
schema_settings.link_to_reused_ref = False
md = Markdown(**markdown_settings)
@dataclass env.filters["upper_first"] = lambda x: x[0].upper() + x[1:]
class Page: env.filters["markdown"] = lambda text: Markup(md.convert(text))
in_name: str env.filters["static"] = lambda path: OUT_DIR + "/" + path
out_name: str
title: str
def render(self, **options): pages_paths = Path("content/pages").glob("**/*.md")
template = env.get_template(self.in_name + ".jinja2") schemas_paths = Path("content/schemas").glob("**/*.json")
options.update({'page': self})
rendered_string = template.render(**options)
with open("out/" + self.out_name + ".html", 'w+', encoding="utf-8") as file:
file.write(rendered_string)
router = {}
config = GenerationConfiguration(custom_template_path="docs_templates/templates/schema_base.jinja2") env.filters['route'] = lambda title: router.get(title.lower(), "#")
config.link_to_reused_ref = False
pages = []
schemas = []
@dataclass for page_path in pages_paths:
class Schema(Page): new_page = Page(page_path, env, markdown_settings)
router[new_page.title.lower()] = OUT_DIR + str(new_page.out_path.relative_to('out/'))
pages.append(new_page)
def render(self, **options): for schema_path in schemas_paths:
schemas = get_schemas_to_render("schemas/" + self.in_name + ".json", Path("out/schemas/" + self.out_name + ".html"), ".html") new_schema = Schema(schema_path, env, schema_settings)
template_renderer = TemplateRenderer(config) router[new_schema.title.lower()] = OUT_DIR + "schemas/" + str(new_schema.out_path.relative_to("out/schemas/"))
template_renderer.render = lambda inter: template_override(template_renderer, inter, self) schemas.append(new_schema)
generate_schemas_doc(schemas, template_renderer)
copy_additional_files_to_target(schemas, config)
router['home'] = OUT_DIR
pages = ( pages.sort(key=lambda p: p.sort_priority, reverse=True)
Page(in_name="home", out_name="index", title="Home"),
Schema(in_name="schema", out_name="body_schema", title="Body"),
Schema(in_name="star_system_schema", out_name="star_system_schema", title="Star System"),
Schema(in_name="translation_schema", out_name="translation_schema", title="Translation")
)
schemas = [s for s in pages if s.__class__.__name__ == "Schema"]
def template_override(template, intermediate_schema, inter_page):
template.template.environment.filters["lowerfirst"] = env.filters["lowerfirst"]
rendered = template.template.render(schema=intermediate_schema, config=config, schemas=schemas, page=inter_page, title=inter_page.title + " Schema")
if template.config.minify:
rendered = _minify(rendered, template.config.template_is_markdown, template.config.template_is_html)
return rendered
print("Initializing")
if os.path.exists("out"):
rmtree("out")
print("Copying Static")
copytree("static", "out")
os.makedirs("out/schemas")
print("Rendering Pages")
for page in pages: for page in pages:
page.render(schemas=schemas) print(page.in_path, "->", page.out_path)
page.render(page=page, pages=pages, schemas=schemas)
print("Done") for schema in schemas:
print(schema.in_path, "->", schema.out_path)
schema.render(page=schema, pages=pages, schemas=schemas)

40
docs/lib/Page.py Normal file
View File

@ -0,0 +1,40 @@
from dataclasses import dataclass
from pathlib import Path
from jinja2 import Environment
from markdown import Markdown
@dataclass
class Page:
sort_priority: int
in_path: Path
out_path: Path
title: str
env: Environment
def __init__(self, path, environment, options):
self.in_path = path
self.env = environment
md = Markdown(**options)
with path.open() as file:
md.convert(file.read())
self.sort_priority = int(md.Meta.get('sort-priority', '0')[0])
self.title = md.Meta.get('title', (path.stem,))[0]
outfile: Path
try:
outfile = Path("out/", path.relative_to(Path("content/pages/")).parent,
md.Meta['out-file'][0] + '.html')
except KeyError:
outfile = Path("out/", path.relative_to(Path("content/pages/"))).with_suffix('.html')
self.out_path = outfile
def render(self, **options):
template = self.env.get_template(str(self.in_path.relative_to(Path("content/")).as_posix()))
page_template = self.env.get_template("base/page_template.jinja2")
rendered_string = page_template.render(content=template.render(**options), **options)
self.out_path.parent.mkdir(mode=511, parents=True, exist_ok=True)
with self.out_path.open(mode='w+', encoding='utf-8') as file:
file.write(rendered_string)

42
docs/lib/Schema.py Normal file
View File

@ -0,0 +1,42 @@
import json
from dataclasses import dataclass
from pathlib import Path
from json_schema_for_humans.generate import generate_schemas_doc, copy_additional_files_to_target
from json_schema_for_humans.schema.schema_importer import get_schemas_to_render
from json_schema_for_humans.template_renderer import TemplateRenderer, _minify
from json_schema_for_humans.generation_configuration import GenerationConfiguration
# noinspection PyUnresolvedReferences
from lib.Page import Page
@dataclass
class Schema(Page):
config: GenerationConfiguration
def __init__(self, path, env, options):
self.sort_priority = 0
self.in_path = path
self.config = options
self.env = env
with path.open() as file:
self.title = json.load(file).get('title', path.stem)
self.out_path = Path('out/schemas/', self.in_path.relative_to(Path("content/schemas/")).with_name(self.title.replace(" ", "_").lower()).with_suffix(".html"))
def render(self, **options):
schemas = get_schemas_to_render(self.in_path, self.out_path, ".html")
template_renderer = TemplateRenderer(self.config)
template_renderer.render = lambda inter: self.template_override(template_renderer, inter, **options)
generate_schemas_doc(schemas, template_renderer)
copy_additional_files_to_target(schemas, self.config)
def template_override(self, template, intermediate_schema, **options):
template.template.environment.filters.update(self.env.filters)
rendered = template.template.render(schema=intermediate_schema, dumb=True, config=self.config, title=self.title + " Schema", **options)
if template.config.minify:
rendered = _minify(rendered, template.config.template_is_markdown, template.config.template_is_html)
return rendered