summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Doherty <bendohmv@gmail.com>2014-04-09 23:58:17 -0400
committerBen Doherty <bendohmv@gmail.com>2014-04-09 23:58:17 -0400
commit9c4333412f5ac71d19031c538a8711c1502f2207 (patch)
tree69cb9c723c8c307326b2dda1c9229b9b32be82b4
parentdc3539340dba1c6d6308a62a9701fdc3f3343de5 (diff)
downloadwebgrind-9c4333412f5ac71d19031c538a8711c1502f2207.zip
webgrind-9c4333412f5ac71d19031c538a8711c1502f2207.tar.gz
webgrind-9c4333412f5ac71d19031c538a8711c1502f2207.tar.bz2
Myriad improvements to the fileviewer code. Lines now get their own line boxes using parsed results from PHP highlight_file output.
Style improvements, some markup changes
-rw-r--r--styles/style.css33
-rw-r--r--templates/fileviewer.phtml63
2 files changed, 74 insertions, 22 deletions
diff --git a/styles/style.css b/styles/style.css
index bd6446b..6475c5d 100644
--- a/styles/style.css
+++ b/styles/style.css
@@ -164,12 +164,41 @@ img.list_reload {
border-right: 1px solid gray;
}
+.line {
+ display: block;
+ padding: 0;
+ margin: 0;
+ font-family: monospace;
+}
+ .line .line-num {
+ display: inline-block;
+ border-right: 1px solid #999;
+padding-right: .5em;
+ color: #999;
+ }
+ .line:hover {
+ background-color: #ffd;
+ }
+ .line.emph {
+ background-color: #dff;
+
.line_emph {
- background-color: #bbbbff;
+position: relative;
+}
+.line_emph:before {
+display: block;
+content: " ";
+position: absolute;
+top: 0;
+left: 0;
+width: 100%;
+height: 100%;
+background-color: #bbffff;
+z-index: -1;
}
a.load_invocations {
display: none;
background-color: #999;
border: 1px solid #333;
padding: 2px;
-} \ No newline at end of file
+}
diff --git a/templates/fileviewer.phtml b/templates/fileviewer.phtml
index c3f01b8..cd529c2 100644
--- a/templates/fileviewer.phtml
+++ b/templates/fileviewer.phtml
@@ -11,7 +11,7 @@
</title>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
- $('div#'+location.hash.substr(1)).addClass('line_emph');
+ $('#'+location.hash.substr(1)).addClass('emph');
});
</script>
@@ -28,24 +28,47 @@
<div id="main">
<h2><?php echo $file?></h2>
<br>
- <?php if ($message==''):?>
- <?php $source = highlight_file($file, true); ?>
- <table border="0">
- <tr>
- <td align="right" valign="top"><code>
- <?php
- foreach ($lines = explode('<br />', $source) as $num => $line) {
- $num++;
- echo "<span class='num' name='line$num' id='line$num'>$num</span>";
- }
- ?>
- </code></td>
- <td valign="top" nowrap="nowrap"><?php echo $source; ?></td>
- </tr>
- </table>
- <?php else:?>
- <p><b><?php echo $message?></b></p>
- <?php endif?>
+<?php
+ echo "</span></code>";
+ if ($message=='') {
+ //Strip code and first span
+ $hl = highlight_file($file, true);
+ $code = substr($hl, 36, -15);
+ //Split lines
+ $lines = explode('<br />', $code);
+ //Count
+ $lineCount = count($lines);
+ //Calc pad length
+ $padLength = strlen($lineCount);
+
+ $lastSpan = '';
+ //Loop lines
+ foreach($lines as $i => $line) {
+ unset( $openSpan );
+
+ //Create line number
+ $lineNumber = str_pad($i + 1, $padLength, '0', STR_PAD_LEFT);
+ // Keep the last open span:
+ if( preg_match( '#.*(<span[^>]+>)#', $line, $matches ) ) {
+ $openSpan = '';
+ if( !preg_match('#</span>\s*$#', $line ) ) {
+ $openSpan = $matches[1];
+ $line .= '</span>';
+ }
+ }
+ //Print line
+ printf('<code id="line%s" class="line"><span class="line-num">%s</span> %s%s</code>', $lineNumber, $lineNumber, $lastSpan, $line);
+
+ if( isset( $openSpan ) ) {
+ $lastSpan = $openSpan;
+ }
+ }
+ }
+ //Close span
+
+ else { ?>
+ <p><b><?php echo $message?></b></p>
+ <?php } ?>
</div>
</body>
-</html> \ No newline at end of file
+</html>