Skip to content

Commit

Permalink
refactor(case): replace custom func with heck
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygwilliams committed Jul 27, 2018
1 parent a2320b5 commit 3bfc5ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Expand Up @@ -85,7 +85,7 @@ main!(|_cli: Cli| {
git::create(&project_dir, args)?;
git::remove_history(&project_dir)?;

let template = template::substitute(&name.kebab_case)?;
let template = template::substitute(&name)?;

let pbar = progressbar::new();
pbar.tick();
Expand Down
14 changes: 7 additions & 7 deletions src/template.rs
Expand Up @@ -3,6 +3,7 @@ use console::style;
use emoji;
use indicatif::ProgressBar;
use liquid;
use projectname::ProjectName;
use quicli::prelude::*;
use std::fs;
use std::path::PathBuf;
Expand All @@ -12,12 +13,15 @@ fn engine() -> liquid::Parser {
liquid::ParserBuilder::new().build()
}

pub fn substitute(name: &str) -> Result<liquid::Object> {
pub fn substitute(name: &ProjectName) -> Result<liquid::Object> {
let mut template = liquid::Object::new();
template.insert(String::from("project-name"), liquid::Value::scalar(name));
template.insert(
String::from("project-name"),
liquid::Value::scalar(&name.kebab_case),
);
template.insert(
String::from("crate_name"),
liquid::Value::scalar(&hyphen_to_lodash(name)),
liquid::Value::scalar(&name.snake_case),
);
template.insert(
String::from("authors"),
Expand All @@ -26,10 +30,6 @@ pub fn substitute(name: &str) -> Result<liquid::Object> {
Ok(template)
}

fn hyphen_to_lodash(string: &str) -> String {
string.to_string().replace("-", "_")
}

pub fn walk_dir(project_dir: &PathBuf, template: liquid::Object, pbar: ProgressBar) -> Result<()> {
let engine = engine();
for entry in WalkDir::new(project_dir) {
Expand Down

0 comments on commit 3bfc5ee

Please sign in to comment.