mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Change find_template_from_path() to take Path as start_at argument
This commit is contained in:
parent
7efd70297d
commit
f15da8ba3e
@ -4,7 +4,7 @@ use path;
|
|||||||
use quote::{Tokens, ToTokens};
|
use quote::{Tokens, ToTokens};
|
||||||
|
|
||||||
use std::{cmp, hash, str};
|
use std::{cmp, hash, str};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use syn;
|
use syn;
|
||||||
@ -55,7 +55,7 @@ pub fn generate(ast: &syn::DeriveInput, path: &str, mut nodes: Vec<Node>) -> Str
|
|||||||
fn trait_name_for_path(base: &Option<Expr>, path: &str) -> String {
|
fn trait_name_for_path(base: &Option<Expr>, path: &str) -> String {
|
||||||
let rooted_path = match *base {
|
let rooted_path = match *base {
|
||||||
Some(Expr::StrLit(user_path)) => {
|
Some(Expr::StrLit(user_path)) => {
|
||||||
path::find_template_from_path(user_path, Some(path))
|
path::find_template_from_path(user_path, Some(Path::new(path)))
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
let mut path_buf = PathBuf::new();
|
let mut path_buf = PathBuf::new();
|
||||||
|
@ -22,7 +22,7 @@ pub fn get_template_source(tpl_path: &Path) -> String {
|
|||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_template_from_path<'a>(path: &str, start_at: Option<&str>) -> PathBuf {
|
pub fn find_template_from_path<'a>(path: &str, start_at: Option<&Path>) -> PathBuf {
|
||||||
let root = template_dir();
|
let root = template_dir();
|
||||||
if let Some(rel) = start_at {
|
if let Some(rel) = start_at {
|
||||||
let mut fs_rel_path = root.clone();
|
let mut fs_rel_path = root.clone();
|
||||||
@ -62,25 +62,25 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn find_absolute() {
|
fn find_absolute() {
|
||||||
let path = find_template_from_path("sub/b.html", Some("a.html"));
|
let path = find_template_from_path("sub/b.html", Some(Path::new("a.html")));
|
||||||
assert_eq!(path, Path::new("sub/b.html"));
|
assert_eq!(path, Path::new("sub/b.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn find_relative_nonexistent() {
|
fn find_relative_nonexistent() {
|
||||||
find_template_from_path("b.html", Some("a.html"));
|
find_template_from_path("b.html", Some(Path::new("a.html")));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn find_relative() {
|
fn find_relative() {
|
||||||
let path = find_template_from_path("c.html", Some("sub/b.html"));
|
let path = find_template_from_path("c.html", Some(Path::new("sub/b.html")));
|
||||||
assert_eq!(path, Path::new("sub/c.html"));
|
assert_eq!(path, Path::new("sub/c.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn find_relative_sub() {
|
fn find_relative_sub() {
|
||||||
let path = find_template_from_path("sub1/d.html", Some("sub/b.html"));
|
let path = find_template_from_path("sub1/d.html", Some(Path::new("sub/b.html")));
|
||||||
assert_eq!(path, Path::new("sub/sub1/d.html"));
|
assert_eq!(path, Path::new("sub/sub1/d.html"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user