forked from datacontract/datacontract-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
datacontract catalog (datacontract#158)
* First draft of catalog feature Co-authored-by: jochen <[email protected]>
- Loading branch information
1 parent
7fc43d1
commit ed6abcf
Showing
10 changed files
with
2,206 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from dataclasses import dataclass | ||
|
||
from jinja2 import PackageLoader, Environment, select_autoescape | ||
import pytz | ||
from datetime import datetime | ||
|
||
from datacontract.export.html_export import get_version | ||
from datacontract.data_contract import DataContract | ||
from datacontract.model.data_contract_specification import DataContractSpecification | ||
|
||
|
||
def create_data_contract_html(contracts, file, path): | ||
data_contract = DataContract(data_contract_file=f"{file.absolute()}", inline_definitions=True) | ||
html = data_contract.export(export_format="html") | ||
spec = data_contract.get_data_contract_specification() | ||
# html_filename = f"dc-{spec.id}-{spec.info.version}.html" | ||
file_without_suffix = file.name.removesuffix(".yaml").removesuffix(".yml") | ||
html_filename = f"{file_without_suffix}.html" | ||
html_filepath = path / html_filename | ||
with open(html_filepath, "w") as f: | ||
f.write(html) | ||
contracts.append(DataContractView( | ||
html_filepath=html_filepath, | ||
html_filename=html_filename, | ||
spec=spec, | ||
)) | ||
print(f"Created {html_filepath}") | ||
|
||
|
||
@dataclass | ||
class DataContractView: | ||
"""Class for keeping track of an item in inventory.""" | ||
html_filepath: str | ||
html_filename: str | ||
spec: DataContractSpecification | ||
|
||
|
||
def create_index_html(contracts, path): | ||
index_filepath = path / "index.html" | ||
with open(index_filepath, "w") as f: | ||
# Load templates from templates folder | ||
package_loader = PackageLoader("datacontract", "templates") | ||
env = Environment( | ||
loader=package_loader, | ||
autoescape=select_autoescape( | ||
enabled_extensions="html", | ||
default_for_string=True, | ||
), | ||
) | ||
|
||
# Load the required template | ||
template = env.get_template("index.html") | ||
|
||
style_content, _, _ = package_loader.get_source(env, "style/output.css") | ||
|
||
tz = pytz.timezone('UTC') | ||
now = datetime.now(tz) | ||
formatted_date = now.strftime('%d %b %Y %H:%M:%S UTC') | ||
datacontract_cli_version = get_version() | ||
|
||
# Render the template with necessary data | ||
html_string = template.render( | ||
style=style_content, | ||
formatted_date=formatted_date, | ||
datacontract_cli_version=datacontract_cli_version, | ||
contracts=contracts, | ||
contracts_size=len(contracts), | ||
) | ||
f.write(html_string) | ||
print(f"Created {index_filepath}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<!doctype html> | ||
<html class="h-full bg-gray-100" lang="en"> | ||
<head> | ||
<title>Data Contract</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
{# <script src="https://cdn.tailwindcss.com"></script> #} | ||
<style> | ||
{{style | safe }} | ||
</style> | ||
</head> | ||
<body class="h-full"> | ||
|
||
<div class="min-h-full flex flex-col"> | ||
|
||
<nav class="bg-white shadow-sm"> | ||
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8"> | ||
<div class="flex h-16 justify-between"> | ||
<div class="flex"> | ||
<div class="flex flex-shrink-0 items-center mr-6"> | ||
<a class="text-xl text-gray-900 font-semibold" href="/"> | ||
Data Contract Catalog | ||
</a> | ||
</div> | ||
</div> | ||
<div class="hidden sm:ml-6 sm:flex sm:items-center"> | ||
<a href="https://datacontract.com" class="text-sky-500 hover:text-gray-700 text-sm font-semibold" target="_blank">datacontract.com</a> | ||
</div> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
<main class="pb-7"> | ||
|
||
<div class="pt-5 mx-auto max-w-7xl sm:px-6 lg:px-8"> | ||
<div> | ||
<div class="lg:flex lg:items-center lg:justify-between px-4 sm:px-0"> | ||
<div class="min-w-0 flex-1"> | ||
<h2 class="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight"> | ||
Data Contracts</h2> | ||
<div class="mt-1 flex flex-col sm:mt-0 sm:flex-row sm:flex-wrap sm:space-x-6"> | ||
There are {{ contracts_size }} contracts in the catalog | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
</div> | ||
|
||
<div> | ||
|
||
<div class="space-y-6 mt-6"> | ||
|
||
<section id="catalog"> | ||
|
||
|
||
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8"> | ||
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8"> | ||
<div class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 sm:rounded-lg"> | ||
|
||
<table class="min-w-full divide-y divide-gray-300"> | ||
<thead class="bg-gray-50"> | ||
<tr> | ||
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">Title</th> | ||
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">ID</th> | ||
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Version</th> | ||
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Owner</th> | ||
</tr> | ||
</thead> | ||
<tbody class="divide-y divide-gray-200 bg-white"> | ||
{% for contract in contracts %} | ||
<tr> | ||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6"> | ||
<a class="text-indigo-600 hover:text-indigo-900" href="{{contract.html_filename}}">{{contract.spec.info.title}}</a> | ||
</td> | ||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"> | ||
{{contract.spec.id}} | ||
</td> | ||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"> | ||
{{contract.spec.info.version}} | ||
</td> | ||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"> | ||
{{contract.spec.info.owner}} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
||
</section> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
<div class="mt-6 text-sm text-gray-400"> | ||
Created at {{formatted_date}} with <a href="https://cli.datacontract.com" class="text-gray-400 hover:text-gray-500">Data Contract CLI</a> v{{datacontract_cli_version}} | ||
</div> | ||
|
||
</div> | ||
</main> | ||
|
||
<dialog id="dialog-datacontract-yaml" class="relative z-10" aria-labelledby="modal-title" aria-modal="true"> | ||
<div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"></div> | ||
|
||
<div class="fixed inset-0 z-10 w-screen overflow-y-auto"> | ||
<div class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0"> | ||
<div class="relative transform rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-4/5 sm:p-6"> | ||
<div class="absolute right-0 top-0 pr-4 pt-4"> | ||
<button type="button" onclick="document.getElementById('dialog-datacontract-yaml').close()" class="rounded-md bg-white text-gray-400 hover:text-gray-500"> | ||
<span class="sr-only">Close</span> | ||
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /> | ||
</svg> | ||
</button> | ||
</div> | ||
<div> | ||
<div class="mt-3 mb-3 text-center sm:mt-5"> | ||
|
||
<h3 class="text-base font-semibold leading-6 text-gray-900" id="modal-title">Data Contract YAML</h3> | ||
</div> | ||
<pre class="overflow-x-auto text-sm bg-gray-50 p-4"><code>{{datacontract_yaml}}</code></pre> | ||
</div> | ||
<div class="mt-5 sm:mt-6"> | ||
<button type="button" onclick="document.getElementById('dialog-datacontract-yaml').close()" | ||
class="inline-flex w-full justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Close</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</dialog> | ||
|
||
|
||
<footer class="bg-white mt-auto text-sm text-gray-400"> | ||
<div class="mx-auto max-w-7xl py-5 px-6 md:flex md:items-center md:justify-between lg:px-8"> | ||
<div class="flex justify-center space-x-6 md:order-2"> | ||
<div> | ||
<a href="https://cli.datacontract.com" class="text-gray-400 hover:text-gray-500 px-2">Data Contract CLI</a> | ||
|
||
<a href="https://datacontract.com" class="text-gray-400 hover:text-gray-500 px-2">Data Contract Specification</a> | ||
</div> | ||
|
||
|
||
</div> | ||
<div class="mt-8 md:order-1 md:mt-0"> | ||
<p class="text-center leading-5 text-gray-400"> | ||
Supported with ❤️ by <a href="https://datamesh-manager.com" class="text-gray-400 hover:text-gray-500">Data Mesh Manager</a> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
</footer> | ||
|
||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
content: ["../datacontract.html"], | ||
content: ["../datacontract.html", "../index.html"], | ||
theme: { }, | ||
plugins: [], | ||
} |
Oops, something went wrong.