Since: 2.0
Author: Carsten Brandt (mail@cebe.cc)
Inheritance: extends cebe\markdown\GithubMarkdown
 /**
  * Renders API documentation files
  * @param array $sourceDirs
  * @param string $targetDir
  * @return integer
  */
 public function actionIndex(array $sourceDirs, $targetDir)
 {
     $renderer = $this->findRenderer($this->template);
     $targetDir = $this->normalizeTargetDir($targetDir);
     if ($targetDir === false || $renderer === false) {
         return 1;
     }
     if ($this->pageTitle !== null) {
         $renderer->pageTitle = $this->pageTitle;
     }
     if ($renderer->guideUrl === null) {
         $renderer->guideUrl = './';
     }
     $renderer->guidePrefix = $this->guidePrefix;
     // setup reference to apidoc
     if ($this->apiDocs !== null) {
         $path = $this->apiDocs;
         if ($renderer->apiUrl === null) {
             $renderer->apiUrl = $path;
         }
         // use relative paths relative to targetDir
         if (strncmp($path, '.', 1) === 0) {
             $renderer->apiContext = $this->loadContext("{$targetDir}/{$path}");
         } else {
             $renderer->apiContext = $this->loadContext($path);
         }
     } elseif (file_exists($targetDir . '/cache/apidoc.data')) {
         if ($renderer->apiUrl === null) {
             $renderer->apiUrl = './';
         }
         $renderer->apiContext = $this->loadContext($targetDir);
     } else {
         $renderer->apiContext = new Context();
     }
     $this->updateContext($renderer->apiContext);
     // read blocktypes translations
     ApiMarkdown::$blockTranslations = [];
     foreach ($sourceDirs as $dir) {
         if (is_file("{$dir}/blocktypes.json")) {
             ApiMarkdown::$blockTranslations = Json::decode(file_get_contents("{$dir}/blocktypes.json"), true);
         }
     }
     // search for files to process
     if (($files = $this->searchFiles($sourceDirs)) === false) {
         return 1;
     }
     $renderer->controller = $this;
     $renderer->render($files, $targetDir);
     $this->stdout('Publishing images...');
     foreach ($sourceDirs as $source) {
         $imageDir = rtrim($source, '/\\') . '/images';
         if (file_exists($imageDir)) {
             FileHelper::copyDirectory($imageDir, $targetDir . '/images');
         }
     }
     $this->stdout('done.' . PHP_EOL, Console::FG_GREEN);
 }
Esempio n. 2
0
 /**
  * Renders a given [[Context]].
  *
  * @param Controller $controller the apidoc controller instance. Can be used to control output.
  */
 public function render($files, $targetDir)
 {
     $this->_targetDir = $targetDir;
     $fileCount = count($files) + 1;
     if ($this->controller !== null) {
         Console::startProgress(0, $fileCount, 'Rendering markdown files: ', false);
     }
     $done = 0;
     $fileData = [];
     $headlines = [];
     foreach ($files as $file) {
         $fileData[$file] = file_get_contents($file);
         if (basename($file) == 'index.md') {
             continue;
             // to not add index file to nav
         }
         if (preg_match("/^(.*)\n=+/", $fileData[$file], $matches)) {
             $headlines[$file] = $matches[1];
         } else {
             $headlines[$file] = basename($file);
         }
     }
     foreach ($fileData as $file => $content) {
         $output = ApiMarkdown::process($content);
         // TODO generate links to yiiframework.com by default
         $output = $this->fixMarkdownLinks($output);
         if ($this->layout !== false) {
             $params = ['headlines' => $headlines, 'currentFile' => $file, 'content' => $output];
             $output = $this->getView()->renderFile($this->layout, $params, $this);
         }
         $fileName = $this->generateGuideFileName($file);
         file_put_contents($targetDir . '/' . $fileName, $output);
         if ($this->controller !== null) {
             Console::updateProgress(++$done, $fileCount);
         }
     }
     if ($this->controller !== null) {
         Console::updateProgress(++$done, $fileCount);
         Console::endProgress(true);
         $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
     }
 }
 public function init()
 {
     ApiMarkdown::$renderer = $this;
     ApiMarkdownLaTeX::$renderer = $this;
 }
Esempio n. 4
0
    ?>
 id="<?php 
    echo $event->name;
    ?>
">
        <td><?php 
    echo $renderer->createSubjectLink($event);
    ?>
</td>
        <td><?php 
    echo $renderer->createTypeLink($event->types);
    ?>
</td>
        <td>
            <?php 
    echo ApiMarkdown::process($event->shortDescription, $event->definedBy, true);
    ?>
            <?php 
    if (!empty($event->since)) {
        ?>
                (available since version <?php 
        echo $event->since;
        ?>
)
            <?php 
    }
    ?>
        </td>
        <td><?php 
    echo $renderer->createTypeLink($event->definedBy);
    ?>
Esempio n. 5
0
</td>
                </tr>
            <?php 
        }
        ?>
            <?php 
        foreach ($method->exceptions as $exception => $description) {
            ?>
                <tr>
                  <th class="param-name-col">throws</th>
                  <td class="param-type-col"><?php 
            echo $renderer->createTypeLink($exception);
            ?>
</td>
                  <td class="param-desc-col"><?php 
            echo ApiMarkdown::process($description, $type);
            ?>
</td>
                </tr>
            <?php 
        }
        ?>
        <?php 
    }
    ?>
    </table>

<!--	--><?php 
    //$this->renderPartial('sourceCode',array('object'=>$method));
    ?>
Esempio n. 6
0
<h1>Class Reference</h1>

<table class="summaryTable docIndex">
    <colgroup>
        <col class="col-package" />
        <col class="col-class" />
        <col class="col-description" />
    </colgroup>
    <tr>
        <th>Class</th>
        <th>Description</th>
    </tr>
<?php 
ksort($types);
foreach ($types as $i => $class) {
    ?>
    <tr>
        <td><?php 
    echo $this->context->typeLink($class, $class->name);
    ?>
</td>
        <td><?php 
    echo \yii\apidoc\helpers\ApiMarkdown::process($class->shortDescription, $class, true);
    ?>
</td>
    </tr>
<?php 
}
?>
</table>
Esempio n. 7
0
        of type <?php 
    echo $renderer->createTypeLink($event->types);
    ?>
        <?php 
    if (!empty($event->since)) {
        ?>
            (available since version <?php 
        echo $event->since;
        ?>
)
        <?php 
    }
    ?>
        </span>
    </div>

    <div class="doc-description">
        <?php 
    echo ApiMarkdown::process($event->description, $type);
    ?>

        <?php 
    echo $this->render('seeAlso', ['object' => $event]);
    ?>
    </div>

<?php 
}
?>
</div>
Esempio n. 8
0
 /**
  * @param MethodDoc $method
  * @return string
  */
 public function renderMethodSignature($method, $context = null)
 {
     $params = [];
     foreach ($method->params as $param) {
         $params[] = (empty($param->typeHint) ? '' : '<span class="signature-type">' . $this->createTypeLink($param->typeHint, $context) . '</span> ') . ($param->isPassedByReference ? '<b>&</b>' : '') . ApiMarkdown::highlight($param->name . ($param->isOptional ? ' = ' . $param->defaultValue : ''), 'php');
     }
     $definition = [];
     $definition[] = $method->visibility;
     if ($method->isAbstract) {
         $definition[] = 'abstract';
     }
     if ($method->isStatic) {
         $definition[] = 'static';
     }
     return '<span class="signature-defs">' . implode(' ', $definition) . '</span> ' . '<span class="signature-type">' . ($method->isReturnByReference ? '<b>&</b>' : '') . ($method->returnType === null ? 'void' : $this->createTypeLink($method->returnTypes, $context)) . '</span> ' . '<strong>' . $this->createSubjectLink($method, $method->name) . '</strong>' . str_replace('  ', ' ', ' ( ' . implode(', ', $params) . ' )');
 }
Esempio n. 9
0
 /**
  * @param MethodDoc $method
  * @return string
  */
 public function renderMethodSignature($method)
 {
     $params = [];
     foreach ($method->params as $param) {
         $params[] = (empty($param->typeHint) ? '' : $param->typeHint . ' ') . ($param->isPassedByReference ? '<b>&</b>' : '') . $param->name . ($param->isOptional ? ' = ' . $param->defaultValue : '');
     }
     return ($method->isReturnByReference ? '<b>&</b>' : '') . ($method->returnType === null ? 'void' : $this->createTypeLink($method->returnTypes)) . ' <strong>' . $this->createSubjectLink($method, $method->name) . '</strong>' . ApiMarkdown::highlight(str_replace('  ', ' ', '( ' . implode(', ', $params) . ' )'), 'php');
 }
Esempio n. 10
0
    <tr<?php 
        echo $property->definedBy != $type->name ? ' class="inherited"' : '';
        ?>
 id="<?php 
        echo $property->name;
        ?>
">
        <td><?php 
        echo $renderer->createSubjectLink($property);
        ?>
</td>
        <td><?php 
        echo $renderer->createTypeLink($property->types);
        ?>
</td>
        <td><?php 
        echo ApiMarkdown::process($property->shortDescription, $property->definedBy, true);
        ?>
</td>
        <td><?php 
        echo $renderer->createTypeLink($property->definedBy);
        ?>
</td>
    </tr>
    <?php 
    }
}
?>
</table>
</div>
Esempio n. 11
0
    ?>
 id="<?php 
    echo $constant->name;
    ?>
">
          <td id="<?php 
    echo $constant->name;
    ?>
-detail"><?php 
    echo $constant->name;
    ?>
</td>
          <td><?php 
    echo $constant->value;
    ?>
</td>
          <td><?php 
    echo ApiMarkdown::process($constant->shortDescription . "\n" . $constant->description, $constant->definedBy, true);
    ?>
</td>
          <td><?php 
    echo $renderer->createTypeLink($constant->definedBy);
    ?>
</td>
        </tr>
    <?php 
}
?>
    </table>
</div>
Esempio n. 12
0
    ?>
    <?php 
    if ($protected && $method->visibility == 'protected' || !$protected && $method->visibility != 'protected') {
        ?>
    <tr<?php 
        echo $method->definedBy != $type->name ? ' class="inherited"' : '';
        ?>
 id="<?php 
        echo $method->name;
        ?>
()">
        <td><?php 
        echo $renderer->createSubjectLink($method, $method->name . '()');
        ?>
</td>
        <td><?php 
        echo ApiMarkdown::process($method->shortDescription, $method->definedBy, true);
        ?>
</td>
        <td><?php 
        echo $renderer->createTypeLink($method->definedBy, $type);
        ?>
</td>
    </tr>
    <?php 
    }
}
?>
</table>
</div>
Esempio n. 13
0
        if (!empty($property->deprecatedSince)) {
            echo 'since version ' . $property->deprecatedSince . ': ';
        }
        if (!empty($property->deprecatedReason)) {
            echo ApiMarkdown::process($property->deprecatedReason, $type, true);
        }
        ?>
</strong>
        </div>
    <?php 
    }
    ?>

    <div class="doc-description">
        <?php 
    echo ApiMarkdown::process($property->description, $type);
    ?>

        <?php 
    echo $this->render('seeAlso', ['object' => $property]);
    ?>
    </div>

    <div class="signature"><?php 
    echo $renderer->renderPropertySignature($property, $type);
    ?>
</div>

<?php 
}
?>
Esempio n. 14
0
<?php

/* @var $object yii\apidoc\models\BaseDoc */
/* @var $this yii\web\View */
$type = $object instanceof \yii\apidoc\models\TypeDoc ? $object : $object->definedBy;
$see = [];
foreach ($object->tags as $tag) {
    /** @var $tag phpDocumentor\Reflection\DocBlock\Tag\SeeTag */
    if (get_class($tag) == 'phpDocumentor\\Reflection\\DocBlock\\Tag\\SeeTag') {
        $ref = $tag->getReference();
        if (strpos($ref, '://') === false) {
            $ref = '[[' . $ref . ']]';
        }
        $see[] = rtrim(\yii\apidoc\helpers\ApiMarkdown::process($ref . ' ' . $tag->getDescription(), $type, true), ". \r\n");
    }
}
if (empty($see)) {
    return;
} elseif (count($see) == 1) {
    echo '<p>See also ' . reset($see) . '.</p>';
} else {
    echo '<p>See also:</p><ul>';
    foreach ($see as $ref) {
        if (!empty($ref)) {
            if (substr_compare($ref, '>', -1, 1)) {
                $ref .= '.';
            }
            echo "<li>{$ref}</li>";
        }
    }
    echo '</ul>';
Esempio n. 15
0
<?php

/**
 * @var yii\apidoc\models\BaseDoc $object
 * @var yii\web\View $this
 */
$see = [];
foreach ($object->tags as $tag) {
    /** @var $tag phpDocumentor\Reflection\DocBlock\Tag\SeeTag */
    if (get_class($tag) == 'phpDocumentor\\Reflection\\DocBlock\\Tag\\SeeTag') {
        $ref = $tag->getReference();
        if (strpos($ref, '://') === false) {
            $ref = '[[' . $ref . ']]';
        }
        $see[] = rtrim(\yii\apidoc\helpers\ApiMarkdown::process($ref . ' ' . $tag->getDescription(), $object->definedBy, true), ". \r\n");
    }
}
if (empty($see)) {
    return;
} elseif (count($see) == 1) {
    echo '<p>See also ' . reset($see) . '.</p>';
} else {
    echo '<p>See also:</p><ul>';
    foreach ($see as $ref) {
        if (substr($ref, -1, 1) != '>') {
            $ref .= '.';
        }
        echo "<li>{$ref}</li>";
    }
    echo '</ul>';
}
Esempio n. 16
0
          <td><?php 
    echo $constant->value;
    ?>
</td>
          <td><?php 
    echo ApiMarkdown::process($constant->shortDescription . "\n" . $constant->description, $constant->definedBy, true);
    ?>
              <?php 
    if (!empty($constant->deprecatedSince) || !empty($constant->deprecatedReason)) {
        ?>
                  <strong>Deprecated <?php 
        if (!empty($constant->deprecatedSince)) {
            echo 'since version ' . $constant->deprecatedSince . ': ';
        }
        if (!empty($constant->deprecatedReason)) {
            echo ApiMarkdown::process($constant->deprecatedReason, $type, true);
        }
        ?>
</strong>
              <?php 
    }
    ?>
          </td>
          <td><?php 
    echo $renderer->createTypeLink($constant->definedBy);
    ?>
</td>
        </tr>
    <?php 
}
?>