Browse Source

Add to changelog + rustfmt

index-subcmd
Vincent Prouillet 5 years ago
parent
commit
8942c15428
3 changed files with 36 additions and 15 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +6
    -2
      components/library/src/content/section.rs
  3. +29
    -13
      src/cmd/init.rs

+ 1
- 0
CHANGELOG.md View File

@@ -15,6 +15,7 @@
- Print some counts when running `zola check` - Print some counts when running `zola check`
- Re-render all pages/sections when `anchor-link.html` is changed - Re-render all pages/sections when `anchor-link.html` is changed
- Taxonomies can now have the same name in multiple languages - Taxonomies can now have the same name in multiple languages
- `zola init` can now be create sites inside the current directory


## 0.8.0 (2019-06-22) ## 0.8.0 (2019-06-22)




+ 6
- 2
components/library/src/content/section.rs View File

@@ -395,8 +395,12 @@ Bonjour le monde"#
+++ +++
Bonjour le monde"# Bonjour le monde"#
.to_string(); .to_string();
let res =
Section::parse(Path::new("content/subcontent/_index.fr.md"), &content, &config, &PathBuf::new());
let res = Section::parse(
Path::new("content/subcontent/_index.fr.md"),
&content,
&config,
&PathBuf::new(),
);
assert!(res.is_ok()); assert!(res.is_ok());
let section = res.unwrap(); let section = res.unwrap();
assert_eq!(section.lang, "fr".to_string()); assert_eq!(section.lang, "fr".to_string());


+ 29
- 13
src/cmd/init.rs View File

@@ -31,19 +31,29 @@ pub fn is_directory_quasi_empty(path: &Path) -> Result<bool> {
if path.is_dir() { if path.is_dir() {
let mut entries = match path.read_dir() { let mut entries = match path.read_dir() {
Ok(entries) => entries, Ok(entries) => entries,
Err(e) => { bail!("Could not read `{}` because of error: {}", path.to_string_lossy().to_string(), e); }
Err(e) => {
bail!(
"Could not read `{}` because of error: {}",
path.to_string_lossy().to_string(),
e
);
}
}; };
// If any entry raises an error or isn't hidden (i.e. starts with `.`), we raise an error // If any entry raises an error or isn't hidden (i.e. starts with `.`), we raise an error
if entries.any(|x| match x { if entries.any(|x| match x {
Ok(file) => !file.file_name().to_str().expect("Could not convert filename to &str").starts_with("."),
Err(_) => true
Ok(file) => !file
.file_name()
.to_str()
.expect("Could not convert filename to &str")
.starts_with('.'),
Err(_) => true,
}) { }) {
return Ok(false)
return Ok(false);
} }
return Ok(true)
} else {
return Ok(false)
return Ok(true);
} }

Ok(false)
} }


pub fn create_new_project(name: &str) -> Result<()> { pub fn create_new_project(name: &str) -> Result<()> {
@@ -54,7 +64,10 @@ pub fn create_new_project(name: &str) -> Result<()> {
if name == "." { if name == "." {
bail!("The current directory is not an empty folder (hidden files are ignored)."); bail!("The current directory is not an empty folder (hidden files are ignored).");
} else { } else {
bail!("`{}` is not an empty folder (hidden files are ignored).", path.to_string_lossy().to_string())
bail!(
"`{}` is not an empty folder (hidden files are ignored).",
path.to_string_lossy().to_string()
)
} }
} }
} else { } else {
@@ -96,9 +109,9 @@ pub fn create_new_project(name: &str) -> Result<()> {


#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::env::temp_dir;
use std::fs::{create_dir,remove_dir,remove_dir_all};
use super::*; use super::*;
use std::env::temp_dir;
use std::fs::{create_dir, remove_dir, remove_dir_all};


#[test] #[test]
fn init_empty_directory() { fn init_empty_directory() {
@@ -108,7 +121,8 @@ mod tests {
remove_dir_all(&dir).expect("Could not free test directory"); remove_dir_all(&dir).expect("Could not free test directory");
} }
create_dir(&dir).expect("Could not create test directory"); create_dir(&dir).expect("Could not create test directory");
let allowed = is_directory_quasi_empty(&dir).expect("An error happened reading the directory's contents");
let allowed = is_directory_quasi_empty(&dir)
.expect("An error happened reading the directory's contents");
remove_dir(&dir).unwrap(); remove_dir(&dir).unwrap();
assert_eq!(true, allowed); assert_eq!(true, allowed);
} }
@@ -124,7 +138,8 @@ mod tests {
let mut content = dir.clone(); let mut content = dir.clone();
content.push("content"); content.push("content");
create_dir(&content).unwrap(); create_dir(&content).unwrap();
let allowed = is_directory_quasi_empty(&dir).expect("An error happened reading the directory's contents");
let allowed = is_directory_quasi_empty(&dir)
.expect("An error happened reading the directory's contents");
remove_dir(&content).unwrap(); remove_dir(&content).unwrap();
remove_dir(&dir).unwrap(); remove_dir(&dir).unwrap();
assert_eq!(false, allowed); assert_eq!(false, allowed);
@@ -141,7 +156,8 @@ mod tests {
let mut git = dir.clone(); let mut git = dir.clone();
git.push(".git"); git.push(".git");
create_dir(&git).unwrap(); create_dir(&git).unwrap();
let allowed = is_directory_quasi_empty(&dir).expect("An error happened reading the directory's contents");
let allowed = is_directory_quasi_empty(&dir)
.expect("An error happened reading the directory's contents");
remove_dir(&git).unwrap(); remove_dir(&git).unwrap();
remove_dir(&dir).unwrap(); remove_dir(&dir).unwrap();
assert_eq!(true, allowed); assert_eq!(true, allowed);


Loading…
Cancel
Save