Skip to content

Commit

Permalink
allow overriding the template being rendered from the controller
Browse files Browse the repository at this point in the history
added action to view the source of a given file
  • Loading branch information
josegonzalez committed Apr 25, 2011
1 parent 4b92154 commit 57d77d5
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
41 changes: 34 additions & 7 deletions controllers/projects_controller.php
@@ -1,22 +1,49 @@
<?php

class ProjectsController extends Controller {

protected function beforeFilter() {
Git::loadRepositories();
}
class ProjectsController extends AppController {

public function show() {
$this->_breadcrumbs = array(
'home' => '/',
$this->_request->params['project'] => "/{$this->_request->params['project']}",
$this->_request->params['branch'] => "/{$this->_request->params['project']}/{$this->_request->params['branch']}",
);
if (!empty($this->_request->params['filepath'])) {
$paths = explode('/', $this->_request->params['filepath']);
$prevPath = "/{$this->_request->params['project']}/{$this->_request->params['branch']}";
foreach ($paths as $i => $path) {
$prevPath = $prevPath . '/' . $path;
$this->_breadcrumbs[$path] = $prevPath;
}
}

System::set('title', $this->_request->params['project']);
$tree = $this->Project->getTree(
$this->_request->params['project'],
$this->_request->params['filepath']
);
$this->set(compact('tree'));
}

public function blob() {
$this->_breadcrumbs = array(
'home' => '/',
$this->_request->params['project'] => "/{$this->_request->params['project']}",
$this->_request->params['branch'] => "/{$this->_request->params['project']}/tree/{$this->_request->params['branch']}",
);

if (!empty($this->_request->params['filepath'])) {
$paths = explode('/', $this->_request->params['filepath']);
$prevPath = "/{$this->_request->params['project']}/{$this->_request->params['branch']}";
foreach ($paths as $i => $path) {
$prevPath = $prevPath . '/' . $path;
$this->_breadcrumbs[$path] = $prevPath;
}
}

$data = $this->Project->getBlob(
$this->_request->params['project'],
$this->_request->params['filepath']
);
$this->set(compact('data'));
}

}
7 changes: 4 additions & 3 deletions core/controller.php
Expand Up @@ -3,6 +3,7 @@
class Controller {

var $name;
var $_action;
var $_request;
var $_models = array();
var $_view;
Expand All @@ -19,6 +20,7 @@ public function __construct($request) {
}

$this->_request = $request;
$this->_action = $this->_request->params['action'];
$this->_view = new Gears($request, array(
'ext' => 'php',
'element_path' => VIEWS . 'elements' . DS,
Expand Down Expand Up @@ -75,11 +77,10 @@ public function layout($layout) {
$this->_view->setLayout(VIEWS . 'layouts' . DS . $layout);
}

public function render($template = null) {
if (!$template) $template = $this->_request->params['action'];
public function render() {
$this->set('request', $this->_request);
$this->set('breadcrumbs', $this->_breadcrumbs);
$this->_view->display($template);
$this->_view->display($this->_action);
}

public function trigger($actionName) {
Expand Down
11 changes: 11 additions & 0 deletions libs/git.php
Expand Up @@ -139,6 +139,17 @@ public static function commit($proj, $commit) {
return self::getLastNCommits($proj, $options);
}

public static function blob($proj, $path) {
if (is_file(self::$repos[$proj] . DS . $path)) {
$File = new File(self::$repos[$proj] . DS .$path);
return array(
'content' => $File->read(),
'ext' => $File->ext()
);
}
return null;
}

public static function lsTree($proj, $tree) {
$gitBinary = System::get('git_binary');

Expand Down
4 changes: 4 additions & 0 deletions models/project.php
Expand Up @@ -94,6 +94,10 @@ function getTree($proj, $filepath = '') {
return Git::lsTree($proj, $filepath);
}

function getBlob($proj, $filepath = '') {
return Git::blob($proj, $filepath);
}

function getCommit($proj, $commit) {
$commit = Git::commit($proj, $commit);
if (is_array($commit) && count($commit) == 1) return current($commit);
Expand Down
6 changes: 6 additions & 0 deletions views/projects/blob.php
@@ -0,0 +1,6 @@
<div class="gitspacer">&nbsp;</div>
<?php echo $this->element('summary_title'); ?>
<div class="gitspacer">&nbsp;</div>
<div class="table-wrapper">
<div class="gitcode"><?php echo $this->Geshi->highlight($data['content'], $data['ext']); ?></div>
</div>
1 change: 1 addition & 0 deletions web/css/gitstyle.css
Expand Up @@ -44,6 +44,7 @@ body{font-family:"Monaco","Courier New",monospace;font-size:12px;margin:0;backgr
.gitbrowse{margin: 1em 2em 1em 2em;}
div.gitbrowse a.blob{text-decoration:none;color:#000000;}
.gitcode{border: 1px solid rgb(216, 216, 216);margin: 1em 2em 1em 2em;padding:10px;}
.gitcode pre{overflow:scrol;};
div.gitspacer{padding:1px 0px 0px 0px;background-color:#FFFFFF;}
a.rss_logo{float:right;padding:3px;width:35px;line-height:10px;border:1px solid;border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;color:#ffffff;background-color:#ff6600;font-weight:bold;font-family:sans-serif;font-size:70%;text-align:center;text-decoration:none;margin-top:49px;margin-left:5px;}
a.rss_logo:hover{background-color:#ee5500;}
Expand Down

0 comments on commit 57d77d5

Please sign in to comment.