Since: 2.0
Author: Carsten Brandt (mail@cebe.cc)
Inheritance: extends yii\apidoc\renderers\ApiRenderer, implements yii\base\ViewContextInterface
Example #1
0
 /**
  * @inheritdoc
  */
 public function render($context, $targetDir)
 {
     parent::render($context, $targetDir);
     if ($this->controller !== null) {
         $this->controller->stdout("writing packages file...");
     }
     $packages = [];
     $notNamespaced = [];
     foreach (array_merge($context->classes, $context->interfaces, $context->traits) as $type) {
         /* @var $type TypeDoc */
         if (empty($type->namespace)) {
             $notNamespaced[] = str_replace('\\', '-', $type->name);
         } else {
             $packages[$type->namespace][] = str_replace('\\', '-', $type->name);
         }
     }
     ksort($packages);
     $packages = array_merge(['Not namespaced' => $notNamespaced], $packages);
     foreach ($packages as $name => $classes) {
         sort($packages[$name]);
     }
     file_put_contents($targetDir . '/packages.txt', serialize($packages));
     if ($this->controller !== null) {
         $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
     }
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function render($context, $targetDir)
 {
     $types = array_merge($context->classes, $context->interfaces, $context->traits);
     $extTypes = [];
     foreach ($this->extensions as $k => $ext) {
         $extType = $this->filterTypes($types, $ext);
         if (empty($extType)) {
             unset($this->extensions[$k]);
             continue;
         }
         $extTypes[$ext] = $extType;
     }
     // render view files
     parent::render($context, $targetDir);
     if ($this->controller !== null) {
         $this->controller->stdout('generating extension index files...');
     }
     foreach ($extTypes as $ext => $extType) {
         $readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-{$ext}/master/README.md");
         $indexFileContent = $this->renderWithLayout($this->indexView, ['docContext' => $context, 'types' => $extType, 'readme' => $readme ?: null]);
         file_put_contents($targetDir . "/ext-{$ext}-index.html", $indexFileContent);
     }
     $yiiTypes = $this->filterTypes($types, 'yii');
     if (empty($yiiTypes)) {
         //			$readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-framework/master/README.md");
         $indexFileContent = $this->renderWithLayout($this->indexView, ['docContext' => $context, 'types' => $this->filterTypes($types, 'app'), 'readme' => null]);
     } else {
         $readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-framework/master/README.md");
         $indexFileContent = $this->renderWithLayout($this->indexView, ['docContext' => $context, 'types' => $yiiTypes, 'readme' => $readme ?: null]);
     }
     file_put_contents($targetDir . '/index.html', $indexFileContent);
     if ($this->controller !== null) {
         $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
     }
 }
 /**
  * @inheritdoc
  */
 public function render($context, $targetDir)
 {
     echo "Phundament EE Docs Renderer\n";
     $types = array_merge($context->classes, $context->interfaces, $context->traits);
     $extTypes = [];
     foreach ($this->extensions as $k => $ext) {
         $extType = $this->filterTypes($types, $ext);
         if (empty($extType)) {
             unset($this->extensions[$k]);
             continue;
         }
         $extTypes[$ext] = $extType;
     }
     // render view files
     parent::render($context, $targetDir);
     if ($this->controller !== null) {
         $this->controller->stdout('generating extension index files...');
     }
     foreach ($extTypes as $ext => $extType) {
         $readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-{$ext}/master/README.md");
         $indexFileContent = $this->renderWithLayout($this->indexView, ['docContext' => $context, 'types' => $extType, 'readme' => $readme ?: null]);
         file_put_contents($targetDir . "/ext-{$ext}-index.html", $indexFileContent);
     }
     #$yiiTypes = $this->filterTypes($types, 'yii');
     #if (empty($yiiTypes)) {
     //			$readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-framework/master/README.md");
     $indexFileContent = $this->renderWithLayout($this->indexView, ['docContext' => $context, 'types' => $this->filterTypes($types, 'app'), 'readme' => null]);
     /*} else {
           $readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-framework/master/README.md");
           $indexFileContent = $this->renderWithLayout($this->indexView, [
               'docContext' => $context,
               'types' => $yiiTypes,
               'readme' => $readme ?: null,
           ]);
       }*/
     file_put_contents($targetDir . '/index.html', $indexFileContent);
     if ($this->controller !== null) {
         $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
         $this->controller->stdout('generating search index...');
     }
     $indexer = new ApiIndexer();
     $indexer->indexFiles(FileHelper::findFiles($targetDir, ['only' => ['*.html']]), $targetDir);
     $js = $indexer->exportJs();
     file_put_contents($targetDir . '/jssearch.index.js', $js);
     if ($this->controller !== null) {
         $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
     }
 }
 /**
  * @inheritdoc
  */
 public function render($context, $targetDir)
 {
     $types = array_merge($context->classes, $context->interfaces, $context->traits);
     $extTypes = [];
     foreach ($this->extensions as $k => $ext) {
         $extType = $this->filterTypes($types, $ext);
         if (empty($extType)) {
             unset($this->extensions[$k]);
             continue;
         }
         $extTypes[$ext] = $extType;
     }
     // render view files
     parent::render($context, $targetDir);
     if ($this->controller !== null) {
         $this->controller->stdout('generating extension index files...');
     }
     foreach ($extTypes as $ext => $extType) {
         $readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-{$ext}/master/README.md");
         $indexFileContent = $this->renderWithLayout($this->indexView, ['docContext' => $context, 'types' => $extType, 'readme' => $readme ?: null]);
         file_put_contents($targetDir . "/ext-{$ext}-index.html", $indexFileContent);
     }
     if ($this->controller !== null) {
         $this->controller->stdout("done.\n", Console::FG_GREEN);
     }
     // create index.html
     $yiiTypes = $this->filterTypes($types, 'yii');
     $indexFileContent = $this->renderWithLayout($this->indexView, ['docContext' => $context, 'types' => $yiiTypes, 'readme' => null]);
     file_put_contents($targetDir . '/index.html', $indexFileContent);
     // create file with page titles
     $titles = [];
     foreach ($types as $type) {
         $titles[$this->generateFileName($type->name)] = StringHelper::basename($type->name) . ", {$type->name}";
     }
     file_put_contents($targetDir . '/titles.php', '<?php return ' . VarDumper::export($titles) . ';');
     try {
         if ($this->controller !== null) {
             Console::startProgress(0, $count = count($types), 'populating elasticsearch index...', false);
         }
         // first delete all records for this version
         $version = $this->version;
         SearchApiType::setMappings();
         SearchApiPrimitive::setMappings();
         //        ApiPrimitive::deleteAllForVersion($version);
         SearchApiType::deleteAllForVersion($version);
         sleep(1);
         $i = 0;
         foreach ($types as $type) {
             SearchApiType::createRecord($type, $version);
             if ($this->controller !== null) {
                 Console::updateProgress(++$i, $count);
             }
         }
         if ($this->controller !== null) {
             Console::endProgress(true, true);
             $this->controller->stdout("done.\n", Console::FG_GREEN);
         }
     } catch (\Exception $e) {
         if (YII_DEBUG && $this->controller !== null) {
             $this->controller->stdout("!!! FAILED !!! Search will not be available.\n", Console::FG_RED, Console::BOLD);
             $this->controller->stdout((string) $e . "\n\n");
         } else {
             throw $e;
         }
     }
     //        if ($this->controller !== null) {
     //            $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
     //            $this->controller->stdout('generating search index...');
     //        }
     //
     //        $indexer = new ApiIndexer();
     //        $indexer->indexFiles(FileHelper::findFiles($targetDir, ['only' => ['*.html']]), $targetDir);
     //        $js = $indexer->exportJs();
     //        file_put_contents($targetDir . '/jssearch.index.js', $js);
     //
     //        if ($this->controller !== null) {
     //            $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
     //        }
 }