Add tag_object html macro to centralize that effort. Still needs work.
This commit is contained in:
parent
aa30d5903d
commit
5ba2ecd38a
4 changed files with 86 additions and 11 deletions
|
@ -2,6 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
{% import "header.html" as header %}
|
||||
{% import "tag_object.html" as tag_object %}
|
||||
<title>Photo {{photo.basename}}</title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="/static/common.css">
|
||||
|
@ -166,13 +167,7 @@
|
|||
{% set tags = photo.sorted_tags() %}
|
||||
{% for tag in tags %}
|
||||
<li>
|
||||
{% set qualified_name=tag.qualified_name() %}
|
||||
{% set display_name=qualified_name %}
|
||||
{% if display_name|length > 30 %}
|
||||
{% set display_name = display_name[-30:] %}
|
||||
{% set display_name = display_name.split(".", 1)[1] %}
|
||||
{% endif %}
|
||||
<a class="tag_object" href="/search?tag_musts={{tag.name}}" title="{{qualified_name}}">{{display_name}}</a><!--
|
||||
{{tag_object.tag_object(tag, qualified_name=True, max_len=30, with_alt_description=True, with_alt_qualified_name=True)}}<!--
|
||||
--><button
|
||||
class="remove_tag_button"
|
||||
onclick="remove_photo_tag('{{photo.id}}', '{{tag.name}}', receive_callback);">
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
{% import "photo_card.html" as photo_card %}
|
||||
{% import "header.html" as header %}
|
||||
{% import "tag_object.html" as tag_object %}
|
||||
<title>Search</title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="/static/common.css">
|
||||
|
@ -270,7 +271,14 @@ form
|
|||
<span>Tags on this page (click to join query):</span>
|
||||
<ul>
|
||||
{% for tag in total_tags %}
|
||||
<li><a href="javascript:void(0)" title="{{tag.description}}" class="tag_object tags_on_this_page">{{tag.name}}</a></li>
|
||||
<li>{{tag_object.tag_object(
|
||||
tag,
|
||||
extra_classes="tags_on_this_page",
|
||||
link='void',
|
||||
qualified_name=False,
|
||||
with_alt_qualified_name=True,
|
||||
with_alt_description=True,
|
||||
)}}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
|
71
frontends/etiquette_flask/templates/tag_object.html
Normal file
71
frontends/etiquette_flask/templates/tag_object.html
Normal file
|
@ -0,0 +1,71 @@
|
|||
<!--
|
||||
tag: The Tag object
|
||||
extra_classes:
|
||||
Space-separated string, if you want more than "tag_object".
|
||||
link:
|
||||
None = no link, just a <span>
|
||||
'search' = link to /search?tag_musts=tagname
|
||||
'info' = link to /tags/tagname
|
||||
'void' = javascript:void(0)
|
||||
max_len:
|
||||
None: As long as it needs to be.
|
||||
integer: Rootmost parents are removed until the text fits under
|
||||
this limit.
|
||||
If the tag's own name can't find under the limit, characters are
|
||||
dropped from the right.
|
||||
qualified_name:
|
||||
True: Use the qualified name as the innerhtml
|
||||
False: Use the basic name
|
||||
with_alt_description:
|
||||
True: Include the description in the alt text
|
||||
with_alt_qualified_name:
|
||||
True: Include the qualified name in the alt text
|
||||
-->
|
||||
{% macro tag_object(
|
||||
tag,
|
||||
extra_classes="",
|
||||
link='search',
|
||||
max_len=None,
|
||||
qualified_name=True,
|
||||
with_alt_description=True,
|
||||
with_alt_qualified_name=True
|
||||
) %}
|
||||
{%- if link is not none -%}
|
||||
{%- set closing="</a>" -%}
|
||||
<a
|
||||
{%- if link == 'search' -%}
|
||||
{{' '}}href="/search?tag_musts={{tag.name}}"
|
||||
{%- elif link == 'info' -%}
|
||||
{{' '}}href="/tags/{{tag.name}}"
|
||||
{%- elif link == 'void' -%}
|
||||
{{' '}}href="javascript:void(0)"
|
||||
{%- else -%}
|
||||
{{' '}}href="{{search}}"
|
||||
{%- endif -%}
|
||||
{{' '}}target="_blank" class="tag_object {{extra_classes}}"
|
||||
|
||||
{%- else -%}
|
||||
{% set closing="</span>" %}
|
||||
<span
|
||||
|
||||
{%- endif -%}
|
||||
{% set altlines=[] %}
|
||||
{% if with_alt_qualified_name %}{% do altlines.append(tag.qualified_name()) %}{% endif %}
|
||||
{% if with_alt_description %}{% do altlines.append(tag.description) %}{% endif %}
|
||||
{% set altlines=altlines|join("\n") %}
|
||||
{%- if altlines -%}
|
||||
{{' '}}title="{{altlines}}"
|
||||
{%- endif -%}
|
||||
>
|
||||
{%- if qualified_name -%}
|
||||
{{tag.qualified_name(max_len=max_len)}}
|
||||
{%- else -%}
|
||||
{% if max_len is not none %}
|
||||
{{tag.name[:max_len]}}
|
||||
{% else %}
|
||||
{{tag.name}}
|
||||
{% endif %}
|
||||
{%- endif -%}
|
||||
|
||||
{{- closing|safe -}}
|
||||
{% endmacro %}
|
|
@ -2,6 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
{% import "header.html" as header %}
|
||||
{% import "tag_object.html" as tag_object %}
|
||||
<title>Tags</title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="/static/common.css">
|
||||
|
@ -75,7 +76,7 @@ body
|
|||
{% for tag in tags %}
|
||||
{% set qualified_name = tag.qualified_name() %}
|
||||
<li>
|
||||
<a target="_blank" class="tag_object" title="{{tag.description}}" href="/search?tag_musts={{tag.name}}">{{qualified_name}}</a><!--
|
||||
{{tag_object.tag_object(tag, link='search', qualified_name=True, with_alt_qualified_name=False)}}<!--
|
||||
--><button class="remove_tag_button" onclick="delete_tag('{{tag.name}}', receive_callback);"></button>
|
||||
</li>
|
||||
{% if include_synonyms %}
|
||||
|
|
Loading…
Reference in a new issue