Also render diff of title
This commit is contained in:
parent
2042e5e7fe
commit
9cb3da86e2
2 changed files with 21 additions and 8 deletions
|
@ -185,14 +185,15 @@ impl Resource for DiffResource {
|
||||||
#[derive(BartDisplay)]
|
#[derive(BartDisplay)]
|
||||||
#[template = "templates/diff.html"]
|
#[template = "templates/diff.html"]
|
||||||
struct Template<'a> {
|
struct Template<'a> {
|
||||||
lines: &'a [DiffLine<'a>],
|
title: &'a [Diff<char>],
|
||||||
|
lines: &'a [Diff<&'a str>],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct DiffLine<'a> {
|
struct Diff<T: fmt::Display> {
|
||||||
removed: Option<&'a str>,
|
removed: Option<T>,
|
||||||
same: Option<&'a str>,
|
same: Option<T>,
|
||||||
added: Option<&'a str>,
|
added: Option<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
let from = self.get_article_revision(&self.from);
|
let from = self.get_article_revision(&self.from);
|
||||||
|
@ -207,15 +208,26 @@ impl Resource for DiffResource {
|
||||||
base: None, // Hmm, should perhaps accept `base` as argument
|
base: None, // Hmm, should perhaps accept `base` as argument
|
||||||
title: "Difference",
|
title: "Difference",
|
||||||
body: &Template {
|
body: &Template {
|
||||||
|
title: &diff::chars(
|
||||||
|
from.as_ref().map(|x| &*x.title).unwrap_or(""),
|
||||||
|
to.as_ref().map(|x| &*x.title).unwrap_or("")
|
||||||
|
)
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| match x {
|
||||||
|
diff::Result::Left(x) => Diff { removed: Some(x), ..Default::default() },
|
||||||
|
diff::Result::Both(x, _) => Diff { same: Some(x), ..Default::default() },
|
||||||
|
diff::Result::Right(x) => Diff { added: Some(x), ..Default::default() },
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
lines: &diff::lines(
|
lines: &diff::lines(
|
||||||
from.as_ref().map(|x| &*x.body).unwrap_or(""),
|
from.as_ref().map(|x| &*x.body).unwrap_or(""),
|
||||||
to.as_ref().map(|x| &*x.body).unwrap_or("")
|
to.as_ref().map(|x| &*x.body).unwrap_or("")
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| match x {
|
.map(|x| match x {
|
||||||
diff::Result::Left(x) => DiffLine { removed: Some(x), ..Default::default() },
|
diff::Result::Left(x) => Diff { removed: Some(x), ..Default::default() },
|
||||||
diff::Result::Both(x, _) => DiffLine { same: Some(x), ..Default::default() },
|
diff::Result::Both(x, _) => Diff { same: Some(x), ..Default::default() },
|
||||||
diff::Result::Right(x) => DiffLine { added: Some(x), ..Default::default() },
|
diff::Result::Right(x) => Diff { added: Some(x), ..Default::default() },
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<header>
|
<header>
|
||||||
<h1>Diff</h1>
|
<h1>Diff</h1>
|
||||||
|
<h1>{{#title}}{{#.removed}}<span class="removed">{{.}}</span>{{/.removed}}{{#.same}}{{.}}{{/.same}}{{#.added}}<span class="added">{{.}}</span>{{/.added}}{{/title}}</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<article>
|
<article>
|
||||||
|
|
Loading…
Reference in a new issue