8000 Ability to include an external file as overview section. by memiah-steve · Pull Request #62 · dingo/blueprint · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ability to include an external file as overview section. #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: php

dist: trusty

php:
- 5.5.9
- 5.5
Expand Down
36 changes: 32 additions & 4 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ protected function registerAnnotationLoader()
}

/**
* Generate documentation with the name and version.
* Generate documentation with the name, version and optional overview content.
*
* @param \Illuminate\Support\Collection $controllers
* @param string $name
* @param string $version
* @param string $includePath
* @param string $overviewFile
*
* @return bool
*/
public function generate(Collection $controllers, $name, $version, $includePath = null)
public function generate(Collection $controllers, $name, $version, $includePath = null, $overviewFile = null)
{
$this->includePath = $includePath;

Expand Down Expand Up @@ -111,7 +112,7 @@ public function generate(Collection $controllers, $name, $version, $includePath
return new Resource($controller->getName(), $controller, $annotations, $actions);
});

$contents = $this->generateContentsFromResources($resources, $name);
$contents = $this->generateContentsFromResources($resources, $name, $overviewFile);

$this->includePath = null;

Expand All @@ -123,17 +124,19 @@ public function generate(Collection $controllers, $name, $version, $includePath
*
* @param \Illuminate\Support\Collection $resources
* @param string $name
* @param string $overviewFile
*
* @return string
*/
protected function generateContentsFromResources(Collection $resources, $name)
protected function generateContentsFromResources(Collection $resources, $name, $overviewFile = null)
{
$contents = '';

$contents .= $this->getFormat();
$contents .= $this->line(2);
$contents .= sprintf('# %s', $name);
$contents .= $this->line(2);
$contents .= $this->getOverview($overviewFile);

$resources->each(function ($resource) use (&$contents) {
if ($resource->getActions()->isEmpty()) {
Expand Down Expand Up @@ -454,4 +457,29 @@ protected function getFormat()
{
return 'FORMAT: 1A';
}

/**
* Get the overview file content to append.
*
* @param null $file
* @return null|string
*/
protected function getOverview($file = null)
{
if (null !== $file) {
if (!file_exists($file)) {
throw new RuntimeException('Overview file could not be found.');
}

$content = file_get_contents($file);

if ($content === false) {
throw new RuntimeException('Failed to read overview file contents.');
}

return $content.$this->line(2);
}

return null;
}
}
23 changes: 23 additions & 0 deletions tests/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,27 @@ public function testGeneratingSimpleBlueprints()

$this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v1', null));
}

public function testGeneratingBlueprintOverview()
{
$resources = new Collection([new Stubs\ActivityController]);

$blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem);

$expected = <<<'EOT'
FORMAT: 1A

# testing

Overview content here.

# Activity

## Show all activities. [GET /activity]
EOT;

$this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v1', null, __DIR__.'/Files/overview.apib'));


}
}
1 change: 1 addition & 0 deletions tests/Files/overview.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Overview content here.
0