Skip to content

Commit

Permalink
Make _repr_html_ look like _repr_json_ output (#1142)
Browse files Browse the repository at this point in the history
* Make html repr look like json repr

* Make index start at 0

* Make sure little triangle shows up in jupyter notebook

* Fix indentation

* Add tests for more objects

* Update some notebooks

* Do not transform hrefs

* Update changelog

* Simplify html a bit

* Remove a few spaces
  • Loading branch information
jsignell authored Jun 6, 2023
1 parent 5402e71 commit 334c4c4
Show file tree
Hide file tree
Showing 22 changed files with 3,658 additions and 1,740 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- EO extension updated to v1.1.0 ([#1131](https://github.com/stac-utils/pystac/pull/1131))
- Use `id` in STACTypeError instead of entire dict ([#1126](https://github.com/stac-utils/pystac/pull/1126))
- Make sure that `get_items` is backwards compatible ([#1139](https://github.com/stac-utils/pystac/pull/1139))
- Make `_repr_html_` look like `_repr_json_` output ([#1142](https://github.com/stac-utils/pystac/pull/1142))

### Deprecated

Expand Down
1,905 changes: 1,075 additions & 830 deletions docs/quickstart.ipynb

Large diffs are not rendered by default.

3,000 changes: 2,424 additions & 576 deletions docs/tutorials/how-to-create-stac-catalogs.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pystac/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def __repr__(self) -> str:
def _repr_html_(self) -> str:
jinja_env = get_jinja_env()
if jinja_env:
template = jinja_env.get_template("Asset.jinja2")
return str(template.render(asset=self))
template = jinja_env.get_template("JSON.jinja2")
return str(template.render(dict=self.to_dict()))
else:
return escape(repr(self))

Expand Down
10 changes: 0 additions & 10 deletions pystac/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import warnings
from copy import deepcopy
from html import escape
from itertools import chain
from typing import (
TYPE_CHECKING,
Expand All @@ -24,7 +23,6 @@
import pystac
from pystac.cache import ResolvedObjectCache
from pystac.errors import STACTypeError
from pystac.html.jinja_env import get_jinja_env
from pystac.layout import (
BestPracticesLayoutStrategy,
HrefLayoutStrategy,
Expand Down Expand Up @@ -207,14 +205,6 @@ def __init__(
def __repr__(self) -> str:
return "<Catalog id={}>".format(self.id)

def _repr_html_(self) -> str:
jinja_env = get_jinja_env()
if jinja_env:
template = jinja_env.get_template("Catalog.jinja2")
return str(template.render(catalog=self))
else:
return escape(repr(self))

def set_root(self, root: Optional["Catalog"]) -> None:
STACObject.set_root(self, root)
if root is not None:
Expand Down
10 changes: 0 additions & 10 deletions pystac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import warnings
from copy import deepcopy
from datetime import datetime
from html import escape
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -25,7 +24,6 @@
from pystac.asset import Asset
from pystac.catalog import Catalog
from pystac.errors import DeprecatedWarning, ExtensionNotImplemented, STACTypeError
from pystac.html.jinja_env import get_jinja_env
from pystac.layout import HrefLayoutStrategy
from pystac.link import Link
from pystac.provider import Provider
Expand Down Expand Up @@ -540,14 +538,6 @@ def __init__(
def __repr__(self) -> str:
return "<Collection id={}>".format(self.id)

def _repr_html_(self) -> str:
jinja_env = get_jinja_env()
if jinja_env:
template = jinja_env.get_template("Collection.jinja2")
return str(template.render(catalog=self))
else:
return escape(repr(self))

def add_item(
self,
item: Item,
Expand Down
31 changes: 0 additions & 31 deletions pystac/html/Asset.jinja2

This file was deleted.

30 changes: 0 additions & 30 deletions pystac/html/Catalog.jinja2

This file was deleted.

20 changes: 0 additions & 20 deletions pystac/html/Collection.jinja2

This file was deleted.

27 changes: 0 additions & 27 deletions pystac/html/Item.jinja2

This file was deleted.

31 changes: 0 additions & 31 deletions pystac/html/ItemCollection.jinja2

This file was deleted.

29 changes: 29 additions & 0 deletions pystac/html/JSON.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% import 'Macros.jinja2' as macros %}

<style>
.pystac-summary {
cursor: pointer;
display:list-item;
}
.pystac-key {
color: rgb(0, 128, 0);
font-weight: 700;
}
.pystac-key-value {
display: inline-block;
margin: 0px 0.5em 0px 0px;
}
</style>
<div class="jp-RenderedJSON jp-mod-trusted jp-OutputArea-output">
<div class="container" style="line-height: normal;">
<ul style="padding: 0px; margin: 0px; list-style: none; display: block;">
{% for key, value in dict.items() %}
{% if value is iterable and (value is not string and value is not mapping) %}
{{ macros.list(key, value) }}
{% else %}
{{ macros.scalar(key, value) }}
{% endif %}
{% endfor %}
</ul>
</div>
</div>
23 changes: 0 additions & 23 deletions pystac/html/Link.jinja2

This file was deleted.

Loading

0 comments on commit 334c4c4

Please sign in to comment.