forked from mirrors/jj
templater: implement list methods for unformattable property
This commit is contained in:
parent
a0be6a5a11
commit
9065b94dc1
2 changed files with 28 additions and 5 deletions
|
@ -65,9 +65,13 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo, '_> {
|
|||
build_commit_or_change_id_method(self, build_ctx, property, function)
|
||||
}
|
||||
CommitTemplatePropertyKind::CommitOrChangeIdList(property) => {
|
||||
template_builder::build_list_method(self, build_ctx, property, function, |item| {
|
||||
self.wrap_commit_or_change_id(item)
|
||||
})
|
||||
template_builder::build_formattable_list_method(
|
||||
self,
|
||||
build_ctx,
|
||||
property,
|
||||
function,
|
||||
|item| self.wrap_commit_or_change_id(item),
|
||||
)
|
||||
}
|
||||
CommitTemplatePropertyKind::ShortestIdPrefix(property) => {
|
||||
build_shortest_id_prefix_method(self, build_ctx, property, function)
|
||||
|
|
|
@ -285,7 +285,7 @@ pub fn build_core_method<'a, L: TemplateLanguage<'a>>(
|
|||
build_string_method(language, build_ctx, property, function)
|
||||
}
|
||||
CoreTemplatePropertyKind::StringList(property) => {
|
||||
build_list_method(language, build_ctx, property, function, |item| {
|
||||
build_formattable_list_method(language, build_ctx, property, function, |item| {
|
||||
language.wrap_string(item)
|
||||
})
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ fn build_list_template_method<'a, L: TemplateLanguage<'a>>(
|
|||
}
|
||||
|
||||
/// Builds method call expression for printable list property.
|
||||
pub fn build_list_method<'a, L, O>(
|
||||
pub fn build_formattable_list_method<'a, L, O>(
|
||||
language: &L,
|
||||
build_ctx: &BuildContext<L::Property>,
|
||||
self_property: impl TemplateProperty<L::Context, Output = Vec<O>> + 'a,
|
||||
|
@ -523,6 +523,25 @@ where
|
|||
Ok(property)
|
||||
}
|
||||
|
||||
pub fn build_unformattable_list_method<'a, L, O>(
|
||||
language: &L,
|
||||
build_ctx: &BuildContext<L::Property>,
|
||||
self_property: impl TemplateProperty<L::Context, Output = Vec<O>> + 'a,
|
||||
function: &FunctionCallNode,
|
||||
wrap_item: impl Fn(PropertyPlaceholder<O>) -> L::Property,
|
||||
) -> TemplateParseResult<L::Property>
|
||||
where
|
||||
L: TemplateLanguage<'a>,
|
||||
O: Clone + 'a,
|
||||
{
|
||||
let property = match function.name {
|
||||
// No "join"
|
||||
"map" => build_map_operation(language, build_ctx, self_property, function, wrap_item)?,
|
||||
_ => return Err(TemplateParseError::no_such_method("List", function)),
|
||||
};
|
||||
Ok(property)
|
||||
}
|
||||
|
||||
/// Builds expression that extracts iterable property and applies template to
|
||||
/// each item.
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue