From b172a80e35d66ae12851ca630a4fbd0932373d6b Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Tue, 23 Jul 2019 00:07:23 +0200 Subject: [PATCH] finally fix url! also please a bit clippy --- src/template_utils.rs | 19 ++++++++++++++++--- templates/blogs/details.rs.html | 2 +- templates/partials/post_card.rs.html | 2 +- templates/posts/details.rs.html | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/template_utils.rs b/src/template_utils.rs index 3d85ffd3..6c034d15 100644 --- a/src/template_utils.rs +++ b/src/template_utils.rs @@ -1,7 +1,10 @@ use plume_models::{notifications::*, users::User, Connection, PlumeRocket}; use rocket::http::hyper::header::{ETag, EntityTag}; -use rocket::http::{Method, Status}; +use rocket::http::{ + uri::{FromUriParam, Query}, + Method, Status, +}; use rocket::request::Request; use rocket::response::{self, content::Html as HtmlCt, Responder, Response}; use rocket_i18n::Catalog; @@ -13,6 +16,16 @@ pub use askama_escape::escape; pub static CACHE_NAME: &str = env!("CACHE_ID"); +pub struct NoValue; // workarround for missing FromUriParam implementation for Option + +impl FromUriParam for Option { + type Target = Option; + + fn from_uri_param(_: NoValue) -> Self::Target { + None + } +} + pub type BaseContext<'a> = &'a ( &'a Connection, &'a Catalog, @@ -363,7 +376,7 @@ macro_rules! url { common=[$($common_args:tt = $common_val:expr),*], normal=[$($normal_args:tt = $normal_val:expr),*], custom=[$($custom_args:tt = $custom_val:expr),*]) => {{ - let domain: Option<&plume_models::blogs::Host> = $domain.as_ref(); //for type inference with None + let domain: &Option = &$domain; //for type inference with None $( let $common_args = $common_val; )* @@ -372,7 +385,7 @@ macro_rules! url { let $custom_args = $custom_val; )* let origin = uri!(crate::routes::$module::custom::$route: - $custom_domain = domain.as_ref(), + $custom_domain = domain.to_string(), $($common_args = $common_args,)* $($custom_args = $custom_args,)* ); diff --git a/templates/blogs/details.rs.html b/templates/blogs/details.rs.html index 51a2a7f2..d4035348 100644 --- a/templates/blogs/details.rs.html +++ b/templates/blogs/details.rs.html @@ -24,7 +24,7 @@ }, { - @blog.title + @blog.title }, {