From 12519fdce51401ea34b31bdbcac72fe6af538d7f Mon Sep 17 00:00:00 2001 From: Ben C Date: Tue, 1 Mar 2022 19:38:54 -0800 Subject: [PATCH 1/3] Add Action --- .github/workflows/main.yml | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..59816a49 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,48 @@ +name: Build Docs + +on: + push: + branches: [ master ] + paths: + - docs/ + - NewHorizons/*schema*.json + + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - run: cp -r docs/** . + + - name: Install dependecies + uses: VaultVulp/action-pipenv@v2.0.1 + with: + command: install + + - name: Copy Schemas + run: | + mkdir schemas/ + cp NewHorizons/schema.json schemas/ + cp NewHorizons/star_system_schema.json schemas/ + cp NewHorizons/translation_schema.json schemas/ + + - name: Create Output Dir + run: | + mkdir out/ + mkdir out/schemas/ + + - name: Build Site + uses: VaultVulp/action-pipenv@v2.0.1 + with: + command: run python generate.py + + - name: Deploy To Pages + uses: JamesIves/github-pages-deploy-action@4.1.5 + with: + branch: gh-pages + folder: out/ + From b691b71b22af9b3edc1446e5c0f557600a790b49 Mon Sep 17 00:00:00 2001 From: Ben C Date: Tue, 1 Mar 2022 22:43:06 -0500 Subject: [PATCH 2/3] Remove BOM On Schemas --- NewHorizons/schema.json | 2 +- NewHorizons/star_system_schema.json | 2 +- NewHorizons/translation_schema.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index 8eb576f5..e12179d6 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -1,4 +1,4 @@ -{ +{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$defs": { "vector3": { diff --git a/NewHorizons/star_system_schema.json b/NewHorizons/star_system_schema.json index 0948e660..cf7f702c 100644 --- a/NewHorizons/star_system_schema.json +++ b/NewHorizons/star_system_schema.json @@ -1,4 +1,4 @@ -{ +{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "description": "Configuration for a specific star system", diff --git a/NewHorizons/translation_schema.json b/NewHorizons/translation_schema.json index 720a7a5e..3576a0ee 100644 --- a/NewHorizons/translation_schema.json +++ b/NewHorizons/translation_schema.json @@ -1,4 +1,4 @@ -{ +{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$defs": { "table": { From 08ad3a176a6ef11dfb64a60d9046f8cef3acdd77 Mon Sep 17 00:00:00 2001 From: Ben C Date: Tue, 1 Mar 2022 22:46:02 -0500 Subject: [PATCH 3/3] Added Builder --- NewHorizons.sln.DotSettings | 2 + docs/Pipfile | 13 + docs/Pipfile.lock | 252 ++++++++++++++++++ docs/docs_templates/__init__.py | 0 docs/docs_templates/templates/badge_type.html | 14 + docs/docs_templates/templates/base.jinja2 | 50 ++++ .../docs_templates/templates/breadcrumbs.html | 17 ++ docs/docs_templates/templates/content.html | 121 +++++++++ docs/docs_templates/templates/home.jinja2 | 15 ++ .../templates/macro_restriction.html | 3 + .../templates/schema_base.jinja2 | 15 ++ .../templates/schema_doc.min.js | 1 + .../templates/section_array.html | 36 +++ .../section_conditional_subschema.html | 58 ++++ .../templates/section_description.html | 20 ++ .../templates/section_examples.html | 18 ++ .../docs_templates/templates/section_not.html | 8 + .../templates/section_properties.html | 62 +++++ ...tion_undocumented_required_properties.html | 11 + .../templates/tabbed_section.html | 25 ++ docs/generate.py | 72 +++++ 21 files changed, 813 insertions(+) create mode 100644 NewHorizons.sln.DotSettings create mode 100644 docs/Pipfile create mode 100644 docs/Pipfile.lock create mode 100644 docs/docs_templates/__init__.py create mode 100644 docs/docs_templates/templates/badge_type.html create mode 100644 docs/docs_templates/templates/base.jinja2 create mode 100644 docs/docs_templates/templates/breadcrumbs.html create mode 100644 docs/docs_templates/templates/content.html create mode 100644 docs/docs_templates/templates/home.jinja2 create mode 100644 docs/docs_templates/templates/macro_restriction.html create mode 100644 docs/docs_templates/templates/schema_base.jinja2 create mode 100644 docs/docs_templates/templates/schema_doc.min.js create mode 100644 docs/docs_templates/templates/section_array.html create mode 100644 docs/docs_templates/templates/section_conditional_subschema.html create mode 100644 docs/docs_templates/templates/section_description.html create mode 100644 docs/docs_templates/templates/section_examples.html create mode 100644 docs/docs_templates/templates/section_not.html create mode 100644 docs/docs_templates/templates/section_properties.html create mode 100644 docs/docs_templates/templates/section_undocumented_required_properties.html create mode 100644 docs/docs_templates/templates/tabbed_section.html create mode 100644 docs/generate.py diff --git a/NewHorizons.sln.DotSettings b/NewHorizons.sln.DotSettings new file mode 100644 index 00000000..c5c5cc6c --- /dev/null +++ b/NewHorizons.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/docs/Pipfile b/docs/Pipfile new file mode 100644 index 00000000..d3679cdd --- /dev/null +++ b/docs/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +jinja2 = "*" +json-schema-for-humans = "*" + +[dev-packages] + +[requires] +python_version = "3.10" diff --git a/docs/Pipfile.lock b/docs/Pipfile.lock new file mode 100644 index 00000000..5f5f7055 --- /dev/null +++ b/docs/Pipfile.lock @@ -0,0 +1,252 @@ +{ + "_meta": { + "hash": { + "sha256": "b4acdc18f2bf25fdf7a2448229884300b7e3ec47731a49ad482b21d32c627370" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.10" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "certifi": { + "hashes": [ + "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872", + "sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569" + ], + "version": "==2021.10.8" + }, + "charset-normalizer": { + "hashes": [ + "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597", + "sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df" + ], + "markers": "python_version >= '3'", + "version": "==2.0.12" + }, + "click": { + "hashes": [ + "sha256:6a7a62563bbfabfda3a38f3023a1db4a35978c0abd76f6c9605ecd6554d6d9b1", + "sha256:8458d7b1287c5fb128c90e23381cf99dcde74beaf6c7ff6384ce84d6fe090adb" + ], + "markers": "python_version >= '3.6'", + "version": "==8.0.4" + }, + "colorama": { + "hashes": [ + "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b", + "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2" + ], + "markers": "platform_system == 'Windows'", + "version": "==0.4.4" + }, + "dataclasses-json": { + "hashes": [ + "sha256:1d7f3a284a49d350ddbabde0e7d0c5ffa34a144aaf1bcb5b9f2c87673ff0c76e", + "sha256:1f60be3405dee30b86ffbf6a436db8ba5efaeeb676bfda358e516a97aa7dfce4" + ], + "markers": "python_version >= '3.6'", + "version": "==0.5.6" + }, + "htmlmin": { + "hashes": [ + "sha256:50c1ef4630374a5d723900096a961cff426dff46b48f34d194a81bbe14eca178" + ], + "version": "==0.1.12" + }, + "idna": { + "hashes": [ + "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff", + "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d" + ], + "markers": "python_version >= '3'", + "version": "==3.3" + }, + "jinja2": { + "hashes": [ + "sha256:077ce6014f7b40d03b47d1f1ca4b0fc8328a692bd284016f806ed0eaca390ad8", + "sha256:611bb273cd68f3b993fabdc4064fc858c5b47a973cb5aa7999ec1ba405c87cd7" + ], + "index": "pypi", + "version": "==3.0.3" + }, + "json-schema-for-humans": { + "hashes": [ + "sha256:2272e053e7b44961c79d22628eca9c475bd3984b99401a4184ae8f4224df296a", + "sha256:986158ae543d6aae5df6bb1dbc9e23f45a374fd7e9da5165ddcd9a7596b877e7" + ], + "index": "pypi", + "version": "==0.40" + }, + "markdown2": { + "hashes": [ + "sha256:8f4ac8d9a124ab408c67361090ed512deda746c04362c36c2ec16190c720c2b0", + "sha256:91113caf23aa662570fe21984f08fe74f814695c0a0ea8e863a8b4c4f63f9f6e" + ], + "markers": "python_version >= '3.5' and python_version < '4'", + "version": "==2.4.2" + }, + "markupsafe": { + "hashes": [ + "sha256:023af8c54fe63530545f70dd2a2a7eed18d07a9a77b94e8bf1e2ff7f252db9a3", + "sha256:09c86c9643cceb1d87ca08cdc30160d1b7ab49a8a21564868921959bd16441b8", + "sha256:142119fb14a1ef6d758912b25c4e803c3ff66920635c44078666fe7cc3f8f759", + "sha256:1d1fb9b2eec3c9714dd936860850300b51dbaa37404209c8d4cb66547884b7ed", + "sha256:204730fd5fe2fe3b1e9ccadb2bd18ba8712b111dcabce185af0b3b5285a7c989", + "sha256:24c3be29abb6b34052fd26fc7a8e0a49b1ee9d282e3665e8ad09a0a68faee5b3", + "sha256:290b02bab3c9e216da57c1d11d2ba73a9f73a614bbdcc027d299a60cdfabb11a", + "sha256:3028252424c72b2602a323f70fbf50aa80a5d3aa616ea6add4ba21ae9cc9da4c", + "sha256:30c653fde75a6e5eb814d2a0a89378f83d1d3f502ab710904ee585c38888816c", + "sha256:3cace1837bc84e63b3fd2dfce37f08f8c18aeb81ef5cf6bb9b51f625cb4e6cd8", + "sha256:4056f752015dfa9828dce3140dbadd543b555afb3252507348c493def166d454", + "sha256:454ffc1cbb75227d15667c09f164a0099159da0c1f3d2636aa648f12675491ad", + "sha256:598b65d74615c021423bd45c2bc5e9b59539c875a9bdb7e5f2a6b92dfcfc268d", + "sha256:599941da468f2cf22bf90a84f6e2a65524e87be2fce844f96f2dd9a6c9d1e635", + "sha256:5ddea4c352a488b5e1069069f2f501006b1a4362cb906bee9a193ef1245a7a61", + "sha256:62c0285e91414f5c8f621a17b69fc0088394ccdaa961ef469e833dbff64bd5ea", + "sha256:679cbb78914ab212c49c67ba2c7396dc599a8479de51b9a87b174700abd9ea49", + "sha256:6e104c0c2b4cd765b4e83909cde7ec61a1e313f8a75775897db321450e928cce", + "sha256:736895a020e31b428b3382a7887bfea96102c529530299f426bf2e636aacec9e", + "sha256:75bb36f134883fdbe13d8e63b8675f5f12b80bb6627f7714c7d6c5becf22719f", + "sha256:7d2f5d97fcbd004c03df8d8fe2b973fe2b14e7bfeb2cfa012eaa8759ce9a762f", + "sha256:80beaf63ddfbc64a0452b841d8036ca0611e049650e20afcb882f5d3c266d65f", + "sha256:84ad5e29bf8bab3ad70fd707d3c05524862bddc54dc040982b0dbcff36481de7", + "sha256:8da5924cb1f9064589767b0f3fc39d03e3d0fb5aa29e0cb21d43106519bd624a", + "sha256:961eb86e5be7d0973789f30ebcf6caab60b844203f4396ece27310295a6082c7", + "sha256:96de1932237abe0a13ba68b63e94113678c379dca45afa040a17b6e1ad7ed076", + "sha256:a0a0abef2ca47b33fb615b491ce31b055ef2430de52c5b3fb19a4042dbc5cadb", + "sha256:b2a5a856019d2833c56a3dcac1b80fe795c95f401818ea963594b345929dffa7", + "sha256:b8811d48078d1cf2a6863dafb896e68406c5f513048451cd2ded0473133473c7", + "sha256:c532d5ab79be0199fa2658e24a02fce8542df196e60665dd322409a03db6a52c", + "sha256:d3b64c65328cb4cd252c94f83e66e3d7acf8891e60ebf588d7b493a55a1dbf26", + "sha256:d4e702eea4a2903441f2735799d217f4ac1b55f7d8ad96ab7d4e25417cb0827c", + "sha256:d5653619b3eb5cbd35bfba3c12d575db2a74d15e0e1c08bf1db788069d410ce8", + "sha256:d66624f04de4af8bbf1c7f21cc06649c1c69a7f84109179add573ce35e46d448", + "sha256:e67ec74fada3841b8c5f4c4f197bea916025cb9aa3fe5abf7d52b655d042f956", + "sha256:e6f7f3f41faffaea6596da86ecc2389672fa949bd035251eab26dc6697451d05", + "sha256:f02cf7221d5cd915d7fa58ab64f7ee6dd0f6cddbb48683debf5d04ae9b1c2cc1", + "sha256:f0eddfcabd6936558ec020130f932d479930581171368fd728efcfb6ef0dd357", + "sha256:fabbe18087c3d33c5824cb145ffca52eccd053061df1d79d4b66dafa5ad2a5ea", + "sha256:fc3150f85e2dbcf99e65238c842d1cfe69d3e7649b19864c1cc043213d9cd730" + ], + "markers": "python_version >= '3.7'", + "version": "==2.1.0" + }, + "marshmallow": { + "hashes": [ + "sha256:04438610bc6dadbdddb22a4a55bcc7f6f8099e69580b2e67f5a681933a1f4400", + "sha256:4c05c1684e0e97fe779c62b91878f173b937fe097b356cd82f793464f5bc6138" + ], + "markers": "python_version >= '3.6'", + "version": "==3.14.1" + }, + "marshmallow-enum": { + "hashes": [ + "sha256:38e697e11f45a8e64b4a1e664000897c659b60aa57bfa18d44e226a9920b6e58", + "sha256:57161ab3dbfde4f57adeb12090f39592e992b9c86d206d02f6bd03ebec60f072" + ], + "version": "==1.5.1" + }, + "mypy-extensions": { + "hashes": [ + "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d", + "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8" + ], + "version": "==0.4.3" + }, + "pygments": { + "hashes": [ + "sha256:44238f1b60a76d78fc8ca0528ee429702aae011c265fe6a8dd8b63049ae41c65", + "sha256:4e426f72023d88d03b2fa258de560726ce890ff3b630f88c21cbb8b2503b8c6a" + ], + "markers": "python_version >= '3.5'", + "version": "==2.11.2" + }, + "pytz": { + "hashes": [ + "sha256:3672058bc3453457b622aab7a1c3bfd5ab0bdae451512f6cf25f64ed37f5b87c", + "sha256:acad2d8b20a1af07d4e4c9d2e9285c5ed9104354062f275f3fcd88dcef4f1326" + ], + "version": "==2021.3" + }, + "pyyaml": { + "hashes": [ + "sha256:0283c35a6a9fbf047493e3a0ce8d79ef5030852c51e9d911a27badfde0605293", + "sha256:055d937d65826939cb044fc8c9b08889e8c743fdc6a32b33e2390f66013e449b", + "sha256:07751360502caac1c067a8132d150cf3d61339af5691fe9e87803040dbc5db57", + "sha256:0b4624f379dab24d3725ffde76559cff63d9ec94e1736b556dacdfebe5ab6d4b", + "sha256:0ce82d761c532fe4ec3f87fc45688bdd3a4c1dc5e0b4a19814b9009a29baefd4", + "sha256:1e4747bc279b4f613a09eb64bba2ba602d8a6664c6ce6396a4d0cd413a50ce07", + "sha256:213c60cd50106436cc818accf5baa1aba61c0189ff610f64f4a3e8c6726218ba", + "sha256:231710d57adfd809ef5d34183b8ed1eeae3f76459c18fb4a0b373ad56bedcdd9", + "sha256:277a0ef2981ca40581a47093e9e2d13b3f1fbbeffae064c1d21bfceba2030287", + "sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513", + "sha256:40527857252b61eacd1d9af500c3337ba8deb8fc298940291486c465c8b46ec0", + "sha256:473f9edb243cb1935ab5a084eb238d842fb8f404ed2193a915d1784b5a6b5fc0", + "sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92", + "sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f", + "sha256:68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2", + "sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc", + "sha256:819b3830a1543db06c4d4b865e70ded25be52a2e0631ccd2f6a47a2822f2fd7c", + "sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86", + "sha256:98c4d36e99714e55cfbaaee6dd5badbc9a1ec339ebfc3b1f52e293aee6bb71a4", + "sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c", + "sha256:9fa600030013c4de8165339db93d182b9431076eb98eb40ee068700c9c813e34", + "sha256:a80a78046a72361de73f8f395f1f1e49f956c6be882eed58505a15f3e430962b", + "sha256:b3d267842bf12586ba6c734f89d1f5b871df0273157918b0ccefa29deb05c21c", + "sha256:b5b9eccad747aabaaffbc6064800670f0c297e52c12754eb1d976c57e4f74dcb", + "sha256:c5687b8d43cf58545ade1fe3e055f70eac7a5a1a0bf42824308d868289a95737", + "sha256:cba8c411ef271aa037d7357a2bc8f9ee8b58b9965831d9e51baf703280dc73d3", + "sha256:d15a181d1ecd0d4270dc32edb46f7cb7733c7c508857278d3d378d14d606db2d", + "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53", + "sha256:d4eccecf9adf6fbcc6861a38015c2a64f38b9d94838ac1810a9023a0609e1b78", + "sha256:d67d839ede4ed1b28a4e8909735fc992a923cdb84e618544973d7dfc71540803", + "sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a", + "sha256:e61ceaab6f49fb8bdfaa0f92c4b57bcfbea54c09277b1b4f7ac376bfb7a7c174", + "sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5" + ], + "markers": "python_version >= '3.6'", + "version": "==6.0" + }, + "requests": { + "hashes": [ + "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61", + "sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", + "version": "==2.27.1" + }, + "typing-extensions": { + "hashes": [ + "sha256:1a9462dcc3347a79b1f1c0271fbe79e844580bb598bafa1ed208b94da3cdcd42", + "sha256:21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2" + ], + "markers": "python_version >= '3.6'", + "version": "==4.1.1" + }, + "typing-inspect": { + "hashes": [ + "sha256:047d4097d9b17f46531bf6f014356111a1b6fb821a24fe7ac909853ca2a782aa", + "sha256:3cd7d4563e997719a710a3bfe7ffb544c6b72069b6812a02e9b414a8fa3aaa6b", + "sha256:b1f56c0783ef0f25fb064a01be6e5407e54cf4a4bf4f3ba3fe51e0bd6dcea9e5" + ], + "version": "==0.7.1" + }, + "urllib3": { + "hashes": [ + "sha256:000ca7f471a233c2251c6c7023ee85305721bfdf18621ebff4fd17a8653427ed", + "sha256:0e7c33d9a63e7ddfcb86780aac87befc2fbddf46c58dbb487e0855f7ceec283c" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", + "version": "==1.26.8" + } + }, + "develop": {} +} diff --git a/docs/docs_templates/__init__.py b/docs/docs_templates/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/docs/docs_templates/templates/badge_type.html b/docs/docs_templates/templates/badge_type.html new file mode 100644 index 00000000..c34be479 --- /dev/null +++ b/docs/docs_templates/templates/badge_type.html @@ -0,0 +1,14 @@ +{% if type_name == "string" %} + {% if schema.kw_min_length %} + {{ restriction("Must be at least " ~ schema.kw_min_length.literal ~ " characters long", "min-length", schema.kw_min_length.html_id) }} + {% endif %} + {% if schema.kw_max_length %} + {{ restriction("Must be at most " ~ schema.kw_max_length.literal ~ " characters long", "max-length", schema.kw_max_length.html_id) }} + {% endif %} +{% endif %} +{% if type_name in ["integer", "number"] %} + {% set restriction_text = (schema | get_numeric_restrictions_text("", "")) %} + {% if restriction_text %} + {{ restriction(schema | get_numeric_restrictions_text("", ""), "numeric", schema.html_id ~ "_number") }} + {% endif %} +{% endif %} diff --git a/docs/docs_templates/templates/base.jinja2 b/docs/docs_templates/templates/base.jinja2 new file mode 100644 index 00000000..08244152 --- /dev/null +++ b/docs/docs_templates/templates/base.jinja2 @@ -0,0 +1,50 @@ + + + + + New Horizons Documentation | {{ page.title|title }} + + + + +
+ +
+
+ {% block content %} {% endblock %} +
+
+
+ + \ No newline at end of file diff --git a/docs/docs_templates/templates/breadcrumbs.html b/docs/docs_templates/templates/breadcrumbs.html new file mode 100644 index 00000000..1f3e65e9 --- /dev/null +++ b/docs/docs_templates/templates/breadcrumbs.html @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/docs/docs_templates/templates/content.html b/docs/docs_templates/templates/content.html new file mode 100644 index 00000000..f7734128 --- /dev/null +++ b/docs/docs_templates/templates/content.html @@ -0,0 +1,121 @@ +{% from "macro_restriction.html" import restriction with context %} + +{% macro tabbed_section(operator, current_node) %} + {% include "tabbed_section.html" %} +{% endmacro %} + +{% macro content(schema, skip_headers=False) %} + {% set keys = schema.keywords %} + + {# Resolve type #} + {% set type_name = schema.type_name %} + + {% if not skip_headers %} + {% if config.show_breadcrumbs %} + {% include "breadcrumbs.html" %} + {% endif %} + + {# Display type #} + {% if not schema is combining %} +
+
+ Type: {{ type_name }} +
+
+ {% endif %} + + {# Display default #} + {% set default_value = schema.default_value %} + {% if default_value %} +
+
+ {{ " " }}Default: {{ default_value }} +
+
+ {% endif %} +
+ + {% set description = (schema | get_description) %} + {% include "section_description.html" %} + {% endif %} + + + {% if schema.should_be_a_link(config) %} + Same definition as {{ schema.links_to.link_name }} + {% elif schema.refers_to %} + {{ content(schema.refers_to_merged, True) }} + {% else %} + {# Handle having oneOf or allOf with only one condition #} + {% if schema.kw_all_of and (schema.kw_all_of.array_items | length) == 1 %} + {{ content(schema.kw_all_of.array_items[0]) }} + {% elif schema.kw_any_of and (schema.kw_any_of.array_items | length) == 1 %} + {{ content(schema.kw_any_of.array_items[0]) }} + {% else %} + {% if schema.explicit_no_additional_properties %} + {{ " " }}No Additional Properties + {% endif %} + + {# Combining: allOf, anyOf, oneOf, not #} + {% if schema.kw_all_of %} +
{{ tabbed_section("allOf", schema.kw_all_of) }}
+ {% endif %} + {% if schema.kw_any_of %} +
{{ tabbed_section("anyOf", schema.kw_any_of) }}
+ {% endif %} + {% if schema.kw_one_of %} +
{{ tabbed_section("oneOf", schema.kw_one_of) }}
+ {% endif %} + {% if schema.kw_not %} + {% include "section_not.html" %} + {% endif %} + + {# Enum and const #} + {% if schema.kw_enum %} +
+

Must be one of:

+
    + {% for enum_choice in schema.kw_enum.array_items %} +
  • {{ enum_choice.literal | python_to_json }}
  • + {% endfor %} +
+
+ {% endif %} + {% if schema.kw_const %} + Specific value: {{ schema.kw_const.raw | python_to_json }} + {% endif %} + + {# Pattern (Regular Expression) #} + {% if schema.kw_pattern %} + Must match regular expression: {{ schema.kw_pattern.literal | escape }} + {% endif %} + + {# Conditional subschema, or if-then-else section #} + {% if schema.has_conditional %} + {% include "section_conditional_subschema.html" %} + {% endif %} + + {# Required properties that are not defined under "properties". They will only be listed #} + {% include "section_undocumented_required_properties.html" %} + + {# Show the requested type(s) #} + {% include "badge_type.html" %} + + {# Show array restrictions #} + {% if type_name.startswith("array") %} + {% include "section_array.html" %} + {% endif %} + + {# Display examples #} + {% set examples = schema.examples %} + {% if examples %} + {% include "section_examples.html" %} + {% endif %} + + {# Properties, pattern properties, additional properties #} + {% for sub_property in schema.iterate_properties %} + {% include "section_properties.html" %} + {% endfor %} + + {% endif %} + {% endif %} +{% endmacro %} \ No newline at end of file diff --git a/docs/docs_templates/templates/home.jinja2 b/docs/docs_templates/templates/home.jinja2 new file mode 100644 index 00000000..9e2aa31f --- /dev/null +++ b/docs/docs_templates/templates/home.jinja2 @@ -0,0 +1,15 @@ +{% extends "base.jinja2" %} + +{% block content %} +
+
+

Welcome!

+
+
+
+
+

This is the official documentation for New Horizons

+
+
+{% endblock %} + diff --git a/docs/docs_templates/templates/macro_restriction.html b/docs/docs_templates/templates/macro_restriction.html new file mode 100644 index 00000000..25627d71 --- /dev/null +++ b/docs/docs_templates/templates/macro_restriction.html @@ -0,0 +1,3 @@ +{%- macro restriction(inner_text, css_class_name, html_id) -%} +

{{ inner_text }}

+{%- endmacro -%} \ No newline at end of file diff --git a/docs/docs_templates/templates/schema_base.jinja2 b/docs/docs_templates/templates/schema_base.jinja2 new file mode 100644 index 00000000..56c4a806 --- /dev/null +++ b/docs/docs_templates/templates/schema_base.jinja2 @@ -0,0 +1,15 @@ +{% extends "base.jinja2" %} +{% from 'content.html' import content with context %} + +{% block content %} +
+
+

{{ title|title }}

+
+
+
+
+ {{ content(schema) }} +
+
+{% endblock %} \ No newline at end of file diff --git a/docs/docs_templates/templates/schema_doc.min.js b/docs/docs_templates/templates/schema_doc.min.js new file mode 100644 index 00000000..0d9c7882 --- /dev/null +++ b/docs/docs_templates/templates/schema_doc.min.js @@ -0,0 +1 @@ +function flashElement(t){myElement=document.getElementById(t),myElement.classList.add("jsfh-animated-property"),setTimeout(function(){myElement.classList.remove("jsfh-animated-property")},1e3)}function setAnchor(t){history.pushState({},"",t)}function anchorOnLoad(){let t=window.location.hash.split("?")[0].split("&")[0];"#"===t[0]&&(t=t.substr(1)),t.length>0&&anchorLink(t)}function anchorLink(t){$("#"+t).parents().addBack().filter(".collapse:not(.show), .tab-pane, [role='tab']").each(function(t){if($(this).hasClass("collapse"))$(this).collapse("show");else if($(this).hasClass("tab-pane")){const t=$("a[href='#"+$(this).attr("id")+"']");t&&t.tab("show")}else"tab"===$(this).attr("role")&&$(this).tab("show")}),setTimeout(function(){let e=document.getElementById(t);e&&(e.scrollIntoView({block:"center",behavior:"smooth"}),setTimeout(function(){flashElement(t)},500))},1e3)}$(document).on("click",'a[href^="#"]',function(t){t.preventDefault(),history.pushState({},"",this.href)}); \ No newline at end of file diff --git a/docs/docs_templates/templates/section_array.html b/docs/docs_templates/templates/section_array.html new file mode 100644 index 00000000..a676f0d9 --- /dev/null +++ b/docs/docs_templates/templates/section_array.html @@ -0,0 +1,36 @@ +{%- if schema.kw_min_items -%} + {{ restriction("Must contain a minimum of " ~ schema.kw_min_items.literal ~ " items", "min-items", schema.kw_min_items.html_id) }} +{%- endif -%} +{%- if schema.kw_max_items -%} + {{ restriction("Must contain a maximum of " ~ schema.kw_max_items.literal ~ " 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 -%} +

Each item of this array must be:

+
+
+ {{ content(schema.array_items_def) }} +
+
+{%- endif -%} +{%- if schema.tuple_validation_items -%} +

Tuple Validation

+ {% for item in schema.tuple_validation_items %} +
Item at {{ loop.index }} must be:
+
+
+ {{ content(item) }} +
+
+ {% endfor %} +{%- endif -%} +{%- if schema.kw_contains and schema.kw_contains.literal != {} -%} +

At least one of the items must be:

+
+
+ {{ content(schema.kw_contains) }} +
+
+{%- endif -%} \ No newline at end of file diff --git a/docs/docs_templates/templates/section_conditional_subschema.html b/docs/docs_templates/templates/section_conditional_subschema.html new file mode 100644 index 00000000..e543669d --- /dev/null +++ b/docs/docs_templates/templates/section_conditional_subschema.html @@ -0,0 +1,58 @@ +

+ +

+

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.

+ + +
+ {% set tab_id = schema.kw_if.html_id %} +
+ {{ content(schema.kw_if) }} +
+ + {% if schema.kw_then %} + {% set tab_id = schema.kw_then.html_id %} +
+ {{ content(schema.kw_then) }} +
+ {%- endif -%} + + {%- if schema.kw_else -%} + {% set tab_id = schema.kw_else.html_id %} +
+ {{ content(schema.kw_else) }} +
+ {%- endif -%} +
\ No newline at end of file diff --git a/docs/docs_templates/templates/section_description.html b/docs/docs_templates/templates/section_description.html new file mode 100644 index 00000000..2e90dc71 --- /dev/null +++ b/docs/docs_templates/templates/section_description.html @@ -0,0 +1,20 @@ +{# Display description #} +{% if description %} +
+
+ {% if not config.collapse_long_descriptions or description is description_short %} + {{ description }} + {% else %} +
+ {{ description }} +
+
+ +
+ {% endif %} +
+
+{% endif %} diff --git a/docs/docs_templates/templates/section_examples.html b/docs/docs_templates/templates/section_examples.html new file mode 100644 index 00000000..51675917 --- /dev/null +++ b/docs/docs_templates/templates/section_examples.html @@ -0,0 +1,18 @@ +
+
Example{% if examples|length > 1 %}s{% endif %}:
+
+ +{%- 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 -%} + + {%- endif -%} +
+ {%- if not examples_as_yaml -%} + {{ example | highlight_json_example }} + {%- else -%} + {{ example | highlight_yaml_example }} + {%- endif -%} +
+{%- endfor -%} diff --git a/docs/docs_templates/templates/section_not.html b/docs/docs_templates/templates/section_not.html new file mode 100644 index 00000000..ed0f5222 --- /dev/null +++ b/docs/docs_templates/templates/section_not.html @@ -0,0 +1,8 @@ +
+

Must not be:

+
+
+ {{ content(schema.kw_not) }} +
+
+
\ No newline at end of file diff --git a/docs/docs_templates/templates/section_properties.html b/docs/docs_templates/templates/section_properties.html new file mode 100644 index 00000000..725139a3 --- /dev/null +++ b/docs/docs_templates/templates/section_properties.html @@ -0,0 +1,62 @@ +{% set html_id = sub_property.html_id %} +
+
+
+
+

+ +

+
+
+ {% if sub_property.is_pattern_property %} +

+ +

+

All property whose name matches the following regular expression must respect the + following + conditions

+ Property name regular expression: {{ sub_property.property_name | escape }} +
+ {% endif %} + + {% if sub_property.is_additional_properties %} + {% if sub_property.is_additional_properties_schema %} +

Each additional property must conform to the following + schema

+ {% else %} +

Additional Properties of any type are allowed.

+ {% endif %} + {% endif %} + + {{ content(sub_property) }} +
+
+
+
+
+
diff --git a/docs/docs_templates/templates/section_undocumented_required_properties.html b/docs/docs_templates/templates/section_undocumented_required_properties.html new file mode 100644 index 00000000..7e7ceaeb --- /dev/null +++ b/docs/docs_templates/templates/section_undocumented_required_properties.html @@ -0,0 +1,11 @@ +{%- set undocumented_required_properties = schema | get_undocumented_required_properties -%} +{%- if undocumented_required_properties-%} +
+

The following properties are required:

+
    + {%- for required_property in undocumented_required_properties -%} +
  • {{ required_property }}
  • + {%- endfor -%} +
+
+{%- endif -%} \ No newline at end of file diff --git a/docs/docs_templates/templates/tabbed_section.html b/docs/docs_templates/templates/tabbed_section.html new file mode 100644 index 00000000..9cecf4c1 --- /dev/null +++ b/docs/docs_templates/templates/tabbed_section.html @@ -0,0 +1,25 @@ +

+ +

+{%- set tab_label = "Option" -%} +{%- if operator == "allOf" -%} + {%- set tab_label = "Requirement" -%} +{%- endif -%} + +
+ {%- for node in current_node.array_items -%} +
+ {{ content(node) }} +
+ {%- endfor -%} +
\ No newline at end of file diff --git a/docs/generate.py b/docs/generate.py new file mode 100644 index 00000000..d9c560a3 --- /dev/null +++ b/docs/generate.py @@ -0,0 +1,72 @@ +from dataclasses import dataclass +from pathlib import Path + +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 + +env = Environment( + loader=PackageLoader('docs_templates', 'templates'), + autoescape=select_autoescape(['jinja2']) +) + +env.filters["lowerfirst"] = lambda x: x[0].lower() + x[1:] + +home = env.get_template("base.jinja2") + + +@dataclass +class Page: + in_name: str + out_name: str + title: str + + 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+') as file: + file.write(rendered_string) + + +config = GenerationConfiguration(custom_template_path="docs_templates/templates/schema_base.jinja2") +config.link_to_reused_ref = False + + +@dataclass +class Schema(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) + + +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 + + +for page in pages: + page.render(schemas=schemas) + +print("Done")