Repositories

grarr

(mirrored on github)

Wim Looman <wim@nemo157.com>
98c7d0 Add linkable line numbers on files
Wim Looman committed at 2016-03-10 13:20:55

Modified src/render/diff.rs

@@ -48,39 +48,57 @@ renderers! {
div.line.hunk-header span.text "No content"
}
@for (hunk, lines) in hunks {
div.line.hunk-header
div.line.hunk-header {
span.line-num
{ }
span.text ^hunk.header.unwrap()
}
@for line in lines {
@match (line.origin, line.content) {
(Origin::LineContext, Some(ref content)) => {
div.line.context
data-old-line-num={ @if let Some(num) = line.old_lineno { ^(format!("{: >4}", num)) } @else { " " } }
data-new-line-num={ @if let Some(num) = line.new_lineno { ^(format!("{: >4}", num)) } @else { " " } }
div.line.context {
span.line-num
data-old-line-num={ @if let Some(num) = line.old_lineno { ^(format!("{: >4}", num)) } @else { " " } }
data-new-line-num={ @if let Some(num) = line.new_lineno { ^(format!("{: >4}", num)) } @else { " " } }
{ }
span.text ^content
}
},
(Origin::LineAddition, Some(ref content)) => {
div.line.addition
data-old-line-num={ @if let Some(num) = line.old_lineno { ^(format!("{: >4}", num)) } @else { " " } }
data-new-line-num={ @if let Some(num) = line.new_lineno { ^(format!("{: >4}", num)) } @else { " " } }
div.line.addition {
span.line-num
data-old-line-num={ @if let Some(num) = line.old_lineno { ^(format!("{: >4}", num)) } @else { " " } }
data-new-line-num={ @if let Some(num) = line.new_lineno { ^(format!("{: >4}", num)) } @else { " " } }
{ }
span.text ^content
}
},
(Origin::LineDeletion, Some(ref content)) => {
div.line.deletion
data-old-line-num={ @if let Some(num) = line.old_lineno { ^(format!("{: >4}", num)) } @else { " " } }
data-new-line-num={ @if let Some(num) = line.new_lineno { ^(format!("{: >4}", num)) } @else { " " } }
div.line.deletion {
span.line-num
data-old-line-num={ @if let Some(num) = line.old_lineno { ^(format!("{: >4}", num)) } @else { " " } }
data-new-line-num={ @if let Some(num) = line.new_lineno { ^(format!("{: >4}", num)) } @else { " " } }
{ }
span.text ^content
}
},
(Origin::AddEOF, _) => {
div.line.add-eof
div.line.add-eof {
span.line-num { }
span.text "Added EOF"
}
},
(Origin::RemoveEOF, _) => {
div.line.remove-eof
div.line.remove-eof {
span.line-num { }
span.text "Removed EOF"
}
},
(Origin::LineBinary, _) => {
div.line.binary
div.line.binary {
span.line-num { }
span.text "Binary file changed"
}
},
(Origin::ContextEOF, _) | (Origin::FileHeader, _) | (Origin::HunkHeader, _) => {
},

Modified src/render/tree.rs

@@ -80,7 +80,8 @@ renderers! {
true => code { "Binary file" },
false => code class={ "hljs lang-" ^context.extension().unwrap_or("") } {
@for (i, line) in str::from_utf8(blob.content()).unwrap().lines().enumerate() {
div.line data-line-num=^(format!("{: >4}", i + 1)) {
div.line {
a.line-num id={ "L" ^(i + 1) } href={ "#L" ^(i + 1) } data-line-num=^(format!("{: >4}", i + 1)) { }
span.text ^line
}
}

Modified src/static/css/layout.css

@@ -216,7 +216,7 @@ pre .line .text:before {
content: " ";
}
pre .line:before {
pre .line-num:before {
content: " ";
padding: 0.2rem 0;
border-right-width: 1px;
@@ -224,7 +224,7 @@ pre .line:before {
font-size: 0.6rem;
}
pre .line[data-line-num]:before {
pre .line-num[data-line-num]:before {
content: " " attr(data-line-num) " " ;
}
@@ -244,11 +244,11 @@ pre .line[data-line-num]:before {
content: " ";
}
.diff .line:before {
.diff .line-num:before {
content: " ";
}
.diff .line[data-old-line-num][data-new-line-num]:before {
.diff .line-num[data-old-line-num][data-new-line-num]:before {
content: " " attr(data-old-line-num) " " attr(data-new-line-num) " " ;
}

Modified src/static/css/theme-solarized-dark.css

@@ -1,6 +1,7 @@
html * { color-profile: sRGB; }
body { color: #839496; }
a.line-num { color: #839496; }
.ci-status a { color: #839496; }
.expander[disabled] + label:hover { color: #839496; }

Modified src/static/css/theme-solarized-light.css

@@ -1,6 +1,7 @@
html * { color-profile: sRGB; }
body { color: #657b83; }
a.line-num { color: #657b83; }
.ci-status a { color: #657b83; }
.expander[disabled] + label:hover { color: #657b83; }