Skip to content

Commit

Permalink
UPDATE
Browse files Browse the repository at this point in the history
  • Loading branch information
simonharrer committed Apr 29, 2024
1 parent c6b6d7a commit 2e8fcc7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
16 changes: 8 additions & 8 deletions datacontract/catalog/catalog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from pathlib import Path

from jinja2 import PackageLoader, Environment, select_autoescape
import pytz
Expand All @@ -9,19 +10,18 @@
from datacontract.model.data_contract_specification import DataContractSpecification


def create_data_contract_html(contracts, file, path):
def create_data_contract_html(contracts, file: Path, path: 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
file_without_suffix = file.with_suffix(".html")
html_filepath = path / file_without_suffix
html_filepath.parent.mkdir(parents=True, exist_ok=True)
with open(html_filepath, "w") as f:
f.write(html)
contracts.append(DataContractView(
html_filepath=html_filepath,
html_filename=html_filename,
html_link=file_without_suffix,
spec=spec,
))
print(f"Created {html_filepath}")
Expand All @@ -30,8 +30,8 @@ def create_data_contract_html(contracts, file, path):
@dataclass
class DataContractView:
"""Class for keeping track of an item in inventory."""
html_filepath: str
html_filename: str
html_filepath: Path
html_link: Path
spec: DataContractSpecification


Expand Down
5 changes: 4 additions & 1 deletion datacontract/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ def catalog(

contracts = []
for file in Path().glob(files):
create_data_contract_html(contracts, file, path)
try:
create_data_contract_html(contracts, file, path)
except Exception as e:
console.print(f"Skipped {file} due to error: {e}")

create_index_html(contracts, path)

Expand Down
4 changes: 2 additions & 2 deletions datacontract/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h2 class="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm
{% for contract in contracts %}

<li class="col-span-1 rounded-lg bg-white shadow hover:bg-gray-50">
<a href="{{contract.html_filename}}" >
<a href="{{contract.html_link}}" >
<div class="flex w-full justify-between space-x-1 p-6 pb-4">
<div class="flex-1 truncate">
<div class="flex items-center space-x-3">
Expand All @@ -70,8 +70,8 @@ <h3 class="truncate text-sm font-medium text-gray-900">{{contract.spec.info.titl
<path stroke-linecap="round" stroke-linejoin="round" d="M18 18.72a9.094 9.094 0 003.741-.479 3 3 0 00-4.682-2.72m.94 3.198l.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0112 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 016 18.719m12 0a5.971 5.971 0 00-.941-3.197m0 0A5.995 5.995 0 0012 12.75a5.995 5.995 0 00-5.058 2.772m0 0a3 3 0 00-4.681 2.72 8.986 8.986 0 003.74.477m.94-3.197a5.971 5.971 0 00-.94 3.197M15 6.75a3 3 0 11-6 0 3 3 0 016 0zm6 3a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0zm-13.5 0a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0z" />
</svg>
<span>{{contract.spec.info.owner}}</span>
{% endif %}
</div>
{% endif %}
</div>

</div>
Expand Down

0 comments on commit 2e8fcc7

Please sign in to comment.