aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama/src/lib.rs6
-rw-r--r--askama_shared/src/escaping.rs12
-rw-r--r--askama_shared/src/filters/json.rs8
-rw-r--r--askama_shared/src/filters/mod.rs27
-rw-r--r--askama_shared/src/generator.rs94
-rw-r--r--askama_shared/src/input.rs4
-rw-r--r--askama_shared/src/lib.rs6
-rw-r--r--askama_shared/src/path.rs3
-rw-r--r--testing/tests/filters.rs23
-rw-r--r--testing/tests/include.rs4
-rw-r--r--testing/tests/inheritance.rs5
-rw-r--r--testing/tests/loops.rs8
-rw-r--r--testing/tests/matches.rs2
-rw-r--r--testing/tests/operators.rs4
-rw-r--r--testing/tests/simple.rs15
15 files changed, 121 insertions, 100 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs
index 4552235..019a2b3 100644
--- a/askama/src/lib.rs
+++ b/askama/src/lib.rs
@@ -319,11 +319,11 @@ pub mod rocket {
fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> {
if dir.is_dir() {
- for entry in try!(fs::read_dir(dir)) {
- let entry = try!(entry);
+ for entry in fs::read_dir(dir)? {
+ let entry = entry?;
let path = entry.path();
if path.is_dir() {
- try!(visit_dirs(&path, cb));
+ visit_dirs(&path, cb)?;
} else {
cb(&entry);
}
diff --git a/askama_shared/src/escaping.rs b/askama_shared/src/escaping.rs
index 99babfd..896fc2a 100644
--- a/askama_shared/src/escaping.rs
+++ b/askama_shared/src/escaping.rs
@@ -11,12 +11,12 @@ impl<T> MarkupDisplay<T> where T: Display {
pub fn mark_safe(self) -> MarkupDisplay<T> {
match self {
MarkupDisplay::Unsafe(t) => MarkupDisplay::Safe(t),
- _ => { self },
+ _ => self,
}
}
pub fn unsafe_string(&self) -> String {
match *self {
- MarkupDisplay::Safe(ref t) | MarkupDisplay::Unsafe(ref t) => format!("{}", t)
+ MarkupDisplay::Safe(ref t) | MarkupDisplay::Unsafe(ref t) => format!("{}", t),
}
}
}
@@ -30,12 +30,8 @@ impl<T> From<T> for MarkupDisplay<T> where T: Display {
impl<T> Display for MarkupDisplay<T> where T: Display {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
- MarkupDisplay::Unsafe(_) => {
- write!(f, "{}", escape(self.unsafe_string()))
- },
- MarkupDisplay::Safe(ref t) => {
- t.fmt(f)
- },
+ MarkupDisplay::Unsafe(_) => write!(f, "{}", escape(self.unsafe_string())),
+ MarkupDisplay::Safe(ref t) => t.fmt(f),
}
}
}
diff --git a/askama_shared/src/filters/json.rs b/askama_shared/src/filters/json.rs
index c388128..6b818eb 100644
--- a/askama_shared/src/filters/json.rs
+++ b/askama_shared/src/filters/json.rs
@@ -26,10 +26,12 @@ mod tests {
fn test_json() {
assert_eq!(json(&true).unwrap().unsafe_string(), "true");
assert_eq!(json(&"foo").unwrap().unsafe_string(), r#""foo""#);
- assert_eq!(json(&vec!["foo", "bar"]).unwrap().unsafe_string(),
-r#"[
+ assert_eq!(
+ json(&vec!["foo", "bar"]).unwrap().unsafe_string(),
+ r#"[
"foo",
"bar"
-]"#);
+]"#
+ );
}
}
diff --git a/askama_shared/src/filters/mod.rs b/askama_shared/src/filters/mod.rs
index 8b1f814..32a7ccc 100644
--- a/askama_shared/src/filters/mod.rs
+++ b/askama_shared/src/filters/mod.rs
@@ -67,7 +67,7 @@ where
/// Rust). All arguments are passed through to the `format!()`
/// [macro](https://doc.rust-lang.org/stable/std/macro.format.html) by
/// the Askama code generator.
-pub fn format() { }
+pub fn format() {}
/// Converts to lowercase.
pub fn lower(s: &fmt::Display) -> Result<String> {
@@ -145,16 +145,28 @@ mod tests {
#[test]
fn test_join() {
- assert_eq!(join((&["hello", "world"]).into_iter(), ", ").unwrap(), "hello, world");
+ assert_eq!(
+ join((&["hello", "world"]).into_iter(), ", ").unwrap(),
+ "hello, world"
+ );
assert_eq!(join((&["hello"]).into_iter(), ", ").unwrap(), "hello");
let empty: &[&str] = &[];
assert_eq!(join(empty.into_iter(), ", ").unwrap(), "");
let input: Vec<String> = vec!["foo".into(), "bar".into(), "bazz".into()];
- assert_eq!(join((&input).into_iter(), ":".to_string()).unwrap(), "foo:bar:bazz");
- assert_eq!(join(input.clone().into_iter(), ":").unwrap(), "foo:bar:bazz");
- assert_eq!(join(input.clone().into_iter(), ":".to_string()).unwrap(), "foo:bar:bazz");
+ assert_eq!(
+ join((&input).into_iter(), ":".to_string()).unwrap(),
+ "foo:bar:bazz"
+ );
+ assert_eq!(
+ join(input.clone().into_iter(), ":").unwrap(),
+ "foo:bar:bazz"
+ );
+ assert_eq!(
+ join(input.clone().into_iter(), ":".to_string()).unwrap(),
+ "foo:bar:bazz"
+ );
let input: &[String] = &["foo".into(), "bar".into()];
assert_eq!(join(input.into_iter(), ":").unwrap(), "foo:bar");
@@ -164,6 +176,9 @@ mod tests {
let input: Vec<&str> = vec![&real];
assert_eq!(join(input.into_iter(), ";").unwrap(), "blah");
- assert_eq!(join((&&&&&["foo", "bar"]).into_iter(), ", ").unwrap(), "foo, bar");
+ assert_eq!(
+ join((&&&&&["foo", "bar"]).into_iter(), ", ").unwrap(),
+ "foo, bar"
+ );
}
}
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs
index f8d8ddf..63ebeb3 100644
--- a/askama_shared/src/generator.rs
+++ b/askama_shared/src/generator.rs
@@ -3,7 +3,7 @@ use input::TemplateInput;
use parser::{self, Cond, Expr, Macro, MatchParameter, MatchVariant, Node, Target, When, WS};
use path;
-use quote::{Tokens, ToTokens};
+use quote::{ToTokens, Tokens};
use std::{cmp, hash, str};
use std::path::Path;
@@ -34,11 +34,11 @@ impl<'a> State<'a> {
let mut macros = HashMap::new();
for n in nodes.iter() {
match *n {
- Node::Extends(ref path) => {
- match base {
- Some(_) => panic!("multiple extend blocks found"),
- None => { base = Some(path); },
- }
+ Node::Extends(ref path) => match base {
+ Some(_) => panic!("multiple extend blocks found"),
+ None => {
+ base = Some(path);
+ },
},
ref def @ Node::BlockDef(_, _, _, _) => {
blocks.push(def);
@@ -65,9 +65,7 @@ impl<'a> State<'a> {
fn trait_name_for_path(base: &Option<&Expr>, path: &Path) -> String {
let rooted_path = match *base {
- Some(&Expr::StrLit(user_path)) => {
- path::find_template_from_path(user_path, Some(path))
- },
+ Some(&Expr::StrLit(user_path)) => path::find_template_from_path(user_path, Some(path)),
_ => path.to_path_buf(),
};
@@ -85,17 +83,15 @@ fn trait_name_for_path(base: &Option<&Expr>, path: &Path) -> String {
fn get_parent_type(ast: &syn::DeriveInput) -> Option<&syn::Ty> {
match ast.body {
- syn::Body::Struct(ref data) => {
- data.fields().iter().filter_map(|f| {
- f.ident.as_ref().and_then(|name| {
- if name.as_ref() == "_parent" {
- Some(&f.ty)
- } else {
- None
- }
- })
+ syn::Body::Struct(ref data) => data.fields().iter().filter_map(|f| {
+ f.ident.as_ref().and_then(|name| {
+ if name.as_ref() == "_parent" {
+ Some(&f.ty)
+ } else {
+ None
+ }
})
- },
+ }),
_ => panic!("derive(Template) only works for struct items"),
}.next()
}
@@ -110,7 +106,6 @@ struct Generator<'a> {
}
impl<'a> Generator<'a> {
-
fn new<'n>(locals: SetChain<'n, &'n str>, indent: u8) -> Generator<'n> {
Generator {
buf: String::new(),
@@ -142,7 +137,11 @@ impl<'a> Generator<'a> {
self.deref_to_parent(state, parent_type);
}
- let trait_nodes = if !state.derived { Some(&state.nodes[..]) } else { None };
+ let trait_nodes = if !state.derived {
+ Some(&state.nodes[..])
+ } else {
+ None
+ };
self.impl_trait(state, trait_nodes);
self.impl_template_for_trait(state);
} else {
@@ -201,7 +200,8 @@ impl<'a> Generator<'a> {
self.writeln(&format!(
"fn render_trait_into(&self, timpl: &{}, writer: &mut ::std::fmt::Write) \
-> ::askama::Result<()> {{",
- state.trait_name));
+ state.trait_name
+ ));
self.writeln("#[allow(unused_imports)] use ::std::ops::Deref as HiddenDerefTrait;");
if let Some(nodes) = nodes {
@@ -335,11 +335,19 @@ impl<'a> Generator<'a> {
fn handle(&mut self, state: &'a State, nodes: &'a [Node], level: AstLevel) {
for n in nodes {
match *n {
- Node::Lit(lws, val, rws) => { self.write_lit(lws, val, rws); }
+ Node::Lit(lws, val, rws) => {
+ self.write_lit(lws, val, rws);
+ },
Node::Comment() => {},
- Node::Expr(ref ws, ref val) => { self.write_expr(state, ws, val); },
- Node::LetDecl(ref ws, ref var) => { self.write_let_decl(ws, var); },
- Node::Let(ref ws, ref var, ref val) => { self.write_let(ws, var, val); },
+ Node::Expr(ref ws, ref val) => {
+ self.write_expr(state, ws, val);
+ },
+ Node::LetDecl(ref ws, ref var) => {
+ self.write_let_decl(ws, var);
+ },
+ Node::Let(ref ws, ref var, ref val) => {
+ self.write_let(ws, var, val);
+ },
Node::Cond(ref conds, ref ws) => {
self.write_cond(state, conds, ws);
},
@@ -392,7 +400,8 @@ impl<'a> Generator<'a> {
self.writeln(&format!(
"fn render_block_{}_into(&self, writer: &mut ::std::fmt::Write) \
-> ::askama::Result<()> {{",
- name));
+ name
+ ));
self.prepare_ws(ws1);
self.locals.push();
@@ -606,8 +615,7 @@ impl<'a> Generator<'a> {
assert!(rws.is_empty());
self.next_ws = Some(lws);
} else {
- self.writeln(&format!("writer.write_str({:#?})?;",
- lws));
+ self.writeln(&format!("writer.write_str({:#?})?;", lws));
}
}
if !val.is_empty() {
@@ -629,11 +637,11 @@ impl<'a> Generator<'a> {
Expr::Array(ref elements) => self.visit_array(elements),
Expr::Attr(ref obj, name) => self.visit_attr(obj, name),
Expr::Filter(name, ref args) => self.visit_filter(name, args),
- Expr::BinOp(op, ref left, ref right) =>
- self.visit_binop(op, left, right),
+ Expr::BinOp(op, ref left, ref right) => self.visit_binop(op, left, right),
Expr::Group(ref inner) => self.visit_group(inner),
- Expr::MethodCall(ref obj, method, ref args) =>
- self.visit_method_call(obj, method, args),
+ Expr::MethodCall(ref obj, method, ref args) => {
+ self.visit_method_call(obj, method, args)
+ },
}
}
@@ -649,12 +657,12 @@ impl<'a> Generator<'a> {
self.write("&");
self.write(s);
DisplayWrap::Unwrapped
- }
+ },
MatchVariant::Path(ref s) => {
self.write("&");
self.write(&s.join("::"));
DisplayWrap::Unwrapped
- }
+ },
}
}
@@ -666,7 +674,7 @@ impl<'a> Generator<'a> {
self.write("ref ");
self.write(s);
DisplayWrap::Unwrapped
- }
+ },
}
}
@@ -817,7 +825,7 @@ impl<'a> Generator<'a> {
fn visit_target<'t>(&mut self, target: &'t Target) -> Vec<&'t str> {
match *target {
- Target::Name(s) => { self.visit_target_single(s) },
+ Target::Name(s) => self.visit_target_single(s),
}
}
@@ -837,8 +845,7 @@ impl<'a> Generator<'a> {
if self.next_ws.is_some() && !ws.0 {
let val = self.next_ws.unwrap();
if !val.is_empty() {
- self.writeln(&format!("writer.write_str({:#?})?;",
- val));
+ self.writeln(&format!("writer.write_str({:#?})?;", val));
}
}
self.next_ws = None;
@@ -903,11 +910,10 @@ impl<'a, T: 'a> SetChain<'a, T> where T: cmp::Eq + hash::Hash {
SetChain { parent: Some(parent), scopes: vec![HashSet::new()] }
}
fn contains(&self, val: T) -> bool {
- self.scopes.iter().rev().any(|set| set.contains(&val)) ||
- match self.parent {
- Some(set) => set.contains(val),
- None => false,
- }
+ self.scopes.iter().rev().any(|set| set.contains(&val)) || match self.parent {
+ Some(set) => set.contains(val),
+ None => false,
+ }
}
fn insert(&mut self, val: T) {
self.scopes.last_mut().unwrap().insert(val);
diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs
index bbff4b4..25382cb 100644
--- a/askama_shared/src/input.rs
+++ b/askama_shared/src/input.rs
@@ -92,7 +92,7 @@ impl<'a> TemplateMeta<'a> {
} else {
panic!("ext value must be string literal");
},
- attr @ _ => { panic!("unsupported annotation key '{}' found", attr) }
+ attr @ _ => panic!("unsupported annotation key '{}' found", attr),
}
}
}
@@ -123,7 +123,7 @@ impl<'a> TemplateMeta<'a> {
} else {
EscapeMode::None
}
- }
+ },
};
TemplateMeta { source, print, escaping, ext }
}
diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs
index 88439dc..0f46b91 100644
--- a/askama_shared/src/lib.rs
+++ b/askama_shared/src/lib.rs
@@ -21,7 +21,7 @@ mod input;
mod parser;
use input::Print;
-use parser::{Node, Macro};
+use parser::{Macro, Node};
use std::borrow::Cow;
use std::collections::HashMap;
@@ -50,10 +50,10 @@ pub fn build_template(ast: &syn::DeriveInput) -> String {
pub struct Imports<'a> {
- pub sources: HashMap<&'a str, Cow<'a, str>>
+ pub sources: HashMap<&'a str, Cow<'a, str>>,
}
-impl <'a> Imports<'a> {
+impl<'a> Imports<'a> {
pub fn new(parent_nodes: &'a [Node], parent_path: &'a Path) -> Imports<'a> {
let sources = parent_nodes.iter().filter_map(|n| {
match *n {
diff --git a/askama_shared/src/path.rs b/askama_shared/src/path.rs
index 80e364f..f7a3762 100644
--- a/askama_shared/src/path.rs
+++ b/askama_shared/src/path.rs
@@ -8,8 +8,7 @@ pub fn get_template_source(tpl_path: &Path) -> String {
path.push(tpl_path);
let mut f = match File::open(&path) {
Err(_) => {
- let msg = format!("unable to open template file '{}'",
- &path.to_str().unwrap());
+ let msg = format!("unable to open template file '{}'", &path.to_str().unwrap());
panic!(msg)
},
Ok(f) => f,
diff --git a/testing/tests/filters.rs b/testing/tests/filters.rs
index fe218e3..ca5e08d 100644
--- a/testing/tests/filters.rs
+++ b/testing/tests/filters.rs
@@ -18,9 +18,11 @@ fn filter_escape() {
let s = TestTemplate {
strvar: "// my <html> is \"unsafe\" & should be 'escaped'".to_string(),
};
- assert_eq!(s.render().unwrap(),
- "&#x2f;&#x2f; my &lt;html&gt; is &quot;unsafe&quot; &amp; \
- should be &#x27;escaped&#x27;");
+ assert_eq!(
+ s.render().unwrap(),
+ "&#x2f;&#x2f; my &lt;html&gt; is &quot;unsafe&quot; &amp; \
+ should be &#x27;escaped&#x27;"
+ );
}
@@ -57,7 +59,7 @@ fn test_my_filter() {
#[derive(Template)]
-#[template(path= "filters_join.html")]
+#[template(path = "filters_join.html")]
struct JoinTemplate<'a> {
s: &'a [&'a str],
}
@@ -69,9 +71,9 @@ fn test_join() {
}
#[derive(Template)]
-#[template(path= "filters_join.html")]
+#[template(path = "filters_join.html")]
struct VecJoinTemplate {
- s: Vec<String>
+ s: Vec<String>,
}
#[test]
@@ -90,10 +92,12 @@ struct JsonTemplate<'a> {
#[test]
fn test_json() {
- let val = json!({"arr": [ "one", 2, true, null ]});
+ let val = json!({"arr": [ "one", 2, true, null ]});
let t = JsonTemplate { foo: "a", bar: &val };
// Note: the json filter lacks a way to specify initial indentation
- assert_eq!(t.render().unwrap(), r#"{
+ assert_eq!(
+ t.render().unwrap(),
+ r#"{
"foo": "a",
"bar": {
"arr": [
@@ -103,5 +107,6 @@ fn test_json() {
null
]
}
-}"#);
+}"#
+ );
}
diff --git a/testing/tests/include.rs b/testing/tests/include.rs
index d2998a1..f474c55 100644
--- a/testing/tests/include.rs
+++ b/testing/tests/include.rs
@@ -12,8 +12,6 @@ struct IncludeTemplate<'a> {
#[test]
fn test_include() {
let strs = vec!["foo", "bar"];
- let s = IncludeTemplate {
- strs: &strs,
- };
+ let s = IncludeTemplate { strs: &strs };
assert_eq!(s.render().unwrap(), "INCLUDED: fooINCLUDED: bar")
}
diff --git a/testing/tests/inheritance.rs b/testing/tests/inheritance.rs
index e9ea9a2..bac9bf5 100644
--- a/testing/tests/inheritance.rs
+++ b/testing/tests/inheritance.rs
@@ -24,5 +24,8 @@ fn test_use_base_directly() {
#[test]
fn test_simple_extends() {
let t = ChildTemplate { _parent: BaseTemplate { title: "Bar" } };
- assert_eq!(t.render().unwrap(), "Bar\n(Bar) Content goes here\nFoo\nCopyright 2017");
+ assert_eq!(
+ t.render().unwrap(),
+ "Bar\n(Bar) Content goes here\nFoo\nCopyright 2017"
+ );
}
diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs
index 3125598..987f26a 100644
--- a/testing/tests/loops.rs
+++ b/testing/tests/loops.rs
@@ -11,9 +11,7 @@ struct ForTemplate<'a> {
#[test]
fn test_for() {
- let s = ForTemplate {
- strings: vec!["A", "alfa", "1"],
- };
+ let s = ForTemplate { strings: vec!["A", "alfa", "1"] };
assert_eq!(s.render().unwrap(), "0. A\n1. alfa\n2. 1\n");
}
@@ -28,8 +26,6 @@ struct NestedForTemplate<'a> {
fn test_nested_for() {
let alpha = vec!["a", "b", "c"];
let numbers = vec!["one", "two"];
- let s = NestedForTemplate {
- seqs: vec![&alpha, &numbers],
- };
+ let s = NestedForTemplate { seqs: vec![&alpha, &numbers] };
assert_eq!(s.render().unwrap(), "1\n 0a1b2c2\n 0one1two");
}
diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs
index 86d32be..8f4b05c 100644
--- a/testing/tests/matches.rs
+++ b/testing/tests/matches.rs
@@ -68,7 +68,7 @@ fn test_match_literal_num() {
enum Color {
Rgb(u32, u32, u32),
GrayScale(u32),
- Cmyk(u32, u32, u32, u32)
+ Cmyk(u32, u32, u32, u32),
}
#[derive(Template)]
diff --git a/testing/tests/operators.rs b/testing/tests/operators.rs
index 625ec29..de51677 100644
--- a/testing/tests/operators.rs
+++ b/testing/tests/operators.rs
@@ -35,10 +35,10 @@ fn test_operators() {
#[derive(Template)]
#[template(path = "precedence.html")]
-struct PrecedenceTemplate { }
+struct PrecedenceTemplate {}
#[test]
fn test_precedence() {
- let t = PrecedenceTemplate { };
+ let t = PrecedenceTemplate {};
assert_eq!(t.render().unwrap(), "6".repeat(7));
}
diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs
index 37027b7..4ed1261 100644
--- a/testing/tests/simple.rs
+++ b/testing/tests/simple.rs
@@ -19,10 +19,13 @@ fn test_variables() {
num: 42,
i18n: "Iñtërnâtiônàlizætiøn".to_string(),
};
- assert_eq!(s.render().unwrap(), "\nhello world, foo\n\
- with number: 42\n\
- Iñtërnâtiônàlizætiøn is important\n\
- in vars too: Iñtërnâtiônàlizætiøn");
+ assert_eq!(
+ s.render().unwrap(),
+ "\nhello world, foo\n\
+ with number: 42\n\
+ Iñtërnâtiônàlizætiøn is important\n\
+ in vars too: Iñtërnâtiônàlizætiøn"
+ );
}
@@ -118,9 +121,7 @@ struct NestedAttrTemplate {
#[test]
fn test_nested_attr() {
- let t = NestedAttrTemplate {
- inner: NestedHolder { holder: Holder { a: 5 } }
- };
+ let t = NestedAttrTemplate { inner: NestedHolder { holder: Holder { a: 5 } } };
assert_eq!(t.render().unwrap(), "5");
}