mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Redid Docs Generation
This commit is contained in:
parent
be71162d24
commit
290a7d54c9
@ -70,8 +70,8 @@
|
||||
"angle": {
|
||||
"type": "number",
|
||||
"default": 0,
|
||||
"min": 0,
|
||||
"max": 360
|
||||
"minimum": 0,
|
||||
"maximum": 360
|
||||
},
|
||||
"curve": {
|
||||
"type": "array",
|
||||
@ -104,7 +104,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"title": "Planet",
|
||||
"title": "Body",
|
||||
"description": "A planet or body to generate",
|
||||
"type": "object",
|
||||
"required": [
|
||||
@ -627,7 +627,7 @@
|
||||
"shipSpawnPoint": {
|
||||
"$ref": "#/$defs/vector3"
|
||||
},
|
||||
"starWithSuit": {
|
||||
"startWithSuit": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"title": "Star System",
|
||||
"description": "Configuration for a specific star system",
|
||||
"properties": {
|
||||
"canEnterViaWarpDrive": {
|
||||
|
||||
@ -6,6 +6,7 @@ name = "pypi"
|
||||
[packages]
|
||||
jinja2 = "*"
|
||||
json-schema-for-humans = "*"
|
||||
markdown = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
||||
10
docs/Pipfile.lock
generated
10
docs/Pipfile.lock
generated
@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "b4acdc18f2bf25fdf7a2448229884300b7e3ec47731a49ad482b21d32c627370"
|
||||
"sha256": "600dddfc39d9e9ca825fd1870bfa2094e3124c7d1759be513936f1d0d842cd5c"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
@ -85,6 +85,14 @@
|
||||
"index": "pypi",
|
||||
"version": "==0.40"
|
||||
},
|
||||
"markdown": {
|
||||
"hashes": [
|
||||
"sha256:76df8ae32294ec39dcf89340382882dfa12975f87f45c3ed1ecdb1e8cefc7006",
|
||||
"sha256:9923332318f843411e9932237530df53162e29dc7a4e2b91e35764583c46c9a3"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.3.6"
|
||||
},
|
||||
"markdown2": {
|
||||
"hashes": [
|
||||
"sha256:8f4ac8d9a124ab408c67361090ed512deda746c04362c36c2ec16190c720c2b0",
|
||||
|
||||
@ -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>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@ -18,7 +24,7 @@
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-2">
|
||||
<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"
|
||||
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
@ -26,32 +32,28 @@
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="/">Home</a>
|
||||
</li>
|
||||
{% for nav_page in pages %}
|
||||
{{ nav_item(nav_page.title|title, nav_page.title|route) }}
|
||||
{% endfor %}
|
||||
<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">
|
||||
Schemas
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
{% for schema in schemas %}
|
||||
<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 %}
|
||||
</ul>
|
||||
</li>
|
||||
</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">
|
||||
<a class="link-light" href="https://github.com/xen-42/outer-wilds-new-horizons">
|
||||
<i class="bi-github"></i>
|
||||
</a>
|
||||
{{ 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") }}
|
||||
</li>
|
||||
<li class="nav-item me-2">
|
||||
<a class="link-light" href="https://github.com/xen-42/outer-wilds-new-horizons">
|
||||
<i class="bi-discord"></i>
|
||||
</a>
|
||||
{{ 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") }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -59,7 +61,7 @@
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
<div class="container-fluid">
|
||||
<div class="container-lg">
|
||||
{% block content %} {% endblock %}
|
||||
</div>
|
||||
</main>
|
||||
13
docs/content/base/breadcrumbs.jinja2
Normal file
13
docs/content/base/breadcrumbs.jinja2
Normal 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>
|
||||
@ -52,7 +52,7 @@
|
||||
{{ content(schema.kw_any_of.array_items[0]) }}
|
||||
{% else %}
|
||||
{% 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 %}
|
||||
|
||||
{# Combining: allOf, anyOf, oneOf, not #}
|
||||
11
docs/content/base/macros.jinja2
Normal file
11
docs/content/base/macros.jinja2
Normal 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 %}
|
||||
16
docs/content/base/page_template.jinja2
Normal file
16
docs/content/base/page_template.jinja2
Normal 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 %}
|
||||
@ -1,21 +1,21 @@
|
||||
{%- 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) }}
|
||||
{%- endif -%}
|
||||
{%- 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) }}
|
||||
{%- endif -%}
|
||||
{%- if schema.kw_unique_items and schema.kw_unique_items.literal == True -%}
|
||||
{% 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) }}
|
||||
{% endif %}
|
||||
{% 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) }}
|
||||
{% endif %}
|
||||
{% 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) }}
|
||||
{%- endif -%}
|
||||
{%- if schema.array_items_def -%}
|
||||
{% endif %}
|
||||
{% if schema.array_items_def %}
|
||||
<h4>Each item of this array must be:</h4>
|
||||
<div class="card">
|
||||
<div class="card-body items-definition" id="{{ schema.array_items_def.html_id }}">
|
||||
{{ content(schema.array_items_def) }}
|
||||
</div>
|
||||
</div>
|
||||
{%- endif -%}
|
||||
{%- if schema.tuple_validation_items -%}
|
||||
{% endif %}
|
||||
{% if schema.tuple_validation_items %}
|
||||
<h4>Tuple Validation</h4>
|
||||
{% for item in schema.tuple_validation_items %}
|
||||
<h5>Item at {{ loop.index }} must be:</h5>
|
||||
@ -25,12 +25,12 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{%- endif -%}
|
||||
{%- if schema.kw_contains and schema.kw_contains.literal != {} -%}
|
||||
{% endif %}
|
||||
{% if schema.kw_contains and schema.kw_contains.literal != {} %}
|
||||
<h4>At least one of the items must be:</h4>
|
||||
<div class="card">
|
||||
<div class="card-body items-contain-definition" id="{{ schema.kw_contains.html_id }}">
|
||||
{{ content(schema.kw_contains) }}
|
||||
</div>
|
||||
</div>
|
||||
{%- endif -%}
|
||||
{% endif %}
|
||||
@ -1,5 +1,5 @@
|
||||
<h2 class="handle">
|
||||
<label>Conditional Subschema</label>
|
||||
<label>Conditional Sub-schema</label>
|
||||
</h2>
|
||||
<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>
|
||||
@ -2,17 +2,17 @@
|
||||
<div class="badge badge-secondary">Example{% if examples|length > 1 %}s{% endif %}:</div>
|
||||
<br/>
|
||||
|
||||
{%- for example in examples -%}
|
||||
{%- set example_id = schema.html_id ~ "_ex" ~ loop.index -%}
|
||||
{%- set example_is_long = example is not description_short -%}
|
||||
{%- if example_is_long -%}
|
||||
{% for example in examples %}
|
||||
{% set example_id = schema.html_id ~ "_ex" ~ loop.index %}
|
||||
{% set example_is_long = example is not description_short %}
|
||||
{% if example_is_long %}
|
||||
<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">
|
||||
{%- if not examples_as_yaml -%}
|
||||
{% if not examples_as_yaml %}
|
||||
{{ example | highlight_json_example }}
|
||||
{%- else -%}
|
||||
{% else %}
|
||||
{{ example | highlight_yaml_example }}
|
||||
{%- endif -%}
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- endfor -%}
|
||||
{% endfor %}
|
||||
@ -13,7 +13,7 @@
|
||||
{% if sub_property.is_additional_properties %}
|
||||
<em>
|
||||
{% 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 %}
|
||||
</em>
|
||||
{% endif %}
|
||||
@ -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 %}
|
||||
@ -1,25 +1,25 @@
|
||||
<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>
|
||||
{%- set tab_label = "Option" -%}
|
||||
{%- if operator == "allOf" -%}
|
||||
{%- set tab_label = "Requirement" -%}
|
||||
{%- endif -%}
|
||||
{% set tab_label = "Option" %}
|
||||
{% if operator == "allOf" %}
|
||||
{% set tab_label = "Requirement" %}
|
||||
{% endif %}
|
||||
<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">
|
||||
<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"
|
||||
onclick="setAnchor('#{{ node.html_id }}')"
|
||||
>{{ node.definition_name or tab_label ~ " " ~ loop.index }}</a>
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="tab-content card">
|
||||
{%- for node in current_node.array_items -%}
|
||||
<div class="tab-pane fade card-body {% if loop.index == 1 -%}active show{% endif -%}"
|
||||
{% for node in current_node.array_items %}
|
||||
<div class="tab-pane fade card-body {% if loop.index == 1 %}active show{% endif %}"
|
||||
id="tab-pane_{{ node.html_id }}" role="tabpanel">
|
||||
{{ content(node) }}
|
||||
</div>
|
||||
{%- endfor -%}
|
||||
{% endfor %}
|
||||
</div>
|
||||
21
docs/content/pages/home.md
Normal file
21
docs/content/pages/home.md
Normal file
@ -0,0 +1,21 @@
|
||||
Title: Home
|
||||
Out-File: index
|
||||
Sort-Priority: 100
|
||||
|
||||

|
||||
|
||||
# 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.
|
||||
|
||||

|
||||
|
||||

|
||||
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 558 KiB After Width: | Height: | Size: 558 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
@ -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>
|
||||
@ -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 "planets"">
|
||||
<figcaption class="figure-caption text-end">Create a new folder named "planets"</figcaption>
|
||||
</figure>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@ -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 -%}
|
||||
106
docs/generate.py
106
docs/generate.py
@ -1,88 +1,62 @@
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from shutil import copytree, rmtree
|
||||
|
||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||
from json_schema_for_humans.schema.schema_importer import get_schemas_to_render
|
||||
from json_schema_for_humans.generate import generate_from_filename, GenerationConfiguration, generate_schemas_doc, \
|
||||
copy_additional_files_to_target
|
||||
from json_schema_for_humans.template_renderer import TemplateRenderer, _minify
|
||||
from jinja2 import Environment, select_autoescape, FileSystemLoader
|
||||
from markupsafe import Markup
|
||||
from json_schema_for_humans.generate import GenerationConfiguration
|
||||
from markdown import Markdown
|
||||
|
||||
from lib.Schema import Schema
|
||||
from lib.Page import Page
|
||||
|
||||
OUT_DIR = os.getenv("OUT_DIR", "/")
|
||||
|
||||
env = Environment(
|
||||
loader=PackageLoader('docs_templates', 'templates'),
|
||||
loader=FileSystemLoader("content"),
|
||||
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
|
||||
class Page:
|
||||
in_name: str
|
||||
out_name: str
|
||||
title: str
|
||||
env.filters["upper_first"] = lambda x: x[0].upper() + x[1:]
|
||||
env.filters["markdown"] = lambda text: Markup(md.convert(text))
|
||||
env.filters["static"] = lambda path: OUT_DIR + "/" + path
|
||||
|
||||
def render(self, **options):
|
||||
template = env.get_template(self.in_name + ".jinja2")
|
||||
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)
|
||||
pages_paths = Path("content/pages").glob("**/*.md")
|
||||
schemas_paths = Path("content/schemas").glob("**/*.json")
|
||||
|
||||
router = {}
|
||||
|
||||
config = GenerationConfiguration(custom_template_path="docs_templates/templates/schema_base.jinja2")
|
||||
config.link_to_reused_ref = False
|
||||
env.filters['route'] = lambda title: router.get(title.lower(), "#")
|
||||
|
||||
pages = []
|
||||
schemas = []
|
||||
|
||||
@dataclass
|
||||
class Schema(Page):
|
||||
for page_path in pages_paths:
|
||||
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):
|
||||
schemas = get_schemas_to_render("schemas/" + self.in_name + ".json", Path("out/schemas/" + self.out_name + ".html"), ".html")
|
||||
template_renderer = TemplateRenderer(config)
|
||||
template_renderer.render = lambda inter: template_override(template_renderer, inter, self)
|
||||
generate_schemas_doc(schemas, template_renderer)
|
||||
copy_additional_files_to_target(schemas, config)
|
||||
for schema_path in schemas_paths:
|
||||
new_schema = Schema(schema_path, env, schema_settings)
|
||||
router[new_schema.title.lower()] = OUT_DIR + "schemas/" + str(new_schema.out_path.relative_to("out/schemas/"))
|
||||
schemas.append(new_schema)
|
||||
|
||||
router['home'] = OUT_DIR
|
||||
|
||||
pages = (
|
||||
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")
|
||||
pages.sort(key=lambda p: p.sort_priority, reverse=True)
|
||||
|
||||
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
40
docs/lib/Page.py
Normal 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
42
docs/lib/Schema.py
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user