Skip to content
This repository was archived by the owner on Apr 12, 2020. It is now read-only.

Commit 072f3f3

Browse files
committed
Moved tree browser to themes
1 parent b9c6aca commit 072f3f3

File tree

7 files changed

+111
-79
lines changed

7 files changed

+111
-79
lines changed

src/Gitonomy/Browser/Application.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public function registerRouting()
9393

9494
/** Browse repository */
9595
$this
96-
->get('/{repository}/tree/{reference}/path/{path}', 'controller.main:treeAction')
96+
->get('/{repository}/tree/{revision}/path/{path}', 'controller.main:treeAction')
9797
->bind('tree')
98-
->value('reference', 'master')
99-
->assert('reference', '.*')
98+
->value('revision', 'master')
99+
->assert('revision', '.*')
100100
->value('path', '')
101101
->assert('path', '.*')
102102
;

src/Gitonomy/Browser/Controller/MainController.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ public function logAjaxAction(Request $request, $repository)
5454
return $this->twig->render('log_ajax.html.twig', array('log' => $log));
5555
}
5656

57-
public function treeAction($repository, $reference, $path)
57+
public function treeAction($repository, $revision, $path)
5858
{
5959
try {
60-
$commit = $repository->getRevision($reference)->getResolved();
60+
$commit = $repository->getRevision($revision)->getResolved();
6161
$tree = $commit->getTree();
6262
} catch (ReferenceNotFoundException $e) {
63-
throw new NotFoundHttpException(sprintf('The reference "%s" is not valid', $reference), $e);
63+
throw new NotFoundHttpException(sprintf('The revision "%s" is not valid', $revision), $e);
6464
}
6565

6666
try {
@@ -69,22 +69,14 @@ public function treeAction($repository, $reference, $path)
6969
throw new NotFoundHttpException(sprintf('Cannot find path "%s" for current commit "%s"', $path, $commit->getHash()), $e);
7070
}
7171

72-
$parameters = array(
73-
'reference' => $reference,
74-
'commit' => $commit,
75-
'parent_path' => substr($path, 0, strrpos($path, '/')),
76-
'path' => $path,
77-
);
78-
79-
if ($element instanceof Blob) {
80-
$parameters['blob'] = $element;
81-
$tpl = 'browse_blob.html.twig';
82-
} elseif ($element instanceof Tree) {
83-
$parameters['tree'] = $element;
84-
$tpl = 'browse_tree.html.twig';
85-
}
72+
$template = $element instanceof Blob ? 'browse_blob.html.twig' : 'browse_tree.html.twig';
8673

87-
return $this->twig->render($tpl, $parameters);
74+
return $this->twig->render($template, array(
75+
'commit' => $commit,
76+
'element' => $element,
77+
'path' => $path,
78+
'revision' => $revision,
79+
));
8880
}
8981

9082
public function showCommitAction($repository, $hash)

src/Gitonomy/Browser/Resources/views/browse_blob.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
{% block content %}
44
<h3>Code</h3>
5-
{{ git_blob(blob, path) }}
5+
{{ git_blob(element, path) }}
66
{% endblock %}
Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,6 @@
11
{% extends "layout.html.twig" %}
22

33
{% block content %}
4-
<h3>Code</h3>
5-
<table class="table table-striped">
6-
<thead>
7-
<tr>
8-
<th width="20"></td>
9-
<th>{{ 'table.filename'|trans }}</th>
10-
<th>{{ 'table.date'|trans }}</th>
11-
<th>{{ 'table.last_commit'|trans }}</th>
12-
</tr>
13-
</thead>
14-
<tbody>
15-
{% if parent_path is not sameas(false) %}
16-
<tr>
17-
<td><i class="icon-folder-open"></i></td>
18-
<td>
19-
<a href="{{ path('tree', {reference: reference, path: parent_path}) }}">
20-
..
21-
</a>
22-
</td>
23-
<td></td>
24-
<td></td>
25-
</tr>
26-
{% endif %}
27-
{% for name, data in tree.entries if data[1] is git_tree %}
28-
{% embed 'browse_tree_row.html.twig' %}
29-
{% block first_column %}<i class="icon-folder-open"></i>{% endblock %}
30-
{% endembed %}
31-
{% endfor %}
32-
{% for name, data in tree.entries if data[1] is not git_tree %}
33-
{% embed 'browse_tree_row.html.twig' %}
34-
{% endembed %}
35-
{% endfor %}
36-
</tbody>
37-
</table>
4+
<h3>Browse</h3>
5+
{{ git_tree(element, commit, path, revision)}}
386
{% endblock %}

src/Gitonomy/Browser/Resources/views/browse_tree_row.html.twig

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Gitonomy/Browser/Resources/views/git/default_theme.html.twig

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,84 @@
233233
<pre><code>BINARY</code></pre>
234234
{% endspaceless %}
235235
{% endblock %}
236+
237+
{% block tree %}
238+
{% spaceless %}
239+
<table class="table table-striped">
240+
{{ git_render('tree_header') }}
241+
<tbody>
242+
{% if parent_path is not sameas(false) %}
243+
<tr>
244+
<td><i class="icon-folder-open"></i></td>
245+
<td>
246+
<a href="{{ path('tree', {revision: revision, path: parent_path}) }}">
247+
..
248+
</a>
249+
</td>
250+
<td></td>
251+
<td></td>
252+
</tr>
253+
{% endif %}
254+
{% for name, data in tree.entries if data[1] is git_tree %}
255+
{{ git_render('tree_row', {
256+
commit: commit,
257+
data: data,
258+
is_dir: true,
259+
name: name,
260+
path: path,
261+
revision: revision,
262+
}) }}
263+
{% endfor %}
264+
{% for name, data in tree.entries if data[1] is not git_tree %}
265+
{{ git_render('tree_row', {
266+
commit: commit,
267+
data: data,
268+
is_dir: false,
269+
name: name,
270+
path: path,
271+
revision: revision,
272+
}) }}
273+
{% endfor %}
274+
</tbody>
275+
</table>
276+
{% endspaceless %}
277+
{% endblock %}
278+
279+
{% block tree_header %}
280+
{% spaceless %}
281+
<thead>
282+
<tr>
283+
<th width="20"></td>
284+
<th>{{ 'table.filename'|trans }}</th>
285+
<th>{{ 'table.date'|trans }}</th>
286+
<th>{{ 'table.last_commit'|trans }}</th>
287+
</tr>
288+
</thead>
289+
{% endspaceless %}
290+
{% endblock %}
291+
292+
{% block tree_row %}
293+
{% spaceless %}
294+
{% set pathLastModification = commit.lastModification(path~'/'~name) %}
295+
<tr>
296+
<td>{% if is_dir is defined and is_dir %}<i class="icon-folder-open"></i>{% endif %}</td>
297+
<td>
298+
<a href="{{ path('tree', {revision: revision, path: (path ~ (path ? '/') ~ name)}) }}">
299+
{{ name }}
300+
</a>
301+
</td>
302+
<td>
303+
{{ pathLastModification.getCommitterDate.format('Y-m-d H:i:s') }}
304+
</td>
305+
<td>
306+
<a href="{{ path('commit', { hash: pathLastModification.hash }) }}">
307+
{{ pathLastModification.fixedShortHash }}
308+
</a>
309+
{{ pathLastModification.shortMessage }}
310+
<small>
311+
({{ pathLastModification.authorName }})
312+
</small>
313+
</td>
314+
</tr>
315+
{% endspaceless %}
316+
{% endblock %}

src/Gitonomy/Browser/Twig/GitExtension.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function getFunctions()
4444
new \Twig_SimpleFunction('git_commit_header', array($this, 'renderCommitHeader'), array('is_safe' => array('html'), 'needs_environment' => true)),
4545
new \Twig_SimpleFunction('git_diff', array($this, 'renderDiff'), array('is_safe' => array('html'), 'needs_environment' => true)),
4646
new \Twig_SimpleFunction('git_log', array($this, 'renderLog'), array('is_safe' => array('html'), 'needs_environment' => true)),
47+
new \Twig_SimpleFunction('git_tree', array($this, 'renderTree'), array('is_safe' => array('html'), 'needs_environment' => true)),
4748
new \Twig_SimpleFunction('git_log_rows', array($this, 'renderLogRows'), array('is_safe' => array('html'), 'needs_environment' => true)),
4849
new \Twig_SimpleFunction('git_render', array($this, 'renderBlock'), array('is_safe' => array('html'), 'needs_environment' => true)),
4950
new \Twig_SimpleFunction('git_repository_name', array($this, 'renderRepositoryName'), array('is_safe' => array('html'))),
@@ -160,6 +161,17 @@ public function renderAuthor(\Twig_Environment $env, Commit $commit, array $opti
160161
));
161162
}
162163

164+
public function renderTree(\Twig_Environment $env, Tree $tree, Commit $commit, $path = '', $revision = 'master')
165+
{
166+
return $this->renderBlock($env, 'tree', array(
167+
'tree' => $tree,
168+
'parent_path' => substr($path, 0, strrpos($path, '/')),
169+
'path' => $path,
170+
'revision' => $revision,
171+
'commit' => $commit,
172+
));
173+
}
174+
163175
public function renderBlob($env, Blob $blob, $path = null)
164176
{
165177
if ($blob->isText()) {
@@ -183,7 +195,7 @@ public function addThemes($themes)
183195
$this->themes = array_merge($themes, $this->themes);
184196
}
185197

186-
public function renderBlock(\Twig_Environment $env, $block, $context = array())
198+
public function renderBlock(\Twig_Environment $env, $block, $parameters = array())
187199
{
188200
foreach ($this->themes as $theme) {
189201
if ($theme instanceof \Twig_Template) {
@@ -192,7 +204,7 @@ public function renderBlock(\Twig_Environment $env, $block, $context = array())
192204
$tpl = $env->loadTemplate($theme);
193205
}
194206
if ($tpl->hasBlock($block)) {
195-
return $tpl->renderBlock($block, $context);
207+
return $tpl->renderBlock($block, $parameters);
196208
}
197209
}
198210

0 commit comments

Comments
 (0)