Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
add view helper for render a composer.json, and write a new tab in a …
Browse files Browse the repository at this point in the history
…module page
  • Loading branch information
GianArb committed Sep 13, 2013
1 parent eac50fe commit 7b6bafd
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 17 deletions.
1 change: 1 addition & 0 deletions module/ZfModule/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'listModule' => 'ZfModule\View\Helper\ListModule',
'moduleView' => 'ZfModule\View\Helper\ModuleView',
'moduleDescription' => 'ZfModule\View\Helper\ModuleDescription',
'composerView' => 'ZfModule\View\Helper\ComposerView',
),
),
'zfmodule' => array(
Expand Down
8 changes: 8 additions & 0 deletions module/ZfModule/src/ZfModule/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ public function viewAction()
$license = 'No license file found for this Module';
}

try{
$composerJson = $client->api('repos')->content($vendor, $module, 'composer.json');
$composerConf = json_decode($composerJson);
$composerConf = base64_decode($composerConf->content);
} catch(\Exception $e) {
$composerConf = 'No license file found for this Module';
}

$viewModel = new ViewModel(array(
'vendor' => $vendor,
'module' => $module,
'repository' => $repository,
'readme' => base64_decode($readme->content),
'composerConf' => json_decode($composerConf, true),
'license' => $license,
));

Expand Down
41 changes: 41 additions & 0 deletions module/ZfModule/src/ZfModule/View/Helper/ComposerView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace ZfModule\View\Helper;

use Zend\View\Helper\AbstractHelper;
use Zend\View\Model\ViewModel;

class ComposerView extends AbstractHelper
{
/**
* $var string template used for view
*/
protected $viewTemplate;

/**
* __invoke
*
* @access public
* @return string
*/
public function __invoke($composerConf)
{
$vm = new ViewModel(array(
'composerConf' => $composerConf,
));
$vm->setTemplate('zf-module/helper/composer-view.phtml');


return $this->getView()->render($vm);
}

/**
* @param string $viewTemplate
* @return ZfcUserLoginWidget
*/
public function setViewTemplate($viewTemplate)
{
$this->viewTemplate = $viewTemplate;
return $this;
}
}
17 changes: 17 additions & 0 deletions module/ZfModule/view/zf-module/helper/composer-view.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="well">php composer.phar require "<?php echo $this->composerConf['name']?>"</div>

<h3>Require</h3>
<ul>
<?php foreach($this->composerConf['require'] as $requireName => $requireVersion){
echo "<li>{$requireName}: <span class='label label-success'>{$requireVersion}</span></li>";
}?>
</ul>
<?php if(!empty($this->composerConf['require-dev'])){?>
<h3>Require Dev</h3>

<ul>
<?php foreach($this->composerConf['require-dev'] as $requireName => $requireVersion){
echo "<li>{$requireName}: <span class='label label-important'>{$requireVersion}</span></li>";
}?>
</ul>
<?php } ?>
38 changes: 21 additions & 17 deletions module/ZfModule/view/zf-module/index/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@
<div class="span8">
<p class="well"><?php echo $this->repository->description; ?></p>
<ul class="nav nav-tabs">
<li class="active"><a href="#readme" data-toggle="tab">README</a></li>
<li ><a href="#license" data-toggle="tab">LICENSE</a></li>
<li class="active"><a href="#readme" data-toggle="tab">README</a></li>
<li><a href="#composer" data-toggle="tab">COMPOSER</a></li>
<li ><a href="#license" data-toggle="tab">LICENSE</a></li>
</ul>

<div class="tab-content">
<div class="tab-pane active" id="readme">
<?php echo $this->markdown($this->readme);?>
</div>
<div class="tab-pane" id="license">
<?php echo $license;?>
</div>
<div class="tab-pane active" id="readme">
<?php echo $this->markdown($this->readme);?>
</div>
<div class="tab-pane" id="composer">
<?php echo $this->composerView($this->composerConf);?>
</div>
<div class="tab-pane" id="license">
<?php echo $license;?>
</div>
</div>
</div>
<div class="span4">
<div class="sidebar"><?php
// infos
echo $this->moduleDescription(array(
'owner' => $repository->owner->login,
'name' => $repository->name,
'created_at' => $repository->created_at,
'url' => $repository->html_url,
'photo_url' => $repository->owner->avatar_url,
'description' => $repository->description
));
?></div>
echo $this->moduleDescription(array(
'owner' => $repository->owner->login,
'name' => $repository->name,
'created_at' => $repository->created_at,
'url' => $repository->html_url,
'photo_url' => $repository->owner->avatar_url,
'description' => $repository->description
));
?></div>
</div>
</div>

0 comments on commit 7b6bafd

Please sign in to comment.