Fix #11 and Cleanup dependencies

This commit is contained in:
Jai A
2020-06-26 22:35:20 -07:00
parent 6e301601f9
commit 8540e09ba7
5 changed files with 60 additions and 10 deletions

36
src/helpers/equals.rs Normal file
View File

@@ -0,0 +1,36 @@
use handlebars::*;
#[derive(Clone, Copy)]
pub struct EqualsHelper;
impl HelperDef for EqualsHelper {
fn call<'reg: 'rc, 'rc>(
&self,
h: &Helper<'reg, 'rc>,
r: &'reg Handlebars<'_>,
ctx: &'rc Context,
rc: &mut RenderContext<'reg, 'rc>,
out: &mut dyn Output,
) -> HelperResult {
let a = h
.param(0)
.map(|v| v.value().as_object().unwrap())
.ok_or_else(|| RenderError::new("Parameter not found!"))?;
let b = h
.param(1)
.map(|v| v.value().as_object().unwrap())
.ok_or_else(|| RenderError::new("Parameter not found!"))?;
let tmpl = if a == b {
h.template()
} else {
h.inverse()
};
match tmpl {
Some(ref t) => t.render(r, ctx, rc, out),
None => Ok(()),
}
}
}

View File

@@ -1,8 +1,13 @@
mod contains;
mod format_human;
mod equals;
use handlebars::*;
pub fn register_helpers(handlebars: &mut Handlebars) {
handlebars.register_helper("contains", Box::new(contains::ContainsHelper));
handlebars.register_helper("format", Box::new(format_human::HumanFormatHelper));
//This helper is not used yet, but could be useful in many circumstances
handlebars.register_helper("equals", Box::new(equals::EqualsHelper));
}

View File

@@ -9,6 +9,9 @@ use std::collections::{HashMap, VecDeque};
use std::error::Error;
use crate::database::*;
use futures_timer::Delay;
use futures::TryFutureExt;
use std::time::Duration;
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
@@ -175,10 +178,10 @@ TODO This method needs a lot of refactoring. Here's a list of changes that need
- Remove code fragment duplicates
*/
pub async fn index_mods(client: mongodb::Client) -> Result<(), Box<dyn Error>>{
pub async fn index_mods(db: mongodb::Client) -> Result<(), Box<dyn Error>>{
let mut docs_to_add: Vec<SearchMod> = vec![];
docs_to_add.append(&mut index_database(client).await?);
docs_to_add.append(&mut index_database(db.clone()).await?);
//docs_to_add.append(&mut index_curseforge(1, 400000).await?);
//Write Indexes