Skip to content
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

Fix documentation generation and contents #394

Merged
merged 4 commits into from
Mar 15, 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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
build/
composer.phar
composer.lock
docs/json/**/*.json
docs/json/*
vendor/
43 changes: 35 additions & 8 deletions dev/src/DocGenerator/Command/Docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Docs extends Command
const DEFAULT_OUTPUT_DIR = 'docs/json';
const TOC_SOURCE_DIR = 'docs/contents';
const TOC_TEMPLATE = 'docs/toc.json';
const OVERVIEW_FILE = 'docs/overview.html';
const DEFAULT_SOURCE_DIR = 'src';

private $cliBasePath;
Expand Down Expand Up @@ -74,7 +75,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
'project' => $this->cliBasePath .'/../',
'manifest' => $this->cliBasePath .'/../docs/manifest.json',
'toc' => $this->cliBasePath .'/../'. self::TOC_SOURCE_DIR,
'tocTemplate' => $this->cliBasePath .'/../'. self::TOC_TEMPLATE
'tocTemplate' => $this->cliBasePath .'/../'. self::TOC_TEMPLATE,
'overview' => $this->cliBasePath .'/../'. self::OVERVIEW_FILE
];

$components = $this->getComponents($paths['source']);
Expand All @@ -83,15 +85,33 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($components as $component) {
$input = $paths['project'] . $component['path'];
$source = $this->getFilesList($input);
$this->generateComponentDocumentation($output, $source, $component, $paths, $tocTemplate, $release, $pretty);
$this->generateComponentDocumentation(
$output,
$source,
$component,
$paths,
$tocTemplate,
$release,
$pretty
);
}

$source = [$paths['project'] .'src/ServiceBuilder.php'];
$source = $this->getFilesList($paths['project'] . '/src');
$component = [
'id' => 'google-cloud',
'path' => 'src/'
];
$this->generateComponentDocumentation($output, $source, $component, $paths, $tocTemplate, $release, $pretty);

$this->generateComponentDocumentation(
$output,
$source,
$component,
$paths,
$tocTemplate,
$release,
$pretty,
false
);
}

private function generateComponentDocumentation(
Expand All @@ -101,7 +121,8 @@ private function generateComponentDocumentation(
array $paths,
$tocTemplate,
$release = false,
$pretty = false
$pretty = false,
$linkCrossComponent = true
) {
$output->writeln(sprintf('Writing documentation for %s', $component['id']));
$output->writeln('--------------');
Expand All @@ -123,23 +144,29 @@ private function generateComponentDocumentation(
$this->cliBasePath,
$component['id'],
$paths['manifest'],
$release
$release,
$linkCrossComponent
);

$docs->generate($component['path'], $pretty);

$types->write($pretty);

$output->writeln(sprintf('Writing table of contents to %s', realpath($outputPath)));
$services = json_decode(file_get_contents($paths['toc'] .'/'. $component['id'] .'.json'), true);
$contents = json_decode(file_get_contents($paths['toc'] .'/'. $component['id'] .'.json'), true);

$toc = new TableOfContents(
$tocTemplate,
$services,
$component['id'],
$release,
$paths['toc'],
$outputPath
);
$toc->generate($pretty);

$output->writeln(sprintf('Copying overview.html to %s', realpath($outputPath)));
copy($paths['overview'], $outputPath .'/overview.html');

$output->writeln(' ');
$output->writeln(' ');
}
Expand Down
12 changes: 9 additions & 3 deletions dev/src/DocGenerator/DocGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DocGenerator
private $componentId;
private $manifestPath;
private $release;
private $linkCrossComponent;

/**
* @param array $files
Expand All @@ -46,7 +47,8 @@ public function __construct(
$executionPath,
$componentId,
$manifestPath,
$release
$release,
$linkCrossComponent = true
) {
$this->types = $types;
$this->files = $files;
Expand All @@ -55,6 +57,7 @@ public function __construct(
$this->componentId = $componentId;
$this->manifestPath = $manifestPath;
$this->release = $release;
$this->linkCrossComponent = $linkCrossComponent;
}

/**
Expand Down Expand Up @@ -84,7 +87,8 @@ public function generate($basePath, $pretty)
dirname($this->executionPath),
$this->componentId,
$this->manifestPath,
$this->release
$this->release,
$this->linkCrossComponent
);
} else {
$content = file_get_contents($file);
Expand All @@ -100,7 +104,9 @@ public function generate($basePath, $pretty)
$this->types->addType([
'id' => $document['id'],
'title' => $document['title'],
'contents' => $this->prune($document['id'] . '.json')
'contents' => ($this->linkCrossComponent)
? $this->prune($document['id'] . '.json')
: $document['id'] . '.json'
]);
}
}
Expand Down
7 changes: 5 additions & 2 deletions dev/src/DocGenerator/Parser/CodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CodeParser implements ParserInterface
private $componentId;
private $manifestPath;
private $release;
private $linkCrossComponent;

public function __construct(
$path,
Expand All @@ -47,7 +48,8 @@ public function __construct(
$projectRoot,
$componentId,
$manifestPath,
$release
$release,
$linkCrossComponent = true
) {
$this->path = $path;
$this->outputName = $outputName;
Expand All @@ -58,6 +60,7 @@ public function __construct(
$this->componentId = $componentId;
$this->manifestPath = $manifestPath;
$this->release = $release;
$this->linkCrossComponent = $linkCrossComponent;
}

public function parse()
Expand Down Expand Up @@ -504,7 +507,7 @@ private function buildExternalType($type)
private function buildLink($content)
{
$componentId = null;
if (substr_compare(trim($content, '\\'), 'Google\Cloud', 0, 12) === 0) {
if ($this->linkCrossComponent && substr_compare(trim($content, '\\'), 'Google\Cloud', 0, 12) === 0) {
try {
$matches = [];
preg_match('/[Generator\<]?(Google\\\Cloud\\\[\w\\\]{0,})[\>]?[\[\]]?/', $content, $matches);
Expand Down
50 changes: 43 additions & 7 deletions dev/src/DocGenerator/TableOfContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,61 @@
class TableOfContents
{
private $template;
private $component;
private $componentId;
private $componentVersion;
private $contentsPath;
private $outputPath;

public function __construct(array $template, array $component, $componentVersion, $outputPath)
public function __construct(array $template, $componentId, $componentVersion, $contentsPath, $outputPath)
{
$this->template = $template;
$this->component = $component;
$this->componentId = $componentId;
$this->componentVersion = $componentVersion;
$this->contentsPath = $contentsPath;
$this->outputPath = $outputPath;
}

public function generate($pretty = false)
{
$toc = $this->template;
$toc['services'] = $this->component;
$toc['tagName'] = $this->componentVersion;
$toc = $this->getToc($this->componentId);

$writer = new Writer($toc, $this->outputPath, $pretty);
$tpl = $this->template;
$tpl['services'] = $this->services($toc);
$tpl['tagName'] = $this->componentVersion;

$writer = new Writer($tpl, $this->outputPath, $pretty);
$writer->write('toc.json');
}

private function services(array $toc)
{
$services = $toc['services'];

if (isset($toc['includes'])) {
foreach ($toc['includes'] as $include) {
$toc = $this->getToc($include);
$nested = $toc['services'];
$firstService = array_shift($nested);

$service = [
'title' => $toc['title'],
'type' => $firstService['type'],
'nav' => $nested
];

if (isset($toc['pattern'])) {
$service['patterns'] = [$toc['pattern']];
}

$services[] = $service;
}
}

return $services;
}

private function getToc($componentId)
{
return json_decode(file_get_contents($this->contentsPath .'/'. $componentId .'.json'), true);
}
}
66 changes: 35 additions & 31 deletions docs/contents/cloud-bigquery.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
[{
"title": "BigQueryClient",
"type": "bigquery/bigqueryclient"
}, {
"title": "Bytes",
"type": "bigquery/bytes"
}, {
"title": "Dataset",
"type": "bigquery/dataset"
}, {
"title": "Date",
"type": "bigquery/date"
}, {
"title": "InsertResponse",
"type": "bigquery/insertresponse"
}, {
"title": "Job",
"type": "bigquery/job"
}, {
"title": "QueryResults",
"type": "bigquery/queryresults"
}, {
"title": "Table",
"type": "bigquery/table"
}, {
"title": "Time",
"type": "bigquery/time"
}, {
"title": "Timestamp",
"type": "bigquery/timestamp"
}]
{
"title": "BigQuery",
"pattern": "bigquery\/\\w{1,}",
"services": [{
"title": "BigQueryClient",
"type": "bigquery/bigqueryclient"
}, {
"title": "Bytes",
"type": "bigquery/bytes"
}, {
"title": "Dataset",
"type": "bigquery/dataset"
}, {
"title": "Date",
"type": "bigquery/date"
}, {
"title": "InsertResponse",
"type": "bigquery/insertresponse"
}, {
"title": "Job",
"type": "bigquery/job"
}, {
"title": "QueryResults",
"type": "bigquery/queryresults"
}, {
"title": "Table",
"type": "bigquery/table"
}, {
"title": "Time",
"type": "bigquery/time"
}, {
"title": "Timestamp",
"type": "bigquery/timestamp"
}]
}
61 changes: 34 additions & 27 deletions docs/contents/cloud-core.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
[{
"title": "Overview",
"type": "core/readme"
}, {
"title": "IAM",
"type": "core/iam/iam",
"patterns": [
"core/iam/\\w{1,}"
],
"nav": [{
"title": "PolicyBuilder",
"type": "core/iam/policybuilder"
}]
}, {
"title": "Upload",
"type": "core/upload/abstractuploader",
"nav": [{
"title": "MultipartUploader",
"type": "core/upload/multipartuploader"
{
"title": "Core",
"pattern": "core\/\\w{1,}",
"services": [{
"title": "Overview",
"type": "core/readme"
}, {
"title": "IAM",
"type": "core/iam/iam",
"patterns": [
"core/iam/\\w{1,}"
],
"nav": [{
"title": "PolicyBuilder",
"type": "core/iam/policybuilder"
}]
}, {
"title": "ResumableUploader",
"type": "core/upload/resumableuploader"
"title": "Upload",
"type": "core/upload/abstractuploader",
"patterns": [
"core/upload/\\w{1,}"
],
"nav": [{
"title": "MultipartUploader",
"type": "core/upload/multipartuploader"
}, {
"title": "ResumableUploader",
"type": "core/upload/resumableuploader"
}, {
"title": "StreamableUploader",
"type": "core/upload/streamableuploader"
}]
}, {
"title": "StreamableUploader",
"type": "core/upload/streamableuploader"
"title": "Int64",
"type": "core/int64"
}]
}, {
"title": "Int64",
"type": "core/int64"
}]
}
Loading