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 %}
{{ blog.title }}
{% endblock title %}
{% block header %}
<a href="/~/{{ blog.fqn }}">{{ blog.title }}</a>
{% endblock header %}
{% block content %}
<h1>{{ blog.title }} <small>~{{ blog.fqn }}</small></h1>
<p>{{ blog.summary }}</p>
<p>
{{ "{{ count }} authors in this blog: " | _n(singular="One author in this blog: ", count = n_authors) }}
{% for author in authors %}
<a class="author" href="/@/{{ author.fqn }}">{{ author.name }}</a>{% if not loop.last %},{% endif %}
{% endfor %}
</p>
<p>
{{ "{{ count }} articles in this blog" | _n(singular="One article in this blog", count = n_articles) }}
</p>
<section>
<h2>
{{ "Latest articles" | _ }}
<small><a href="/~/{{ blog.fqn }}/atom.xml" title="Atom feed">{{ macros::feather(name="rss") }}</a></small>
</h2>
{% if posts | length < 1 %}
<p>{{ "No posts to see here yet." | _ }}</p>
{% endif %}
{% if is_author %}
<a href="/~/{{ blog.fqn }}/new/" class="button inline-block">{{ "New article" | _ }}</a>
{% endif %}
<div class="cards">
{% for article in posts %}
{{ macros::post_card(article=article) }}
{% endfor %}
</div>
{{ macros::paginate(page=page, total=n_pages) }}
</section>
{% if is_author %}
<h2>{{ "Danger zone" | _ }}</h2>
<p>{{ "Be very careful, any action taken here can't be cancelled." | _ }}
<form method="post" action="/~/{{ blog.fqn }}/delete">
<input type="submit" class="inline-block button destructive" value="{{ "Delete this blog" | _ }}">
</form>
{% endif %}
{% endblock content %}
+49
View File
@@ -0,0 +1,49 @@
@use plume_models::blogs::Blog;
@use plume_models::posts::Post;
@use plume_models::users::User;
@use templates::{base, partials::post_card};
@use template_utils::*;
@(ctx: BaseContext, blog: Blog, fqn: String, authors: &Vec<User>, total_articles: usize, page: i32, n_pages: i32, is_author: bool, posts: Vec<Post>)
@:base(ctx, blog.title.as_ref(), {}, {
<a href="/~/@fqn">@blog.title</a>
}, {
<h1>@blog.title <small>~@fqn</small></h1>
<p>@blog.summary</p>
<p>
@i18n!(ctx.1, "One author in this blog: ", "{0} authors in this blog: ", authors.len())
@for author in authors {
<a class="author" href="/@@/@author.get_fqn(ctx.0)">@author.name(ctx.0)</a>
}
</p>
<p>
@i18n!(ctx.1, "One article in this blog", "{0} articles in this blog", total_articles)
</p>
<section>
<h2>
@i18n!(ctx.1, "Latest articles")
<small><a href="/~/@fqn/atom.xml" title="Atom feed">@icon!("rss")</a></small>
</h2>
@if posts.len() < 1 {
<p>@i18n!(ctx.1, "No posts to see here yet.")</p>
}
@if is_author {
<a href="/~/@fqn/new/" class="button inline-block">@i18n!(ctx.1, "New article")</a>
}
<div class="cards">
@for article in posts {
@:post_card(ctx, article)
}
</div>
@paginate(ctx.1, page, n_pages)
</section>
@if is_author {
<h2>@i18n!(ctx.1, "Danger zone")</h2>
<p>@i18n!(ctx.1, "Be very careful, any action taken here can't be cancelled.")</p>
<form method="post" action="/~/@fqn/delete">
<input type="submit" class="inline-block button destructive" value="@i18n!(ctx.1, "Delete this blog")">
</form>
}
})
-15
View File
@@ -1,15 +0,0 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
{{ "New blog" | _ }}
{% endblock title %}
{% block content %}
<h1>{{ "Create a blog" | _ }}</h1>
<form method="post">
{{ macros::input(name="title", label="Title", errors=errors, form=form, props='required minlength="1"') }}
<input type="submit" value="{{ "Create blog" | _ }}"/>
</form>
{% endblock content %}
+14
View File
@@ -0,0 +1,14 @@
@use validator::ValidationErrors;
@use templates::base;
@use template_utils::*;
@use routes::blogs::NewBlogForm;
@(ctx: BaseContext, form: &NewBlogForm, errors: ValidationErrors)
@:base(ctx, "New Blog", {}, {}, {
<h1>@i18n!(ctx.1, "Create a blog")</h1>
<form method="post">
@input!(ctx.1, title (text), "Title", form, errors, "required minlength=\"1\"")
<input type="submit" value="@i18n!(ctx.1, "Create blog")"/>
</form>
})