mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-29 23:57:51 +00:00
templater: extract formatting function from LabelTemplate
This commit is contained in:
parent
4474577ceb
commit
610e310112
1 changed files with 18 additions and 11 deletions
|
@ -169,18 +169,10 @@ where
|
|||
L: TemplateProperty<Output = Vec<String>>,
|
||||
{
|
||||
fn format(&self, formatter: &mut TemplateFormatter) -> io::Result<()> {
|
||||
let labels = match self.labels.extract() {
|
||||
Ok(labels) => labels,
|
||||
Err(err) => return formatter.handle_error(err),
|
||||
};
|
||||
for label in &labels {
|
||||
formatter.push_label(label)?;
|
||||
match self.labels.extract() {
|
||||
Ok(labels) => format_labeled(formatter, &self.content, &labels),
|
||||
Err(err) => formatter.handle_error(err),
|
||||
}
|
||||
self.content.format(formatter)?;
|
||||
for _label in &labels {
|
||||
formatter.pop_label()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -748,6 +740,21 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn format_labeled<T: Template + ?Sized>(
|
||||
formatter: &mut TemplateFormatter,
|
||||
content: &T,
|
||||
labels: &[String],
|
||||
) -> io::Result<()> {
|
||||
for label in labels {
|
||||
formatter.push_label(label)?;
|
||||
}
|
||||
content.format(formatter)?;
|
||||
for _label in labels {
|
||||
formatter.pop_label()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
type PropertyErrorHandler = fn(&mut dyn Formatter, TemplatePropertyError) -> io::Result<()>;
|
||||
|
||||
/// Prints property evaluation error as inline template output.
|
||||
|
|
Loading…
Reference in a new issue