This repository has been archived by the owner on Feb 16, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aa8d086
Showing
92 changed files
with
7,679 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CHANGELOG | ||
========= | ||
|
||
* 0.8 (2012-05-15) | ||
|
||
* initial Open-Source version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2010-2012 Fabien Potencier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
Sami: an API documentation generator | ||
==================================== | ||
|
||
Curious about what Sami generates? Have a look at the [Symfony | ||
API](http://api.symfony.com/). | ||
|
||
Installation | ||
------------ | ||
|
||
First, get Sami from [Github](https://github.com/fabpot/Sami) (or integrate it | ||
as a dependency in your project [Composer](packagist.org/fabpot/Sami) file -- | ||
you are using [Composer](http://getcomposer.org/), right?): | ||
|
||
https://github.com/fabpot/Sami | ||
|
||
You can also download an [archive](https://github.com/fabpot/Sami/downloads) | ||
from Github. | ||
|
||
As Sami uses Composer to manage its dependencies, installing it is a matter of | ||
running composer: | ||
|
||
$ composer.phar install | ||
|
||
Check that everything worked as expected by executing the `sami.php` file | ||
without any arguments: | ||
|
||
$ php sami.php | ||
|
||
Configuration | ||
------------- | ||
|
||
Before generating documentation, you must create a configuration file. Here is | ||
the simplest possible one: | ||
|
||
<?php | ||
|
||
return new Sami\Sami('/path/to/symfony/src'); | ||
|
||
The configuration file must return an instance of `Sami\Sami` and the first | ||
argument of the constructor is the path to the code you want to generate | ||
documentation for. | ||
|
||
Actually, instead of a directory, you can use any valid PHP iterator (and for | ||
that matter any instance of the Symfony | ||
[Finder](http://symfony.com/doc/current/components/finder.html) class): | ||
|
||
<?php | ||
|
||
use Sami\Sami; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
$iterator = Finder::create() | ||
->files() | ||
->name('*.php') | ||
->exclude('Resources') | ||
->exclude('Tests') | ||
->in('/path/to/symfony/src') | ||
; | ||
|
||
return new Sami($iterator); | ||
|
||
The `Sami` constructor optionally takes an array of options as a second | ||
argument: | ||
|
||
return new Sami($iterator, array( | ||
'theme' => 'symfony', | ||
'title' => 'Symfony2 API', | ||
'build_dir' => __DIR__.'/build', | ||
'cache_dir' => __DIR__.'/cache', | ||
'default_opened_level' => 2, | ||
)); | ||
|
||
And here is how you can configure different versions: | ||
|
||
<?php | ||
|
||
use Sami\Sami; | ||
use Sami\Version\GitVersionCollection; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
$iterator = Finder::create() | ||
->files() | ||
->name('*.php') | ||
->exclude('Resources') | ||
->exclude('Tests') | ||
->in($dir = '/path/to/symfony/src') | ||
; | ||
|
||
// generate documentation for all v2.0.* tags, the 2.0 branch, and the master one | ||
$versions = GitVersionCollection::create($dir) | ||
->addFromTags('v2.0.*') | ||
->add('2.0', '2.0 branch') | ||
->add('master', 'master branch') | ||
; | ||
|
||
return new Sami($iterator, array( | ||
'theme' => 'symfony', | ||
'versions' => $versions, | ||
'title' => 'Symfony2 API', | ||
'build_dir' => __DIR__.'/../build/sf2/%version%', | ||
'cache_dir' => __DIR__.'/../cache/sf2/%version%', | ||
'default_opened_level' => 2, | ||
)); | ||
|
||
To generate documentation for a PHP 5.2 project, simply set the | ||
`simulate_namespaces` option to `true`. | ||
|
||
You can find more configuration examples under the `examples/` directory of | ||
the source code. | ||
|
||
Rendering | ||
--------- | ||
|
||
Now that we have a configuration file, let's generate the API documentation: | ||
|
||
$ php sami.php update /path/to/config.php | ||
|
||
The generated documentation can be found under the configured `build/` | ||
directory (note that the client side search engine does not work on Chrome due | ||
to JavaScript execution restriction -- it works fine in Firefox). | ||
|
||
By default, Sami is configured to run in "incremental" mode. It means that | ||
when running the `update` command, Sami only re-generates the files that needs | ||
to be updated based on what has changed in your code since the last execution. | ||
|
||
Sami also detects problems in your phpdoc and can tell you what you need to | ||
fix if you add the `-v` option: | ||
|
||
$ php sami.php update /path/to/config.php -v | ||
|
||
Creating a Theme | ||
---------------- | ||
|
||
If the default themes do not suit your needs, you can very easily create a new | ||
one, or just override an existing one. | ||
|
||
A theme is just a directory with a `manifest.yml` file that describes the | ||
theme (this is a YAML file): | ||
|
||
name: symfony | ||
parent: enhanced | ||
|
||
The above configuration creates a new `symfony` theme based on the `enhanced` | ||
built-in theme. To override a template, just create a file with the same name | ||
as the original one. For instance, here is how you can extend the default | ||
class template to prefix the class name with "Class " in the class page title: | ||
|
||
{# pages/class.twig #} | ||
|
||
{% extends 'default/pages/class.twig' %} | ||
|
||
{% block title %}Class {{ parent() }}{% endblock %} | ||
|
||
If you are familiar with Twig, you will be able to very easily tweak every | ||
aspect of the templates as everything has been well isolated in named Twig | ||
blocks. | ||
|
||
A theme can also add more templates and static files. Here is the manifest for | ||
the default theme: | ||
|
||
name: default | ||
|
||
static: | ||
'stylesheet.css': 'stylesheet.css' | ||
|
||
global: | ||
'index.twig': 'index.html' | ||
'namespaces.twig': 'namespaces-frame.html' | ||
'classes.twig': 'classes-frame.html' | ||
'pages/opensearch.twig': 'opensearch.xml' | ||
'pages/index.twig': 'doc-index.html' | ||
'pages/namespaces.twig': 'namespaces.html' | ||
'pages/interfaces.twig': 'interfaces.html' | ||
'pages/classes.twig': 'classes.html' | ||
|
||
namespace: | ||
'namespace.twig': '%s/namespace-frame.html' | ||
'pages/namespace.twig': '%s.html' | ||
|
||
class: | ||
'pages/class.twig': '%s.html' | ||
|
||
Files are contained into sections, depending on how Sami needs to treat them: | ||
|
||
* `static`: Files are copied as is (for assets like images, stylesheets, or | ||
JavaScript files); | ||
|
||
* `global`: Templates that do not depend on the current class context; | ||
|
||
* `namespace`: Templates that should be generated for every namespace; | ||
|
||
* `class`: Templates that should be generated for every class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sami utility. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sami\Console; | ||
|
||
use Symfony\Component\Console\Application as BaseApplication; | ||
use Sami\Console\Command\UpdateCommand; | ||
use Sami\Console\Command\ParseCommand; | ||
use Sami\Console\Command\RenderCommand; | ||
use Sami\Sami; | ||
use Sami\ErrorHandler; | ||
|
||
class Application extends BaseApplication | ||
{ | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
error_reporting(-1); | ||
ErrorHandler::register(); | ||
|
||
parent::__construct('Sami', Sami::VERSION); | ||
|
||
$this->add(new UpdateCommand()); | ||
$this->add(new ParseCommand()); | ||
$this->add(new RenderCommand()); | ||
} | ||
|
||
public function getLongVersion() | ||
{ | ||
return parent::getLongVersion().' by <comment>Fabien Potencier</comment>'; | ||
} | ||
} |
Oops, something went wrong.