Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Prouillet committed Oct 31, 2018
1 parent 8586bc1 commit b7ce4e5
Show file tree
Hide file tree
Showing 52 changed files with 1,420 additions and 1,093 deletions.
10 changes: 5 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ include!("src/cli.rs");

fn main() {
// disabled below as it fails in CI
// let mut app = build_cli();
// app.gen_completions("zola", Shell::Bash, "completions/");
// app.gen_completions("zola", Shell::Fish, "completions/");
// app.gen_completions("zola", Shell::Zsh, "completions/");
// app.gen_completions("zola", Shell::PowerShell, "completions/");
// let mut app = build_cli();
// app.gen_completions("zola", Shell::Bash, "completions/");
// app.gen_completions("zola", Shell::Fish, "completions/");
// app.gen_completions("zola", Shell::Zsh, "completions/");
// app.gen_completions("zola", Shell::PowerShell, "completions/");
}
8 changes: 4 additions & 4 deletions components/config/examples/generate_sublime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! Although it is a valid example for serializing syntaxes, you probably won't need
//! to do this yourself unless you want to cache your own compiled grammars.
extern crate syntect;
use syntect::parsing::SyntaxSetBuilder;
use syntect::highlighting::ThemeSet;
use syntect::dumps::*;
use std::env;
use syntect::dumps::*;
use syntect::highlighting::ThemeSet;
use syntect::parsing::SyntaxSetBuilder;

fn usage_and_exit() -> ! {
println!("USAGE: cargo run --example generate_sublime synpack source-dir newlines.packdump nonewlines.packdump\n
Expand All @@ -32,7 +32,7 @@ fn main() {
println!("- {} -> {:?}", s.name, s.file_extensions);
}
}
},
}
(Some(ref cmd), Some(ref theme_dir), Some(ref packpath)) if cmd == "themepack" => {
let ts = ThemeSet::load_from_folder(theme_dir).unwrap();
for path in ts.themes.keys() {
Expand Down
49 changes: 9 additions & 40 deletions components/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ impl Taxonomy {

impl Default for Taxonomy {
fn default() -> Taxonomy {
Taxonomy {
name: String::new(),
paginate_by: None,
paginate_path: None,
rss: false,
}
Taxonomy { name: String::new(), paginate_by: None, paginate_path: None, rss: false }
}
}

Expand Down Expand Up @@ -137,19 +132,12 @@ impl Config {
for pat in &config.ignored_content {
let glob = match Glob::new(pat) {
Ok(g) => g,
Err(e) => bail!(
"Invalid ignored_content glob pattern: {}, error = {}",
pat,
e
),
Err(e) => bail!("Invalid ignored_content glob pattern: {}, error = {}", pat, e),
};
glob_set_builder.add(glob);
}
config.ignored_content_globset = Some(
glob_set_builder
.build()
.expect("Bad ignored_content in config file."),
);
config.ignored_content_globset =
Some(glob_set_builder.build().expect("Bad ignored_content in config file."));
}

Ok(config)
Expand All @@ -162,10 +150,7 @@ impl Config {
let file_name = path.file_name().unwrap();
File::open(path)
.chain_err(|| {
format!(
"No `{:?}` file found. Are you in the right directory?",
file_name
)
format!("No `{:?}` file found. Are you in the right directory?", file_name)
})?
.read_to_string(&mut content)?;

Expand Down Expand Up @@ -217,16 +202,12 @@ impl Config {
let original = self.extra.clone();
// 2. inject theme extra values
for (key, val) in &theme.extra {
self.extra
.entry(key.to_string())
.or_insert_with(|| val.clone());
self.extra.entry(key.to_string()).or_insert_with(|| val.clone());
}

// 3. overwrite with original config
for (key, val) in &original {
self.extra
.entry(key.to_string())
.or_insert_with(|| val.clone());
self.extra.entry(key.to_string()).or_insert_with(|| val.clone());
}

Ok(())
Expand Down Expand Up @@ -316,16 +297,7 @@ hello = "world"

let config = Config::parse(config);
assert!(config.is_ok());
assert_eq!(
config
.unwrap()
.extra
.get("hello")
.unwrap()
.as_str()
.unwrap(),
"world"
);
assert_eq!(config.unwrap().extra.get("hello").unwrap().as_str().unwrap(), "world");
}

#[test]
Expand Down Expand Up @@ -360,10 +332,7 @@ hello = "world"
fn can_make_url_with_localhost() {
let mut config = Config::default();
config.base_url = "http://127.0.0.1:1111".to_string();
assert_eq!(
config.make_permalink("/tags/rust"),
"http://127.0.0.1:1111/tags/rust/"
);
assert_eq!(config.make_permalink("/tags/rust"), "http://127.0.0.1:1111/tags/rust/");
}

// https://github.com/Keats/gutenberg/issues/486
Expand Down
15 changes: 8 additions & 7 deletions components/config/src/highlighting.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use syntect::dumps::from_binary;
use syntect::parsing::SyntaxSet;
use syntect::highlighting::ThemeSet;
use syntect::easy::HighlightLines;
use syntect::highlighting::ThemeSet;
use syntect::parsing::SyntaxSet;

use Config;


lazy_static! {
pub static ref SYNTAX_SET: SyntaxSet = {
let ss: SyntaxSet = from_binary(include_bytes!("../../../sublime_syntaxes/newlines.packdump"));
let ss: SyntaxSet =
from_binary(include_bytes!("../../../sublime_syntaxes/newlines.packdump"));
ss
};

pub static ref THEME_SET: ThemeSet = from_binary(include_bytes!("../../../sublime_themes/all.themedump"));
pub static ref THEME_SET: ThemeSet =
from_binary(include_bytes!("../../../sublime_themes/all.themedump"));
}

/// Returns the highlighter and whether it was found in the extra or not
Expand All @@ -21,7 +21,8 @@ pub fn get_highlighter<'a>(info: &str, config: &Config) -> (HighlightLines<'a>,
let mut in_extra = false;

if let Some(ref lang) = info.split(' ').next() {
let syntax = SYNTAX_SET.find_syntax_by_token(lang)
let syntax = SYNTAX_SET
.find_syntax_by_token(lang)
.or_else(|| {
if let Some(ref extra) = config.extra_syntax_set {
let s = extra.find_syntax_by_token(lang);
Expand Down
3 changes: 1 addition & 2 deletions components/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ extern crate globset;
extern crate lazy_static;
extern crate syntect;


mod config;
mod theme;
pub mod highlighting;
mod theme;
pub use config::{Config, Taxonomy};

use std::path::Path;
Expand Down
10 changes: 4 additions & 6 deletions components/config/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use toml::Value as Toml;

use errors::{Result, ResultExt};


/// Holds the data from a `theme.toml` file.
/// There are other fields than `extra` in it but Zola
/// itself doesn't care about them.
Expand Down Expand Up @@ -36,19 +35,18 @@ impl Theme {
bail!("Expected the `theme.toml` to be a TOML table")
}


Ok(Theme { extra })
}

/// Parses a theme file from the given path
pub fn from_file(path: &PathBuf) -> Result<Theme> {
let mut content = String::new();
File::open(path)
.chain_err(||
.chain_err(|| {
"No `theme.toml` file found. \
Is the `theme` defined in your `config.toml present in the `themes` directory \
and does it have a `theme.toml` inside?"
)?
Is the `theme` defined in your `config.toml present in the `themes` directory \
and does it have a `theme.toml` inside?"
})?
.read_to_string(&mut content)?;

Theme::parse(&content)
Expand Down
4 changes: 2 additions & 2 deletions components/errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#[macro_use]
extern crate error_chain;
extern crate tera;
extern crate toml;
extern crate image;
extern crate syntect;
extern crate tera;
extern crate toml;

error_chain! {
errors {}
Expand Down
36 changes: 22 additions & 14 deletions components/front_matter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
extern crate lazy_static;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate toml;
extern crate chrono;
extern crate regex;
extern crate serde;
extern crate tera;
extern crate chrono;
extern crate toml;

#[macro_use]
extern crate errors;

use std::path::Path;
use regex::Regex;
use errors::{Result, ResultExt};
use regex::Regex;
use std::path::Path;

mod page;
mod section;
Expand All @@ -22,7 +22,8 @@ pub use page::PageFrontMatter;
pub use section::SectionFrontMatter;

lazy_static! {
static ref PAGE_RE: Regex = Regex::new(r"^[[:space:]]*\+\+\+\r?\n((?s).*?(?-s))\+\+\+\r?\n?((?s).*(?-s))$").unwrap();
static ref PAGE_RE: Regex =
Regex::new(r"^[[:space:]]*\+\+\+\r?\n((?s).*?(?-s))\+\+\+\r?\n?((?s).*(?-s))$").unwrap();
}

#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
Expand All @@ -44,12 +45,14 @@ pub enum InsertAnchor {
None,
}


/// Split a file between the front matter and its content
/// Will return an error if the front matter wasn't found
fn split_content(file_path: &Path, content: &str) -> Result<(String, String)> {
if !PAGE_RE.is_match(content) {
bail!("Couldn't find front matter in `{}`. Did you forget to add `+++`?", file_path.to_string_lossy());
bail!(
"Couldn't find front matter in `{}`. Did you forget to add `+++`?",
file_path.to_string_lossy()
);
}

// 2. extract the front matter and the content
Expand All @@ -62,27 +65,32 @@ fn split_content(file_path: &Path, content: &str) -> Result<(String, String)> {

/// Split a file between the front matter and its content.
/// Returns a parsed `SectionFrontMatter` and the rest of the content
pub fn split_section_content(file_path: &Path, content: &str) -> Result<(SectionFrontMatter, String)> {
pub fn split_section_content(
file_path: &Path,
content: &str,
) -> Result<(SectionFrontMatter, String)> {
let (front_matter, content) = split_content(file_path, content)?;
let meta = SectionFrontMatter::parse(&front_matter)
.chain_err(|| format!("Error when parsing front matter of section `{}`", file_path.to_string_lossy()))?;
let meta = SectionFrontMatter::parse(&front_matter).chain_err(|| {
format!("Error when parsing front matter of section `{}`", file_path.to_string_lossy())
})?;
Ok((meta, content))
}

/// Split a file between the front matter and its content
/// Returns a parsed `PageFrontMatter` and the rest of the content
pub fn split_page_content(file_path: &Path, content: &str) -> Result<(PageFrontMatter, String)> {
let (front_matter, content) = split_content(file_path, content)?;
let meta = PageFrontMatter::parse(&front_matter)
.chain_err(|| format!("Error when parsing front matter of page `{}`", file_path.to_string_lossy()))?;
let meta = PageFrontMatter::parse(&front_matter).chain_err(|| {
format!("Error when parsing front matter of page `{}`", file_path.to_string_lossy())
})?;
Ok((meta, content))
}

#[cfg(test)]
mod tests {
use std::path::Path;

use super::{split_section_content, split_page_content};
use super::{split_page_content, split_section_content};

#[test]
fn can_split_page_content_valid() {
Expand Down
Loading

0 comments on commit b7ce4e5

Please sign in to comment.