Skip to content

Commit

Permalink
improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
iganev committed Jul 22, 2024
1 parent 68873d1 commit 5447da5
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ pub(crate) fn create_block<'rc>(param: &PathAndJson<'rc>) -> BlockContext<'rc> {
block
}

pub(crate) fn apply_wrapper(subject: String, wrapper: &str, wrap: bool) -> String {
if wrap {
format!("{}{}{}", wrapper, subject, wrapper)
} else {
subject
}
}

#[derive(Clone, Copy)]
/// Concat helper for handlebars-rust
///
Expand Down Expand Up @@ -188,11 +196,7 @@ impl HelperDef for HandlebarsConcat {
param.value().render()
};

let value = if quotes {
format!("{}{}{}", quotation_mark, value, quotation_mark)
} else {
value
};
let value = apply_wrapper(value, quotation_mark, quotes);

if !value.is_empty() && (!output.contains(&value) || !distinct) {
output.push(value);
Expand All @@ -217,15 +221,11 @@ impl HelperDef for HandlebarsConcat {

rc.pop_block();

if let Ok(out) = content.into_string() {
let result = if quotes {
format!("{}{}{}", quotation_mark, out, quotation_mark)
} else {
out
};
if let Ok(value) = content.into_string() {
let value = apply_wrapper(value, quotation_mark, quotes);

if !result.is_empty() && (!output.contains(&result) || !distinct) {
output.push(result);
if !value.is_empty() && (!output.contains(&value) || !distinct) {
output.push(value);
}
}
}
Expand All @@ -235,11 +235,7 @@ impl HelperDef for HandlebarsConcat {
.iter()
.map(|item| item.render())
.map(|item| {
if quotes {
format!("{}{}{}", quotation_mark, item, quotation_mark)
} else {
item
}
apply_wrapper(item, quotation_mark, quotes)
})
.filter(|item| {
if distinct {
Expand Down Expand Up @@ -271,15 +267,11 @@ impl HelperDef for HandlebarsConcat {

rc.pop_block();

if let Ok(out) = content.into_string() {
let result = if quotes {
format!("{}{}{}", quotation_mark, out, quotation_mark)
} else {
out
};
if let Ok(value) = content.into_string() {
let value = apply_wrapper(value, quotation_mark, quotes);

if !result.is_empty() && (!output.contains(&result) || !distinct) {
output.push(result);
if !value.is_empty() && (!output.contains(&value) || !distinct) {
output.push(value);
}
}
}
Expand All @@ -291,11 +283,7 @@ impl HelperDef for HandlebarsConcat {
.keys()
.cloned()
.map(|item| {
if quotes {
format!("{}{}{}", quotation_mark, item, quotation_mark)
} else {
item
}
apply_wrapper(item, quotation_mark, quotes)
})
.filter(|item| {
if distinct {
Expand Down

0 comments on commit 5447da5

Please sign in to comment.