1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Reduced excessive whitespaces in jinja output

This commit is contained in:
Krateng 2020-09-01 00:35:14 +02:00
parent 1321fcb45e
commit e27a83bdc9
9 changed files with 36 additions and 29 deletions

View File

@ -5,7 +5,7 @@ author = {
"email":"maloja@krateng.dev", "email":"maloja@krateng.dev",
"github": "krateng" "github": "krateng"
} }
version = 2,8,1 version = 2,8,2
versionstr = ".".join(str(n) for n in version) versionstr = ".".join(str(n) for n in version)
links = { links = {
"pypi":"malojaserver", "pypi":"malojaserver",

View File

@ -78,6 +78,6 @@ NAME = None
[Misc] [Misc]
USE_JINJA = no
SKIP_SETUP = no SKIP_SETUP = no
LOGGING = true LOGGING = true
DEV_MODE = false

View File

@ -68,3 +68,7 @@ jinja_environment = Environment(
) )
jinja_environment.globals.update(JINJA_CONTEXT) jinja_environment.globals.update(JINJA_CONTEXT)
jinja_environment.filters.update({k:filters.__dict__[k] for k in filters.__dict__ if not k.startswith("__")}) jinja_environment.filters.update({k:filters.__dict__[k] for k in filters.__dict__ if not k.startswith("__")})
jinja_environment.trim_blocks = True
jinja_environment.lstrip_blocks = True
jinja_environment.strip_trailing_newlines = False

View File

@ -158,7 +158,8 @@ def static_image(pth):
@webserver.route("/style.css") @webserver.route("/style.css")
def get_css(): def get_css():
response.content_type = 'text/css' response.content_type = 'text/css'
return generate_css() if settings.get_settings("CSS_DEBUG") else css if settings.get_settings("DEV_MODE"): css = generate_css()
return css
@webserver.route("/login") @webserver.route("/login")
@ -222,6 +223,8 @@ def static_html(name):
template = jinja_environment.get_template(name + '.jinja') template = jinja_environment.get_template(name + '.jinja')
res = template.render(**LOCAL_CONTEXT) res = template.render(**LOCAL_CONTEXT)
if settings.get_settings("DEV_MODE"): jinja_environment.cache.clear()
log("Generated page {name} in {time:.5f}s (Jinja)".format(name=name,time=clock.stop()),module="debug_performance") log("Generated page {name} in {time:.5f}s (Jinja)".format(name=name,time=clock.stop()),module="debug_performance")
return res return res

View File

@ -15,7 +15,7 @@
<td> <td>
{% set segmentsize = segment+1 %} {% set segmentsize = segment+1 %}
<table class="tiles_{{ segmentsize }}x{{ segmentsize }} tiles_sub"> <table class="tiles_{{ segmentsize }}x{{ segmentsize }} tiles_sub">
{% for row in range(segmentsize) %} {% for row in range(segmentsize) -%}
<tr> <tr>
{% for col in range(segmentsize) %} {% for col in range(segmentsize) %}
{% set entry = charts_cycler.next() %} {% set entry = charts_cycler.next() %}
@ -29,12 +29,12 @@
</div> </div>
</a> </a>
</td> </td>
{% else %} {% else -%}
<td></td> <td></td>
{% endif %} {%- endif -%}
{% endfor %} {%- endfor -%}
</tr> </tr>
{% endfor %} {%- endfor -%}
</table> </table>
</td> </td>
{% endfor %} {% endfor %}

View File

@ -15,7 +15,7 @@
<td> <td>
{% set segmentsize = segment+1 %} {% set segmentsize = segment+1 %}
<table class="tiles_{{ segmentsize }}x{{ segmentsize }} tiles_sub"> <table class="tiles_{{ segmentsize }}x{{ segmentsize }} tiles_sub">
{% for row in range(segmentsize) %} {% for row in range(segmentsize) -%}
<tr> <tr>
{% for col in range(segmentsize) %} {% for col in range(segmentsize) %}
{% set entry = charts_cycler.next() %} {% set entry = charts_cycler.next() %}
@ -29,12 +29,12 @@
</div> </div>
</a> </a>
</td> </td>
{% else %} {% else -%}
<td></td> <td></td>
{% endif %} {%- endif %}
{% endfor %} {%- endfor -%}
</tr> </tr>
{% endfor %} {%- endfor %}
</table> </table>
</td> </td>
{% endfor %} {% endfor %}

View File

@ -7,12 +7,12 @@
<table class='list'> <table class='list'>
{% for s in scrobbles %} {% for s in scrobbles -%}
{% if loop.index0 >= firstindex and loop.index0 < lastindex %} {%- if loop.index0 >= firstindex and loop.index0 < lastindex -%}
<tr> <tr>
<td class='time'>{{ malojatime.timestamp_desc(s["time"],short=shortTimeDesc) }}</td> <td class='time'>{{ malojatime.timestamp_desc(s["time"],short=shortTimeDesc) }}</td>
{{ entityrow.row(s) }} {{ entityrow.row(s) }}
</tr> </tr>
{% endif %} {%- endif -%}
{% endfor %} {% endfor %}
</table> </table>

View File

@ -16,24 +16,24 @@
{% macro url(entity) -%} {% macro url(entity) %}
{% if 'artists' in entity %} {% if 'artists' in entity -%}
{{ mlj_uri.create_uri("/track",{'track':entity}) }} {{ mlj_uri.create_uri("/track",{'track':entity}) }}
{% else %} {%- else -%}
{{ mlj_uri.create_uri("/artist",{'artist':entity}) }} {{ mlj_uri.create_uri("/artist",{'artist':entity}) }}
{% endif %} {%- endif %}
{%- endmacro %} {% endmacro %}
{% macro link_scrobbles(keydicts,amount=None,percent=None) %} {% macro link_scrobbles(keydicts,amount=None,percent=None) -%}
<a href='{{ mlj_uri.create_uri("/scrobbles",*keydicts) }}'> <a href='{{ mlj_uri.create_uri("/scrobbles",*keydicts) }}'>
{% if percent is not none %} {%- if percent is not none -%}
<div style='width:{{ percent }}%;'></div> <div style='width:{{ percent }}%;'></div>
{% elif amount is not none %} {%- elif amount is not none -%}
{{ amount }} {{ amount }}
{% endif %} {%- endif -%}
</a> </a>
{%- endmacro %} {%- endmacro %}

View File

@ -18,12 +18,12 @@
<!-- ARTIST CHARTS --> <!-- ARTIST CHARTS -->
<h1><a class="stat_link_topartists" href="/charts_artists?in=alltime">Top Artists</a></h1> <h1><a class="stat_link_topartists" href="/charts_artists?in=alltime">Top Artists</a></h1>
{% for range in xcurrent %} {% for range in xcurrent -%}
<span onclick="showRangeManual('topartists','{{ range.identifier }}')" class="stat_selector_topartists selector_topartists_{{ range.identifier }}"> <span onclick="showRangeManual('topartists','{{ range.identifier }}')" class="stat_selector_topartists selector_topartists_{{ range.identifier }}">
{{ range.localisation }} {{ range.localisation }}
</span> </span>
{{ "|" if not loop.last }} {{ "|" if not loop.last }}
{% endfor %} {%- endfor %}
<br/><br/> <br/><br/>
@ -41,12 +41,12 @@
<!-- TRACK CHARTS --> <!-- TRACK CHARTS -->
<h1><a class="stat_link_toptracks" href="/charts_tracks?in=alltime">Top Tracks</a></h1> <h1><a class="stat_link_toptracks" href="/charts_tracks?in=alltime">Top Tracks</a></h1>
{% for range in xcurrent %} {% for range in xcurrent -%}
<span onclick="showRangeManual('toptracks','{{ range.identifier }}')" class="stat_selector_toptracks selector_toptracks_{{ range.identifier }}"> <span onclick="showRangeManual('toptracks','{{ range.identifier }}')" class="stat_selector_toptracks selector_toptracks_{{ range.identifier }}">
{{ range.localisation }} {{ range.localisation }}
</span> </span>
{{ "|" if not loop.last }} {{ "|" if not loop.last }}
{% endfor %} {%- endfor %}
<br/><br/> <br/><br/>