aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-10-05 16:08:56 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-10-07 07:37:46 +0200
commiteb4f10b0f69c5417e574d51b57a4428712e6a2ad (patch)
treefaab40d896a06a5437905a4c02b5957b5dfe1047 /askama_shared
parent52bdd4b2792093616b83b9cd216e8e691d68f5e4 (diff)
downloadaskama-eb4f10b0f69c5417e574d51b57a4428712e6a2ad.tar.gz
askama-eb4f10b0f69c5417e574d51b57a4428712e6a2ad.tar.bz2
askama-eb4f10b0f69c5417e574d51b57a4428712e6a2ad.zip
Reorder code for better readability
Diffstat (limited to '')
-rw-r--r--askama_shared/src/lib.rs96
1 files changed, 48 insertions, 48 deletions
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<RawSyntax<'a>> 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<RawSyntax<'a>> 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<General>,
@@ -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";