diff --git a/src/template_builder.rs b/src/template_builder.rs index bf584d265..5ddc9270c 100644 --- a/src/template_builder.rs +++ b/src/template_builder.rs @@ -20,9 +20,9 @@ use crate::template_parser::{ TemplateParseResult, }; use crate::templater::{ - ConcatTemplate, ConditionalTemplate, FormattablePropertyListTemplate, IntoTemplate, - LabelTemplate, Literal, PlainTextFormattedProperty, ReformatTemplate, SeparateTemplate, - Template, TemplateFunction, TemplateProperty, TimestampRange, + ConcatTemplate, ConditionalTemplate, IntoTemplate, LabelTemplate, ListPropertyTemplate, + Literal, PlainTextFormattedProperty, ReformatTemplate, SeparateTemplate, Template, + TemplateFunction, TemplateProperty, TimestampRange, }; use crate::{text_util, time_util}; @@ -444,7 +444,10 @@ pub fn build_list_method<'a, L: TemplateLanguage<'a>, P: Template<()> + 'a>( "join" => { let [separator_node] = template_parser::expect_exact_arguments(function)?; let separator = build_expression(language, separator_node)?.into_template(); - let template = FormattablePropertyListTemplate::new(self_property, separator); + let template = + ListPropertyTemplate::new(self_property, separator, |_, formatter, item| { + item.format(&(), formatter) + }); language.wrap_template(template) } // TODO: .map() diff --git a/src/templater.rs b/src/templater.rs index ea9e462d4..1d10727ab 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -366,36 +366,38 @@ impl> TemplateProperty for PlainTextFormattedProperty { } } -/// Renders a list of template properties with the given separator. +/// Renders template property of list type with the given separator. /// -/// Each template property can be extracted as a context-less value, but -/// the separator takes a context of type `C`. -pub struct FormattablePropertyListTemplate { +/// Each list item will be formatted by the given `format_item()` function. +/// The separator takes a context of type `C`. +pub struct ListPropertyTemplate { property: P, separator: S, + format_item: F, } -impl FormattablePropertyListTemplate { - pub fn new(property: P, separator: S) -> Self +impl ListPropertyTemplate { + pub fn new(property: P, separator: S, format_item: F) -> Self where P: TemplateProperty, - P::Output: IntoIterator, - ::Item: Template<()>, + P::Output: IntoIterator, S: Template, + F: Fn(&C, &mut dyn Formatter, O) -> io::Result<()>, { - FormattablePropertyListTemplate { + ListPropertyTemplate { property, separator, + format_item, } } } -impl Template for FormattablePropertyListTemplate +impl Template for ListPropertyTemplate where P: TemplateProperty, - P::Output: IntoIterator, - ::Item: Template<()>, + P::Output: IntoIterator, S: Template, + F: Fn(&C, &mut dyn Formatter, O) -> io::Result<()>, { fn format(&self, context: &C, formatter: &mut dyn Formatter) -> io::Result<()> { let contents = self.property.extract(context); @@ -404,7 +406,7 @@ where formatter, contents, &self.separator, - |_, formatter, item| item.format(&(), formatter), + &self.format_item, ) } }