Skip to content

convert dirs from list of strings to list of pathbufs #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ pub struct FileSystemLoader {
}

impl FileSystemLoader {
pub fn new(dirs: Vec<String>, encoding: &'static Encoding) -> Self {
Self {
dirs: dirs.iter().map(PathBuf::from).collect(),
encoding,
}
pub fn new(dirs: Vec<PathBuf>, encoding: &'static Encoding) -> Self {
Self { dirs, encoding }
}

pub fn from_pathbuf(dirs: Vec<PathBuf>, encoding: &'static Encoding) -> Self {
Expand Down Expand Up @@ -286,7 +283,7 @@ mod tests {
Python::with_gil(|py| {
let engine = EngineData::empty();
let loader =
FileSystemLoader::new(vec!["tests/templates".to_string()], encoding_rs::UTF_8);
FileSystemLoader::new(vec![PathBuf::from("tests/templates")], encoding_rs::UTF_8);
let template = loader
.get_template(py, "basic.txt", &engine)
.unwrap()
Expand All @@ -305,7 +302,7 @@ mod tests {
Python::with_gil(|py| {
let engine = EngineData::empty();
let loader =
FileSystemLoader::new(vec!["tests/templates".to_string()], encoding_rs::UTF_8);
FileSystemLoader::new(vec![PathBuf::from("tests/templates")], encoding_rs::UTF_8);
let error = loader.get_template(py, "missing.txt", &engine).unwrap_err();

let mut expected = std::env::current_dir().unwrap();
Expand All @@ -329,7 +326,7 @@ mod tests {
Python::with_gil(|py| {
let engine = EngineData::empty();
let loader =
FileSystemLoader::new(vec!["tests/templates".to_string()], encoding_rs::UTF_8);
FileSystemLoader::new(vec![PathBuf::from("tests/templates")], encoding_rs::UTF_8);
let error = loader
.get_template(py, "invalid.txt", &engine)
.unwrap()
Expand Down Expand Up @@ -364,7 +361,7 @@ mod tests {

// Create a FileSystemLoader for the CachedLoader
let filesystem_loader =
FileSystemLoader::new(vec!["tests/templates".to_string()], encoding_rs::UTF_8);
FileSystemLoader::new(vec![PathBuf::from("tests/templates")], encoding_rs::UTF_8);

// Wrap the FileSystemLoader in a CachedLoader
let mut cached_loader = CachedLoader::new(vec![Loader::FileSystem(filesystem_loader)]);
Expand Down Expand Up @@ -407,7 +404,7 @@ mod tests {
Python::with_gil(|py| {
let engine = EngineData::empty();
let filesystem_loader =
FileSystemLoader::new(vec!["tests/templates".to_string()], encoding_rs::UTF_8);
FileSystemLoader::new(vec![PathBuf::from("tests/templates")], encoding_rs::UTF_8);

let mut cached_loader = CachedLoader::new(vec![Loader::FileSystem(filesystem_loader)]);
let error = cached_loader
Expand Down Expand Up @@ -444,7 +441,7 @@ mod tests {
Python::with_gil(|py| {
let engine = EngineData::empty();
let filesystem_loader =
FileSystemLoader::new(vec!["tests/templates".to_string()], encoding_rs::UTF_8);
FileSystemLoader::new(vec![PathBuf::from("tests/templates")], encoding_rs::UTF_8);

let mut cached_loader = CachedLoader::new(vec![Loader::FileSystem(filesystem_loader)]);
let error = cached_loader
Expand Down
2 changes: 1 addition & 1 deletion src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub mod django_rusty_templates {

#[pyclass]
pub struct Engine {
dirs: Vec<String>,
dirs: Vec<PathBuf>,
app_dirs: bool,
context_processors: Vec<String>,
debug: bool,
Expand Down
3 changes: 2 additions & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -21,7 +22,7 @@
},
{
"BACKEND": "django_rusty_templates.RustyTemplates",
"DIRS": ["tests/templates"],
"DIRS": ["tests/templates", Path(BASE_DIR) / "templates"],
"NAME": "rusty",
"OPTIONS": {
"libraries": {
Expand Down