mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-03 07:45:14 +00:00
Use 2018 edition idioms
This commit is contained in:
parent
d042c5d758
commit
5549f9a3cd
@ -400,7 +400,7 @@
|
|||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate askama_derive;
|
extern crate askama_derive;
|
||||||
extern crate askama_shared as shared;
|
use askama_shared as shared;
|
||||||
|
|
||||||
use std::fs::{self, DirEntry};
|
use std::fs::{self, DirEntry};
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -415,7 +415,7 @@ pub trait Template {
|
|||||||
Ok(buf)
|
Ok(buf)
|
||||||
}
|
}
|
||||||
/// Renders the template to the given `writer` buffer
|
/// Renders the template to the given `writer` buffer
|
||||||
fn render_into(&self, writer: &mut std::fmt::Write) -> Result<()>;
|
fn render_into(&self, writer: &mut dyn std::fmt::Write) -> Result<()>;
|
||||||
/// Helper function to inspect the template's extension
|
/// Helper function to inspect the template's extension
|
||||||
fn extension() -> Option<&'static str>
|
fn extension() -> Option<&'static str>
|
||||||
where
|
where
|
||||||
@ -478,7 +478,7 @@ pub mod actix_web {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> {
|
fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry)) -> io::Result<()> {
|
||||||
if dir.is_dir() {
|
if dir.is_dir() {
|
||||||
for entry in fs::read_dir(dir)? {
|
for entry in fs::read_dir(dir)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::{get_template_source, Context, Heritage};
|
use super::{get_template_source, Context, Heritage};
|
||||||
use crate::input::TemplateInput;
|
use crate::input::TemplateInput;
|
||||||
use crate::parser::{Cond, Expr, MatchParameter, MatchVariant, Node, Target, When, WS};
|
use crate::parser::{Cond, Expr, MatchParameter, MatchVariant, Node, Target, When, WS};
|
||||||
use crate::shared::filters;
|
use askama_shared::filters;
|
||||||
|
|
||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use proc_macro2::TokenStream;
|
|||||||
|
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
|
|
||||||
use crate::shared::{Config, Syntax};
|
use askama_shared::{Config, Syntax};
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
extern crate askama_shared as shared;
|
extern crate proc_macro;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate nom;
|
extern crate nom;
|
||||||
extern crate proc_macro;
|
|
||||||
extern crate proc_macro2;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
extern crate syn;
|
|
||||||
|
|
||||||
mod generator;
|
mod generator;
|
||||||
mod input;
|
mod input;
|
||||||
@ -13,7 +10,7 @@ mod parser;
|
|||||||
|
|
||||||
use crate::input::{Print, Source, TemplateInput};
|
use crate::input::{Print, Source, TemplateInput};
|
||||||
use crate::parser::{Expr, Macro, Node};
|
use crate::parser::{Expr, Macro, Node};
|
||||||
use crate::shared::{read_config_file, Config};
|
use askama_shared::{read_config_file, Config};
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
|
||||||
use crate::parser::parse;
|
use crate::parser::parse;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use nom;
|
use nom;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use crate::shared::Syntax;
|
use askama_shared::Syntax;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Expr<'a> {
|
pub enum Expr<'a> {
|
||||||
@ -771,7 +771,7 @@ pub fn parse<'a>(src: &'a str, syntax: &'a Syntax<'a>) -> Vec<Node<'a>> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::shared::Syntax;
|
use askama_shared::Syntax;
|
||||||
|
|
||||||
fn check_ws_split(s: &str, res: &(&str, &str, &str)) {
|
fn check_ws_split(s: &str, res: &(&str, &str, &str)) {
|
||||||
let node = super::split_ws_parts(s.as_bytes());
|
let node = super::split_ws_parts(s.as_bytes());
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
extern crate askama_escape;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate criterion;
|
extern crate criterion;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ impl<T> Display for MarkupDisplay<T>
|
|||||||
where
|
where
|
||||||
T: Display,
|
T: Display,
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
MarkupDisplay::Unsafe(ref t) => escape(&t.to_string()).fmt(f),
|
MarkupDisplay::Unsafe(ref t) => escape(&t.to_string()).fmt(f),
|
||||||
MarkupDisplay::Safe(ref t) => t.fmt(f),
|
MarkupDisplay::Safe(ref t) => t.fmt(f),
|
||||||
@ -43,7 +43,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn escape(s: &str) -> Escaped {
|
pub fn escape(s: &str) -> Escaped<'_> {
|
||||||
Escaped {
|
Escaped {
|
||||||
bytes: s.as_bytes(),
|
bytes: s.as_bytes(),
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ pub struct Escaped<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ::std::fmt::Display for Escaped<'a> {
|
impl<'a> ::std::fmt::Display for Escaped<'a> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
for (i, b) in self.bytes.iter().enumerate() {
|
for (i, b) in self.bytes.iter().enumerate() {
|
||||||
if b.wrapping_sub(b'"') <= FLAG {
|
if b.wrapping_sub(b'"') <= FLAG {
|
||||||
|
@ -49,7 +49,7 @@ impl ErrorTrait for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cause(&self) -> Option<&ErrorTrait> {
|
fn cause(&self) -> Option<&dyn ErrorTrait> {
|
||||||
match *self {
|
match *self {
|
||||||
Error::Fmt(ref err) => err.cause(),
|
Error::Fmt(ref err) => err.cause(),
|
||||||
#[cfg(feature = "serde_json")]
|
#[cfg(feature = "serde_json")]
|
||||||
@ -60,7 +60,7 @@ impl ErrorTrait for Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Error::Fmt(ref err) => write!(formatter, "formatting error: {}", err),
|
Error::Fmt(ref err) => write!(formatter, "formatting error: {}", err),
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use MarkupDisplay;
|
use askama_escape::MarkupDisplay;
|
||||||
|
|
||||||
/// Serialize to JSON (requires `serde_json` feature)
|
/// Serialize to JSON (requires `serde_json` feature)
|
||||||
///
|
///
|
||||||
|
@ -97,7 +97,7 @@ pub fn format() {}
|
|||||||
///
|
///
|
||||||
/// A single newline becomes an HTML line break `<br>` and a new line
|
/// A single newline becomes an HTML line break `<br>` and a new line
|
||||||
/// followed by a blank line becomes a paragraph break `<p>`.
|
/// followed by a blank line becomes a paragraph break `<p>`.
|
||||||
pub fn linebreaks(s: &fmt::Display) -> Result<String> {
|
pub fn linebreaks(s: &dyn fmt::Display) -> Result<String> {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
let linebroken = s.replace("\n\n", "</p><p>").replace("\n", "<br/>");
|
let linebroken = s.replace("\n\n", "</p><p>").replace("\n", "<br/>");
|
||||||
|
|
||||||
@ -105,41 +105,41 @@ pub fn linebreaks(s: &fmt::Display) -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Converts all newlines in a piece of plain text to HTML line breaks
|
/// Converts all newlines in a piece of plain text to HTML line breaks
|
||||||
pub fn linebreaksbr(s: &fmt::Display) -> Result<String> {
|
pub fn linebreaksbr(s: &dyn fmt::Display) -> Result<String> {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
Ok(s.replace("\n", "<br/>"))
|
Ok(s.replace("\n", "<br/>"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts to lowercase
|
/// Converts to lowercase
|
||||||
pub fn lower(s: &fmt::Display) -> Result<String> {
|
pub fn lower(s: &dyn fmt::Display) -> Result<String> {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
Ok(s.to_lowercase())
|
Ok(s.to_lowercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alias for the `lower()` filter
|
/// Alias for the `lower()` filter
|
||||||
pub fn lowercase(s: &fmt::Display) -> Result<String> {
|
pub fn lowercase(s: &dyn fmt::Display) -> Result<String> {
|
||||||
lower(s)
|
lower(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts to uppercase
|
/// Converts to uppercase
|
||||||
pub fn upper(s: &fmt::Display) -> Result<String> {
|
pub fn upper(s: &dyn fmt::Display) -> Result<String> {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
Ok(s.to_uppercase())
|
Ok(s.to_uppercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alias for the `upper()` filter
|
/// Alias for the `upper()` filter
|
||||||
pub fn uppercase(s: &fmt::Display) -> Result<String> {
|
pub fn uppercase(s: &dyn fmt::Display) -> Result<String> {
|
||||||
upper(s)
|
upper(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strip leading and trailing whitespace
|
/// Strip leading and trailing whitespace
|
||||||
pub fn trim(s: &fmt::Display) -> Result<String> {
|
pub fn trim(s: &dyn fmt::Display) -> Result<String> {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
Ok(s.trim().to_owned())
|
Ok(s.trim().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Limit string length, appends '...' if truncated
|
/// Limit string length, appends '...' if truncated
|
||||||
pub fn truncate(s: &fmt::Display, len: &usize) -> Result<String> {
|
pub fn truncate(s: &dyn fmt::Display, len: &usize) -> Result<String> {
|
||||||
let mut s = s.to_string();
|
let mut s = s.to_string();
|
||||||
if s.len() < *len {
|
if s.len() < *len {
|
||||||
Ok(s)
|
Ok(s)
|
||||||
@ -151,7 +151,7 @@ pub fn truncate(s: &fmt::Display, len: &usize) -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Indent lines with `width` spaces
|
/// Indent lines with `width` spaces
|
||||||
pub fn indent(s: &fmt::Display, width: &usize) -> Result<String> {
|
pub fn indent(s: &dyn fmt::Display, width: &usize) -> Result<String> {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
|
|
||||||
let mut indented = String::new();
|
let mut indented = String::new();
|
||||||
@ -216,7 +216,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Capitalize a value. The first character will be uppercase, all others lowercase.
|
/// Capitalize a value. The first character will be uppercase, all others lowercase.
|
||||||
pub fn capitalize(s: &fmt::Display) -> Result<String> {
|
pub fn capitalize(s: &dyn fmt::Display) -> Result<String> {
|
||||||
let mut s = s.to_string();
|
let mut s = s.to_string();
|
||||||
|
|
||||||
match s.get_mut(0..1).map(|s| {
|
match s.get_mut(0..1).map(|s| {
|
||||||
@ -234,7 +234,7 @@ pub fn capitalize(s: &fmt::Display) -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Centers the value in a field of a given width
|
/// Centers the value in a field of a given width
|
||||||
pub fn center(s: &fmt::Display, l: usize) -> Result<String> {
|
pub fn center(s: &dyn fmt::Display, l: usize) -> Result<String> {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
let len = s.len();
|
let len = s.len();
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ pub fn center(s: &fmt::Display, l: usize) -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Count the words in that string
|
/// Count the words in that string
|
||||||
pub fn wordcount(s: &fmt::Display) -> Result<usize> {
|
pub fn wordcount(s: &dyn fmt::Display) -> Result<usize> {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
|
|
||||||
Ok(s.split_whitespace().count())
|
Ok(s.split_whitespace().count())
|
||||||
|
@ -1,14 +1,8 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(unused_parens))]
|
#![cfg_attr(feature = "cargo-clippy", allow(unused_parens))]
|
||||||
|
|
||||||
extern crate askama_escape;
|
|
||||||
extern crate humansize;
|
|
||||||
extern crate num_traits;
|
|
||||||
extern crate serde;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
#[cfg(feature = "serde_json")]
|
|
||||||
extern crate serde_json;
|
use toml;
|
||||||
extern crate toml;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@ -31,14 +25,14 @@ pub struct Config<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Config<'a> {
|
impl<'a> Config<'a> {
|
||||||
pub fn new(s: &str) -> Config {
|
pub fn new(s: &str) -> Config<'_> {
|
||||||
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||||
let default_dirs = vec![root.join("templates")];
|
let default_dirs = vec![root.join("templates")];
|
||||||
|
|
||||||
let mut syntaxes = BTreeMap::new();
|
let mut syntaxes = BTreeMap::new();
|
||||||
syntaxes.insert(DEFAULT_SYNTAX_NAME.to_string(), Syntax::default());
|
syntaxes.insert(DEFAULT_SYNTAX_NAME.to_string(), Syntax::default());
|
||||||
|
|
||||||
let raw: RawConfig =
|
let raw: RawConfig<'_> =
|
||||||
toml::from_str(&s).expect(&format!("invalid TOML in {}", CONFIG_FILE_NAME));
|
toml::from_str(&s).expect(&format!("invalid TOML in {}", CONFIG_FILE_NAME));
|
||||||
|
|
||||||
let (dirs, default_syntax) = match raw.general {
|
let (dirs, default_syntax) = match raw.general {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate criterion;
|
extern crate criterion;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate askama;
|
use askama;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
askama::rerun_if_templates_changed();
|
askama::rerun_if_templates_changed();
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
#![cfg(feature = "actix")]
|
#![cfg(feature = "actix")]
|
||||||
extern crate actix_web;
|
|
||||||
extern crate askama;
|
|
||||||
extern crate bytes;
|
|
||||||
|
|
||||||
use actix_web::http::header::CONTENT_TYPE;
|
use actix_web::http::header::CONTENT_TYPE;
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
use actix_web::HttpMessage;
|
use actix_web::HttpMessage;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
#[cfg(feature = "serde-json")]
|
#[cfg(feature = "serde-json")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
@ -48,7 +47,7 @@ mod filters {
|
|||||||
Ok(s.replace("oo", "aa").to_string())
|
Ok(s.replace("oo", "aa").to_string())
|
||||||
}
|
}
|
||||||
// for test_nested_filter_ref
|
// for test_nested_filter_ref
|
||||||
pub fn mytrim(s: &::std::fmt::Display) -> ::askama::Result<String> {
|
pub fn mytrim(s: &dyn (::std::fmt::Display)) -> ::askama::Result<String> {
|
||||||
let s = format!("{}", s);
|
let s = format!("{}", s);
|
||||||
Ok(s.trim().to_owned())
|
Ok(s.trim().to_owned())
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)] // this will generate the code...
|
#[derive(Template)] // this will generate the code...
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
#![cfg(feature = "iron")]
|
#![cfg(feature = "iron")]
|
||||||
extern crate askama;
|
|
||||||
extern crate iron;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use iron::{status, Response};
|
use iron::{status, Response};
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#![cfg(feature = "with-rocket")]
|
#![cfg(feature = "with-rocket")]
|
||||||
#![feature(proc_macro_hygiene, decl_macro)]
|
#![feature(proc_macro_hygiene, decl_macro)]
|
||||||
|
|
||||||
extern crate askama;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
macro_rules! hello {
|
macro_rules! hello {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate askama;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user