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
-50
View File
@@ -1,50 +0,0 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
Search
{% endblock title %}
{% block head %}
<script>
window.onload = function(evt) {
var form = document.getElementById('form');
form.addEventListener('submit', function () {
for (var input of form.getElementsByTagName('input')) {
if (input.name === '') {
input.name = input.id
}
if (input.name && !input.value) {
input.name = '';
}
}
});
}
</script>
{% endblock head %}
{% block content %}
<h1>search</h1>
<form method="get" id="form">
<input id="q" name="q" placeholder="Your query" type="search">
<details>
<summary>Advanced search</summary>
{{ macros::input(name="title", label="Title matching these words", props='placeholder="Title"') }}
{{ macros::input(name="subtitle", label="Subtitle matching these words", props='placeholder="Subtitle"') }}
{{ macros::input(name="content", label="Content matching these words", props='placeholder="Content"') }}
{{ macros::input(name="after", label="From this date", type="date", props='max=' ~ now) }}
{{ macros::input(name="before", label="To this date", type="date", props='max=' ~ now) }}
{{ macros::input(name="instance", label="Sent from one of these instance", props='placeholder="Instance domain"') }}
{{ macros::input(name="author", label="Sent by one of these author", props='placeholder="Authors"') }}
{{ macros::input(name="tag", label="Containing these tags", props='placeholder="Tags"') }}
{{ macros::input(name="blog", label="In blog", props='placeholder="Blog title"') }}
{{ macros::input(name="lang", label="Language used", props='placeholder="Language"') }}
{{ macros::input(name="license", label="Using license", props='placeholder="License"') }}
</details>
<input type="submit" value="Search"/>
</form>
{% endblock content %}
+43
View File
@@ -0,0 +1,43 @@
@use templates::base;
@use template_utils::*;
@(ctx: BaseContext, now: &str)
@:base(ctx, "Search", {
<script>
window.onload = function(evt) @{
var form = document.getElementById('form');
form.addEventListener('submit', function () @{
for (var input of form.getElementsByTagName('input')) @{
if (input.name === '') @{
input.name = input.id
@}
if (input.name && !input.value) @{
input.name = '';
@}
@}
@});
@}
</script>
}, {}, {
<h1>@i18n!(ctx.1, "Search")</h1>
<form method="get" id="form">
<input id="q" name="q" placeholder="Your query" type="search">
<details>
<summary>Advanced search</summary>
@input!(ctx.1, title (text), "Title matching these words", "placeholder=\"Title\"")
@input!(ctx.1, subtitle (text), "Subtitle matching these words", "placeholder=\"Subtitle\"")
@input!(ctx.1, content (text), "Content matching these words", "placeholder=\"Content\"")
@input!(ctx.1, after (date), "From this date", &format!("max={}", now)))
@input!(ctx.1, before (date), "To this date", &format!("max={}", now))
@input!(ctx.1, tag (text), "Containing these tags", "placeholder=\"Tags\"")
@input!(ctx.1, instance (text), "Posted in one of these instances", "placeholder=\"Instance domain\"")
@input!(ctx.1, author (text), "Posted by one of these authors", "placeholder=\"Authors\"")
@input!(ctx.1, blog (text), "Posted in one of these blogs", "placeholder=\"Blog title\"")
@input!(ctx.1, lang (text), "Wrote in this language", "placeholder=\"Language\"")
@input!(ctx.1, license (text), "Using this license", "placeholder=\"License\"")
</details>
<input type="submit" value="Search"/>
</form>
})
-26
View File
@@ -1,26 +0,0 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
Search result for "{{query}}"
{% endblock title %}
{% block content %}
<h1>Search result</h1>
<p>{{query}}</p>
<section>
{% if posts | length < 1 %}
{% if page == 1 %}
<p>No result for your query</p>
{% else %}
<p>No more result for your query</p>
{% endif %}
{% endif %}
<div class="cards">
{% for article in posts %}
{{ macros::post_card(article=article) }}
{% endfor %}
</div>
{{ macros::paginate(page=page, total=next_page, query= "q=" ~ query) }}
</section>
{% endblock content %}
+27
View File
@@ -0,0 +1,27 @@
@use templates::{base, partials::post_card};
@use template_utils::*;
@use plume_models::posts::Post;
@(ctx: BaseContext, query_str: &str, articles: Vec<Post>, page: i32, n_pages: i32)
@:base(ctx, i18n!(ctx.1, "Search result for \"{0}\""; query_str).as_str(), {}, {}, {
<h1>@i18n!(ctx.1, "Search result")</h1>
<p>@query_str</p>
@if articles.is_empty() {
<section>
@if page == 1 {
<h2>@i18n!(ctx.1, "No result for your query")</h2>
} else {
<h2>@i18n!(ctx.1, "No more result for your query")</h2>
}
</section>
} else {
<div class="cards">
@for article in articles {
@:post_card(ctx, article)
}
</div>
}
@paginate(ctx.1, page, n_pages)
})