Unify blob template
Unify blob template

--- a/include/display.git_blob.php
+++ b/include/display.git_blob.php
@@ -23,30 +23,22 @@
 	if (!isset($hash) && isset($file))
 		$hash = git_get_hash_by_path($projectroot . $project, $hashbase,$file,"blob");
 	$catout = git_cat_file($projectroot . $project, $hash);
-	if (isset($hashbase) && ($co = git_read_commit($projectroot . $project, $hashbase))) {
+	$tpl->clear_all_assign();
+	$tpl->assign("hash",$hash);
+	$tpl->assign("project",$project);
+	$tpl->assign("hashbase",$hashbase);
+	if ($co = git_read_commit($projectroot . $project, $hashbase)) {
+		$tpl->assign("fullnav",TRUE);
 		$refs = read_info_ref($projectroot . $project);
-		$tpl->clear_all_assign();
-		$tpl->assign("project",$project);
-		$tpl->assign("hashbase",$hashbase);
 		$tpl->assign("tree",$co['tree']);
-		$tpl->assign("hash",$hash);
+		$tpl->assign("title",$co['title']);
 		if (isset($file))
 			$tpl->assign("file",$file);
-		$tpl->assign("title",$co['title']);
 		if (isset($refs[$hashbase]))
 			$tpl->assign("hashbaseref",$refs[$hashbase]);
-		$tpl->display("blob_nav.tpl");
-	} else {
-		$tpl->clear_all_assign();
-		$tpl->assign("hash",$hash);
-		$tpl->display("blob_emptynav.tpl");
 	}
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
-	$tpl->assign("hashbase",$hashbase);
 	$paths = git_path_trees($projectroot . $project, $hashbase, $file);
 	$tpl->assign("paths",$paths);
-	$tpl->display("blob_header.tpl");
 
 	if ($gitphp_conf['filemimetype']) {
 		$mime = file_mime($catout,$file);
@@ -55,10 +47,8 @@
 	}
 
 	if ($mimetype == "image") {
-		$tpl->clear_all_assign();
 		$tpl->assign("mime", $mime);
 		$tpl->assign("data", base64_encode($catout));
-		$tpl->display("blob_image.tpl");
 	} else {
 		$usedgeshi = $gitphp_conf['geshi'];
 		if ($usedgeshi) {
@@ -74,7 +64,7 @@
 						$geshi->set_source($catout);
 						$geshi->set_language($lang);
 						$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
-						echo $geshi->parse_code();
+						$tpl->assign("geshiout",$geshi->parse_code());
 						$usedgeshi = TRUE;
 					}
 				}
@@ -83,20 +73,11 @@
 
 		if (!$usedgeshi) {
 			$lines = explode("\n",$catout);
-			foreach ($lines as $i => $line) {
-				/*
-				 * TODO: Convert tabs to spaces
-				 */
-				$tpl->clear_all_assign();
-				$tpl->assign("nr",$i+1);
-				$tpl->assign("line",htmlentities($line));
-				$tpl->display("blob_line.tpl");
-			}
+			$tpl->assign("lines",$lines);
 		}
 	}
 
-	$tpl->clear_all_assign();
-	$tpl->display("blob_footer.tpl");
+	$tpl->display("blob.tpl");
 }
 
 ?>

--- /dev/null
+++ b/templates/blob.tpl
@@ -1,1 +1,63 @@
+{*
+ *  blob_nav.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Blob view template
+ *
+ *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
+ *}
+ {* If we managed to look up commit info, we have enough info to display the full header - othewise just use a simple header *}
+ <div class="page_nav">
+   {if $fullnav}
+     <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hashbase}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$tree}&hb={$hashbase}">tree</a><br />
+     {if $file}
+       <a href="{$SCRIPT_NAME}?p={$project}&a=blob_plain&h={$hash}&f={$file}">plain</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=blob&hb=HEAD&f={$file}">head</a><br />
+     {else}
+       <a href="{$SCRIPT_NAME}?p={$project}&a=blob_plain&h={$hash}">plain</a><br />
+     {/if}
+   {else}
+     <br /><br />
+   {/if}
+ </div>
+ <div>
+   {if $fullnav}
+     <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}" class="title">{$title}
+     {if $hashbaseref}
+       <span class="tag">{$hashbaseref}</span>
+     {/if}
+     </a>
+   {else}
+     <div class="title">{$hash}</div>
+   {/if}
+ </div>
+ <div class="page_path">
+   {* The path to the file, with directories broken into tree links *}
+   <b>
+     <a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$hashbase}&h={$hashbase}">[{$project}]</a> / 
+     {foreach from=$paths item=path name=paths}
+       {if $smarty.foreach.paths.last}
+         <a href="{$SCRIPT_NAME}?p={$project}&a=blob_plain&h={$path.tree}&f={$path.full}">{$path.short}</a>
+       {else}
+         <a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$hashbase}&h={$path.tree}&f={$path.full}">{$path.short}</a> / 
+       {/if}
+     {/foreach}
+   </b>
+ </div>
+ <div class="page_body">
+   {if $mime && $data}
+     {* We're trying to display an image *}
+     <div>
+       <img src="data:{$mime};base64,{$data}" />
+     </div>
+   {elseif $geshiout}
+     {* We're using the highlighted output from geshi *}
+     {$geshiout}
+   {else}
+     {* Just plain display *}
+     <div class="pre">
+     {foreach from=$lines item=line name=lines}
+       {if $smarty.foreach.lines.iteration < 10} {/if}{if $smarty.foreach.lines.iteration < 100} {/if}{if $smarty.foreach.lines.iteration < 1000} {/if}<a id="l{$smarty.foreach.lines.iteration}" href="#l{$smarty.foreach.lines.iteration}" class="linenr">{$smarty.foreach.lines.iteration}</a> {$line|escape:'htmlall'}
+     {/foreach}
+     </div>
+   {/if}
+ </div>
 

--- a/templates/blob_emptynav.tpl
+++ /dev/null
@@ -1,11 +1,1 @@
-{*
- *  blob_emptynav.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blob view emptynav template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- <div class="page_nav">
- <br /><br /></div>
- <div class="title">{$hash}</div>
 

--- a/templates/blob_footer.tpl
+++ /dev/null
@@ -1,9 +1,1 @@
-{*
- *  blob_footer.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blob view footer template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- </div>
 

--- a/templates/blob_header.tpl
+++ /dev/null
@@ -1,10 +1,1 @@
-{*
- *  blob_header.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blob view header template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- <div class="page_path"><b><a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$hashbase}&h={$hashbase}">[{$project}]</a> / {foreach from=$paths item=path name=paths}{if $smarty.foreach.paths.last}<a href="{$SCRIPT_NAME}?p={$project}&a=blob_plain&h={$path.tree}&f={$path.full}">{$path.short}</a>{else}<a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$hashbase}&h={$path.tree}&f={$path.full}">{$path.short}</a> / {/if}{/foreach}</b></div>
- <div class="page_body">
 

--- a/templates/blob_image.tpl
+++ /dev/null
@@ -1,9 +1,1 @@
-{*
- *  blob_image.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blob image template
- *
- *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
- *}
- <div><img src="data:{$mime};base64,{$data}" /></div>
 

file:a/templates/blob_line.tpl (deleted)
--- a/templates/blob_line.tpl
+++ /dev/null
@@ -1,9 +1,1 @@
-{*
- *  blob_line.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blob view line template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- <div class="pre">{if $nr < 10} {/if}{if $nr < 100} {/if}{if $nr < 1000} {/if}<a id="l{$nr}" href="#l{$nr}" class="linenr">{$nr}</a> {$line}</div>
 

file:a/templates/blob_nav.tpl (deleted)
--- a/templates/blob_nav.tpl
+++ /dev/null
@@ -1,21 +1,1 @@
-{*
- *  blob_nav.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blob view nav template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- <div class="page_nav">
- <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hashbase}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$tree}&hb={$hashbase}">tree</a><br />
- {if $file}
- <a href="{$SCRIPT_NAME}?p={$project}&a=blob_plain&h={$hash}&f={$file}">plain</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=blob&hb=HEAD&f={$file}">head</a><br />
- {else}
- <a href="{$SCRIPT_NAME}?p={$project}&a=blob_plain&h={$hash}">plain</a><br />
- {/if}
- </div>
- <div><a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}" class="title">{$title}
- {if $hashbaseref}
- <span class="tag">{$hashbaseref}</span>
- {/if}
- </a></div>
 

comments