Skip to content

Commit 9960f72

Browse files
Formatting, alt text, empty string edge case, names
1 parent 98c3b44 commit 9960f72

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/hexdoc/_templates/pages/patchouli/entity.html.jinja

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
{% import "macros/textures.html.jinja" as texture_macros with context %}
55

66
{% block body %}
7-
<h4>
8-
{{- page.get_name() -}}
9-
{%- if page_anchor_id is defined %}
10-
{{- fmt.permalink(page_anchor_id) -}}
11-
{% endif -%}
12-
</h4>
13-
<p class="image-wrapper">
14-
{{ texture_macros.render_texture(
15-
name=page.get_name(),
16-
texture=page.texture,
17-
class_names=["entity-display"]
18-
) }}
19-
</p>
20-
{{ fmt.styled(page.text) }}
7+
<h4>
8+
{{- page.name -}}
9+
{%- if page_anchor_id is defined %}
10+
{{- fmt.permalink(page_anchor_id) -}}
11+
{% endif -%}
12+
</h4>
13+
{% block image %}
14+
<p class="image-wrapper">
15+
{{ texture_macros.render_texture(
16+
name=page.entity_name,
17+
texture=page.texture,
18+
class_names=["entity-display"]
19+
) }}
20+
</p>
21+
{% endblock image %}
22+
{{ fmt.styled(page.text) }}
2123
{% endblock %}

src/hexdoc/patchouli/page/pages.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,25 @@ class EmptyPage(Page, type="patchouli:empty", template_type="patchouli:page"):
5353

5454

5555
class EntityPage(PageWithText, type="patchouli:entity"):
56-
_default_name: LocalizedStr = PrivateAttr()
56+
_entity_name: LocalizedStr = PrivateAttr()
5757
_texture: PNGTexture = PrivateAttr()
5858

5959
entity: Entity
6060
scale: float = 1
6161
offset: float = 0
6262
rotate: bool = True
6363
default_rotation: float = -45
64-
name: LocalizedStr | None = None
64+
name_field: LocalizedStr | None = Field(default=None, serialization_alias="name")
6565

66-
def get_name(self):
67-
if self.name is None:
68-
return self._default_name
69-
return self.name
66+
@property
67+
def entity_name(self):
68+
return self._entity_name
69+
70+
@property
71+
def name(self):
72+
if self.name_field is None or not self.name_field.value:
73+
return self._entity_name
74+
return self.name_field
7075

7176
@property
7277
def texture(self):
@@ -78,7 +83,7 @@ def _get_texture(self, info: ValidationInfo) -> Self:
7883
# causes circular references with the PNGTexture
7984
assert info.context is not None
8085
i18n = I18n.of(info)
81-
self._default_name = i18n.localize_entity(self.entity.id)
86+
self._entity_name = i18n.localize_entity(self.entity.id)
8287
self._texture = PNGTexture.load_id(
8388
id="textures/entities" / self.entity.id + ".png", context=info.context
8489
)

0 commit comments

Comments
 (0)