aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2017-06-25 09:14:26 -0400
committerAustin Adams <git@austinjadams.com>2017-06-25 09:14:26 -0400
commit5be0c186982f70ab104a2a206fa66b31b315ec37 (patch)
tree5968d8bca1c0faec7461a4ed6cd60f2fa5072dc3
parent3999a905d75172d83f26996586acf9ff778d5a56 (diff)
downloadgong-5be0c186982f70ab104a2a206fa66b31b315ec37.tar.gz
gong-5be0c186982f70ab104a2a206fa66b31b315ec37.tar.xz
templates/repo-tree: Don't print empty ending line
Spliting the blob on \n often yields an empty line ("") at the end since most/many text files end with a newline. But I want \n to be a line _terminator_, not a line _separator_. So print the last line of the blob only if it's not empty. This condition allows an ending line without a terminating newline to still show up.
-rw-r--r--templates/repo-tree.html15
1 files changed, 13 insertions, 2 deletions
diff --git a/templates/repo-tree.html b/templates/repo-tree.html
index 02170eb..a5d4962 100644
--- a/templates/repo-tree.html
+++ b/templates/repo-tree.html
@@ -20,8 +20,19 @@
{{ end }}
{{ define "repo-body" }}
{{ if not .IsListing }}
- <pre><code>{{ range $lineNum, $line := (split .Blob "\n") }}<span class="line" id="n{{ add $lineNum 1 }}">{{ $line }}</span>
-{{ end }}</code></pre>
+ {{/* Ugly comments are needed here since this is a <pre>, which will
+ preserve whitespace left between our template tags */}}
+ <pre id="blob"><code>{{/*
+ */}}{{ $lines := (split .Blob "\n") }}{{/*
+ */}}{{ range $index, $line := $lines }}{{/*
+ */}}{{ $lineNum := (add $index 1) }}{{/*
+ If the last line is empty, it's just a newline at the end of
+ the file, so don't print an empty line for it
+ */}}{{ if or (lt $lineNum (len $lines)) $line }}{{/*
+ */}}<span class="line" id="n{{ $lineNum }}">{{ $line }}</span>{{"\n"}}{{/*
+ */}}{{ end }}{{/*
+ */}}{{ end }}{{/*
+*/}}</code></pre>
{{ end }}
{{ end }}