Skip to content

Commit

Permalink
fixup! feat: add datetime, random, error in tera.rs
Browse files Browse the repository at this point in the history
Removed because `tera` supports `now`.
  • Loading branch information
erickguan committed Sep 15, 2024
1 parent 6f78d55 commit 95f8abf
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/tera.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};

use chrono::{Local, Utc};
use heck::{
ToKebabCase, ToLowerCamelCase, ToShoutyKebabCase, ToShoutySnakeCase, ToSnakeCase,
ToUpperCamelCase,
Expand Down Expand Up @@ -110,28 +109,6 @@ pub fn get_tera(dir: Option<&Path>) -> Tera {
}
},
);
tera.register_function(
"datetime",
move |args: &HashMap<String, Value>| -> tera::Result<Value> {
let format = match args.get("format") {
Some(Value::String(format)) => format,
_ => "%+",
};
let result = Local::now().format(format).to_string();
Ok(Value::String(result))
},
);
tera.register_function(
"datetime_utc",
move |args: &HashMap<String, Value>| -> tera::Result<Value> {
let format = match args.get("format") {
Some(Value::String(format)) => format,
_ => "%+",
};
let result = Utc::now().format(format).to_string();
Ok(Value::String(result))
},
);
tera.register_filter(
"hash_file",
move |input: &Value, args: &HashMap<String, Value>| match input {
Expand Down Expand Up @@ -346,7 +323,6 @@ pub fn get_tera(dir: Option<&Path>) -> Tera {
mod tests {
use super::*;
use crate::test::reset;
use chrono::Datelike;
use insta::assert_snapshot;

#[test]
Expand Down Expand Up @@ -466,20 +442,6 @@ mod tests {
assert_eq!(result.trim().len(), 8);
}

#[test]
fn test_datetime() {
reset();
let result = render("{{datetime(format=\"%Y\")}}");
assert_eq!(result, Local::now().year().to_string());
}

#[test]
fn test_datetime_utc() {
reset();
let result = render("{{datetime_utc(format=\"%m\")}}");
assert_eq!(result, format!("{:0>2}", Utc::now().month().to_string()));
}

#[test]
fn test_quote() {
reset();
Expand Down

0 comments on commit 95f8abf

Please sign in to comment.