From eb4f10b0f69c5417e574d51b57a4428712e6a2ad Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 5 Oct 2018 16:08:56 +0200 Subject: Reorder code for better readability --- askama_shared/src/lib.rs | 96 ++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'askama_shared/src') diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index 46efea0..ab26646 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -29,54 +29,6 @@ pub struct Config<'a> { pub default_syntax: &'a str, } -#[derive(Debug)] -pub struct Syntax<'a> { - pub block_start: &'a str, - pub block_end: &'a str, - pub expr_start: &'a str, - pub expr_end: &'a str, - pub comment_start: &'a str, - pub comment_end: &'a str, -} - -impl<'a> Default for Syntax<'a> { - fn default() -> Self { - Self { - block_start: "{%", - block_end: "%}", - expr_start: "{{", - expr_end: "}}", - comment_start: "{#", - comment_end: "#}", - } - } -} - -impl<'a> From> for Syntax<'a> { - fn from(raw: RawSyntax<'a>) -> Self { - let syntax = Self::default(); - Self { - block_start: raw.block_start.unwrap_or(syntax.block_start), - block_end: raw.block_end.unwrap_or(syntax.block_end), - expr_start: raw.expr_start.unwrap_or(syntax.expr_start), - expr_end: raw.expr_end.unwrap_or(syntax.expr_end), - comment_start: raw.comment_start.unwrap_or(syntax.comment_start), - comment_end: raw.comment_end.unwrap_or(syntax.comment_end), - } - } -} - -pub fn read_config_file() -> String { - let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); - let filename = root.join(CONFIG_FILE_NAME); - if filename.exists() { - fs::read_to_string(&filename) - .expect(&format!("unable to read {}", filename.to_str().unwrap())) - } else { - "".to_string() - } -} - impl<'a> Config<'a> { pub fn new(s: &str) -> Config { let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); @@ -144,6 +96,43 @@ impl<'a> Config<'a> { } } +#[derive(Debug)] +pub struct Syntax<'a> { + pub block_start: &'a str, + pub block_end: &'a str, + pub expr_start: &'a str, + pub expr_end: &'a str, + pub comment_start: &'a str, + pub comment_end: &'a str, +} + +impl<'a> Default for Syntax<'a> { + fn default() -> Self { + Self { + block_start: "{%", + block_end: "%}", + expr_start: "{{", + expr_end: "}}", + comment_start: "{#", + comment_end: "#}", + } + } +} + +impl<'a> From> for Syntax<'a> { + fn from(raw: RawSyntax<'a>) -> Self { + let syntax = Self::default(); + Self { + block_start: raw.block_start.unwrap_or(syntax.block_start), + block_end: raw.block_end.unwrap_or(syntax.block_end), + expr_start: raw.expr_start.unwrap_or(syntax.expr_start), + expr_end: raw.expr_end.unwrap_or(syntax.expr_end), + comment_start: raw.comment_start.unwrap_or(syntax.comment_start), + comment_end: raw.comment_end.unwrap_or(syntax.comment_end), + } + } +} + #[derive(Deserialize)] struct RawConfig<'d> { general: Option, @@ -167,6 +156,17 @@ struct RawSyntax<'a> { comment_end: Option<&'a str>, } +pub fn read_config_file() -> String { + let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); + let filename = root.join(CONFIG_FILE_NAME); + if filename.exists() { + fs::read_to_string(&filename) + .expect(&format!("unable to read {}", filename.to_str().unwrap())) + } else { + "".to_string() + } +} + static CONFIG_FILE_NAME: &str = "askama.toml"; static DEFAULT_SYNTAX_NAME: &str = "default"; -- cgit