Skip to content

Commit

Permalink
improved README generation with render functions and section templates
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Oct 15, 2015
1 parent 9c861c7 commit 25fa62d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 50 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Task runner, code generator and build tool for continuos integration.

And more planned. See [ROADMAP](https://github.com/hiqdev/hidev/blob/master/ROADMAP.md).


[![Latest Stable Version](https://poser.pugx.org/hiqdev/hidev/v/stable.png)](https://packagist.org/packages/hiqdev/hidev)
[![Total Downloads](https://poser.pugx.org/hiqdev/hidev/downloads.png)](https://packagist.org/packages/hiqdev/hidev)
[![Dependency Status](https://www.versioneye.com/php/hiqdev:hidev/dev-master/badge.svg)](https://www.versioneye.com/php/hiqdev:hidev/dev-master)
Expand Down Expand Up @@ -54,7 +53,7 @@ require:
hiqdev/hidev-config-php: "*"
```
## Licence
## License
This project is released under the terms of the BSD-3-Clause [license](https://github.com/hiqdev/hidev/blob/master/LICENSE).
Read more [here](http://choosealicense.com/licenses/bsd-3-clause).
Expand Down
34 changes: 27 additions & 7 deletions src/goals/ReadmeGoal.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace hidev\goals;

use Yii;
use hidev\helpers\Helper;

/**
* Goal for README.
Expand All @@ -23,15 +24,34 @@ public function getTemplate()
return 'README';
}

public function renderH1($title)
{
$res = $title . "\n";
$res .= str_repeat('-', mb_strlen($title, Yii::$app->charset));
return $res . "\n";
}

public function renderText($text)
{
$text = trim($text);
return $text ? "\n$text\n" : '';
}

public function renderSection($section, $default = null)
{
$file = str_replace(' ', '', $section);
$path = Yii::getAlias("@source/docs/readme/$file.md");
if (!file_exists($path)) {
return $default;
}
$file = 'readme/' . str_replace(' ', '', $section);
$path = Yii::getAlias("@source/docs/$file.md");
$text = file_exists($path) ? file_get_contents($path) : $this->getSection($file, $default);
$text = trim($text);

return "\n## $section\n\n" . file_get_contents($path);
return $text ? "\n## $section\n\n$text\n" : '';
}

public function getSection($file, $default = null)
{
$view = Yii::$app->getView();
$tpl = Helper::file2template($file);
return $view->existsTemplate($tpl) ? $view->render($tpl, ['config' => $this->config]) : $default;
}

public $badges = [
Expand All @@ -51,7 +71,7 @@ public function renderBadges()
$res .= $this->renderBadge($badge) . "\n";
}

return $res;
return $res ? "\n$res" : '';
}

public function renderBadge($badge)
Expand Down
4 changes: 3 additions & 1 deletion src/goals/VcsGoal.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class VcsGoal extends DefaultGoal
public $initTag = 'Development started';

public $_ignore = [
'.hidev/composer.json' => 'hidev composer.json',
'.hidev/composer.json' => 'hidev internals',
'.hidev/composer.lock' => 'hidev internals',
'.hidev/vendor' => 'hidev internals',
'.*.swp' => 'IDE & OS files',
'.idea' => 'IDE & OS files',
'nbproject' => 'IDE & OS files',
Expand Down
44 changes: 4 additions & 40 deletions src/views/README.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,7 @@
<?= $config->package->title ?>

<?= str_repeat('-', mb_strlen($config->package->title, \Yii::$app->charset)) ?>


<?= $config->package->description ?>


<?= $config->readme->renderH1($config->package->title) ?>
<?= $config->readme->renderText($config->package->description) ?>
<?= $config->readme->renderBadges() ?>

## Installation

The preferred way to install this <?= $config->package->type ?> is through [composer](http://getcomposer.org/download/).

<?php if ($config->package->type === 'project') { ?>
```
php composer.phar create-project "<?= $config->package->fullName ?>:*" directory2install
```
<?php } else { ?>
Either run

```
php composer.phar require "<?= $config->package->fullName ?>"
```

or add

```json
"<?= $config->package->fullName ?>": "*"
```

to the require section of your composer.json.
<?php } ?>
<?= $config->readme->renderSection('Installation') ?>
<?= $config->readme->renderSection('Configuration') ?>
<?= $config->readme->renderSection('Usage') ?>

## Licence

This project is released under the terms of the <?= $config->package->license ?> [license](<?= $config->package->getRepositoryUrl('LICENSE') ?>).
Read more [here](<?= $config->license->url ?>).

Copyright © <?= $config->package->years ?>, <?= $config->vendor->titleAndHomepage ?>

<?= $config->readme->renderSection('License') ?>
Empty file.
4 changes: 4 additions & 0 deletions src/views/readme/License.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This project is released under the terms of the <?= $config->package->license ?> [license](<?= $config->package->getRepositoryUrl('LICENSE') ?>).
Read more [here](<?= $config->license->url ?>).

Copyright © <?= $config->package->years ?>, <?= $config->vendor->titleAndHomepage ?>

0 comments on commit 25fa62d

Please sign in to comment.