Use Ructe (#327)

All the template are now compiled at compile-time with the `ructe` crate.

I preferred to use it instead of askama because it allows more complex Rust expressions, where askama only supports a small subset of expressions and doesn't allow them everywhere (for instance, `{{ macro!() | filter }}` would result in a parsing error).

The diff is quite huge, but there is normally no changes in functionality.

Fixes #161 and unblocks #110 and #273
This commit is contained in:
Baptiste Gelez
2018-12-06 18:54:16 +01:00
committed by GitHub
parent 5f059c3e98
commit 70af57c6e1
121 changed files with 3132 additions and 3260 deletions
-35
View File
@@ -1,35 +0,0 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
{{ "Media details" | _ }}
{% endblock title %}
{% block content %}
<h1>{{ "Media details" }}</h1>
<section>
<a href="/medias">{{ "Go back to the gallery" | _ }}</a>
</section>
<section>
<figure class="media">
{{ media.html | safe }}
<figcaption>{{ media.alt_text }}</figcaption>
</figure>
<div>
<p>
{{ "Markdown code" | _ }}
<small>{{ "Copy it in your articles to insert this media." }}</small>
</p>
<code>{{ media.md }}</code>
</div>
<div>
<form class="inline" method="post" action="/medias/{{ media.id }}/avatar">
<input class="button" type="submit" value="{{ 'Use as avatar' | _ }}">
</form>
<form class="inline" method="post" action="/medias/{{ media.id }}/delete">
<input class="button" type="submit" value="{{ 'Delete' | _ }}">
</form>
</div>
</section>
{% endblock content %}
+36
View File
@@ -0,0 +1,36 @@
@use templates::base;
@use template_utils::*;
@use plume_models::medias::{Media, MediaCategory};
@(ctx: BaseContext, media: Media)
@:base(ctx, "Media details", {}, {}, {
<h1>@i18n!(ctx.1, "Media details")</h1>
<section>
<a href="/medias">@i18n!(ctx.1, "Go back to the gallery")</a>
</section>
<section>
<figure class="media">
@Html(media.html(ctx.0))
<figcaption>@media.alt_text</figcaption>
</figure>
<div>
<p>
@i18n!(ctx.1, "Markdown code")
<small>@i18n!(ctx.1, "Copy it in your articles to insert this media.")</small>
</p>
<code>@media.markdown(ctx.0)</code>
</div>
<div>
@if media.category() == MediaCategory::Image {
<form class="inline" method="post" action="/medias/@media.id/avatar">
<input class="button" type="submit" value="@i18n!(ctx.1, "Use as avatar")">
</form>
}
<form class="inline" method="post" action="/medias/@media.id/delete">
<input class="button" type="submit" value="@i18n!(ctx.1, "Delete")">
</form>
</div>
</section>
})
-31
View File
@@ -1,31 +0,0 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
{{ "Your media" | _ }}
{% endblock title %}
{% block content %}
<h1>{{ "Your media" | _ }}</h1>
<div>
<a href="/medias/new" class="inline-block button">Upload</a>
</div>
<section>
{% if medias | length < 1 %}
<p>{{ "You don't have any media yet." | _ }}</p>
{% endif %}
<div class="list">
{% for media in medias %}
<div class="card flex">
{{ media.html_preview | safe }}
<main class="grow">
<p><a href="/medias/{{ media.id }}">{{ media.alt_text }}</a></p>
</main>
<a href="/medias/{{ media.id }}/delete">{{ "Delete" | _ }}</a>
</div>
{% endfor %}
</div>
{# TODO: macros::paginate(page=page, total=n_pages) #}
</section>
{% endblock content %}
+29
View File
@@ -0,0 +1,29 @@
@use templates::base;
@use template_utils::*;
@use plume_models::medias::Media;
@(ctx: BaseContext, medias: Vec<Media>)
@:base(ctx, "Your media", {}, {}, {
<h1>@i18n!(ctx.1, "Your media")</h1>
<div>
<a href="/medias/new" class="inline-block button">@i18n!(ctx.1, "Upload")</a>
</div>
<section>
@if medias.is_empty() {
<p>@i18n!(ctx.1, "You don't have any media yet.")</p>
}
<div class="list">
@for media in medias {
<div class="card flex">
@Html(media.preview_html(ctx.0))
<main class="grow">
<p><a href="/medias/@media.id">@media.alt_text</a></p>
</main>
<a href="/medias/@media.id/delete">@i18n!(ctx.1, "Delete")</a>
</div>
}
</div>
</section>
})
-17
View File
@@ -1,17 +0,0 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
{{ "Media upload" | _ }}
{% endblock title %}
{% block content %}
<h1>{{ "Media upload" | _ }}</h1>
<form method="post" enctype="multipart/form-data">
{{ macros::input(name="alt", label="Description", errors=errors, form=form, props='required minlength="1"', details='Useful for visually impaired people and licensing') }}
{{ macros::input(name="cw", label="Content warning", errors=errors, form=form, details='Let it empty if there is none') }}
{{ macros::input(name="file", type='file', label="File", errors=errors, form=form, props='required') }}
<input type="submit" value="{{ "Send" | _ }}"/>
</form>
{% endblock content %}
+28
View File
@@ -0,0 +1,28 @@
@use templates::base;
@use template_utils::*;
@(ctx: BaseContext)
@:base(ctx, "Media upload", {}, {}, {
<h1>@i18n!(ctx.1, "Media upload")</h1>
<form method="post" enctype="multipart/form-data">
<label for="alt">
@i18n!(ctx.1, "Description")
<small>@i18n!(ctx.1, "Useful for visually impaired people and licensing")</small>
</label>
<input type="text" id="alt" name="alt" required minlenght="1"/>
<label for="cw">
@i18n!(ctx.1, "Content warning")
<small>@i18n!(ctx.1, "Let it empty if there is none")</small>
</label>
<input type="txt" id="cw" name="cw"/>
<label for="file">
@i18n!(ctx.1, "File")
</label>
<input type="file" id="file" name="file" required/>
<input type="submit" value="@i18n!(ctx.1, "Send")"/>
</form>
})