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)]
|
||||
#[template = "templates/diff.html"]
|
||||
struct Template<'a> {
|
||||
lines: &'a [DiffLine<'a>],
|
||||
title: &'a [Diff<char>],
|
||||
lines: &'a [Diff<&'a str>],
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct DiffLine<'a> {
|
||||
removed: Option<&'a str>,
|
||||
same: Option<&'a str>,
|
||||
added: Option<&'a str>,
|
||||
struct Diff<T: fmt::Display> {
|
||||
removed: Option<T>,
|
||||
same: Option<T>,
|
||||
added: Option<T>,
|
||||
}
|
||||
|
||||
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
|
||||
title: "Difference",
|
||||
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(
|
||||
from.as_ref().map(|x| &*x.body).unwrap_or(""),
|
||||
to.as_ref().map(|x| &*x.body).unwrap_or("")
|
||||
)
|
||||
.into_iter()
|
||||
.map(|x| match x {
|
||||
diff::Result::Left(x) => DiffLine { removed: Some(x), ..Default::default() },
|
||||
diff::Result::Both(x, _) => DiffLine { same: Some(x), ..Default::default() },
|
||||
diff::Result::Right(x) => DiffLine { added: Some(x), ..Default::default() },
|
||||
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<_>>()
|
||||
},
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<div class="container">
|
||||
<header>
|
||||
<h1>Diff</h1>
|
||||
<h1>{{#title}}{{#.removed}}<span class="removed">{{.}}</span>{{/.removed}}{{#.same}}{{.}}{{/.same}}{{#.added}}<span class="added">{{.}}</span>{{/.added}}{{/title}}</h1>
|
||||
</header>
|
||||
|
||||
<article>
|
||||
|
|
Loading…
Reference in a new issue