Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
acde64c8
Commit
acde64c8
authored
Mar 07, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished guide command refactoring
parent
740a7694
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
92 additions
and
32 deletions
+92
-32
events.md
docs/guide/events.md
+2
-2
README.md
extensions/apidoc/README.md
+26
-4
ApiController.php
extensions/apidoc/commands/ApiController.php
+21
-3
GuideController.php
extensions/apidoc/commands/GuideController.php
+12
-3
BaseController.php
extensions/apidoc/components/BaseController.php
+1
-1
BaseRenderer.php
extensions/apidoc/renderers/BaseRenderer.php
+13
-0
api.php
extensions/apidoc/templates/bootstrap/layouts/api.php
+1
-0
guide.php
extensions/apidoc/templates/bootstrap/layouts/guide.php
+4
-10
main.php
extensions/apidoc/templates/bootstrap/layouts/main.php
+10
-6
GuideRenderer.php
extensions/apidoc/templates/html/GuideRenderer.php
+2
-3
No files found.
docs/guide/events.md
View file @
acde64c8
...
@@ -115,14 +115,14 @@ Removing Event Handlers
...
@@ -115,14 +115,14 @@ Removing Event Handlers
The correspondoing
`off`
method removes an event handler:
The correspondoing
`off`
method removes an event handler:
```
php
```
php
//
$component->off($eventName);
$component
->
off
(
$eventName
);
```
```
Yii supports the ability to associate multiple handlers with the same event. When using
`off`
as in the above,
Yii supports the ability to associate multiple handlers with the same event. When using
`off`
as in the above,
every handler is removed. To remove only a specific handler, provide that as the second argument to
`off`
:
every handler is removed. To remove only a specific handler, provide that as the second argument to
`off`
:
```
php
```
php
//
$component->off($eventName, $handler);
$component
->
off
(
$eventName
,
$handler
);
```
```
The
`$handler`
should be presented in the
`off`
method in the same way as was presented in
`on`
in order to remove it.
The
`$handler`
should be presented in the
`off`
method in the same way as was presented in
`on`
in order to remove it.
...
...
extensions/apidoc/README.md
View file @
acde64c8
...
@@ -25,14 +25,36 @@ to the require section of your composer.json.
...
@@ -25,14 +25,36 @@ to the require section of your composer.json.
Usage
Usage
-----
-----
To generate API documentation, run the
`apidoc`
command.
This extension offers two commands:
-
`api`
to generate class API documentation.
-
`guide`
to render nice HTML pages from markdown files such as the yii guide.
Simple usage for stand alone class documentation:
```
vendor/bin/apidoc api source/directory ./output
```
Simple usage for stand alone guide documentation:
```
vendor/bin/apidoc guide source/docs ./output
```
You can combine them to generate class API and guide doc in one place:
```
```
vendor/bin/apidoc source/directory ./output
# first generate guide docs to allow links from code to guide you may skip this if you do not need these.
vendor/bin/apidoc guide source/docs ./output
# second generate API docs
vendor/bin/apidoc api source/directory ./output
# third run guide docs again to have class links enabled
vendor/bin/apidoc guide source/docs ./output
```
```
By default the
`
offline
`
template will be used. You can choose a different templates with the
`--template=name`
parameter.
By default the
`
bootstrap
`
template will be used. You can choose a different templates with the
`--template=name`
parameter.
Currently there is only the
`
offline
`
template available.
Currently there is only the
`
bootstrap
`
template available.
You may also add the
`yii\apidoc\commands\RenderController`
to your console application class map and
You may also add the
`yii\apidoc\commands\RenderController`
to your console application class map and
run it inside of your applications console app.
run it inside of your applications console app.
...
...
extensions/apidoc/commands/ApiController.php
View file @
acde64c8
<?php
<?php
/**
/**
* @author Carsten Brandt <mail@cebe.cc>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\apidoc\commands
;
namespace
yii\apidoc\commands
;
use
yii\apidoc\components\BaseController
;
use
yii\apidoc\renderers\ApiRenderer
;
use
yii\apidoc\renderers\ApiRenderer
;
use
yii\apidoc\renderers\BaseRenderer
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Console
;
use
yii\helpers\Console
;
use
yii\helpers\FileHelper
;
use
yii\helpers\FileHelper
;
/**
* Generate class API documentation
*
*/
class
ApiController
extends
BaseController
class
ApiController
extends
BaseController
{
{
/**
/**
...
@@ -36,8 +44,18 @@ class ApiController extends BaseController
...
@@ -36,8 +44,18 @@ class ApiController extends BaseController
// setup reference to guide
// setup reference to guide
if
(
$this
->
guide
!==
null
)
{
if
(
$this
->
guide
!==
null
)
{
$renderer
->
guideUrl
=
$this
->
guide
;
$guideUrl
=
$this
->
guide
;
$renderer
->
guideReferences
=
[];
// TODO set references
$referenceFile
=
$guideUrl
.
'/'
.
BaseRenderer
::
GUIDE_PREFIX
.
'references.txt'
;
}
else
{
$guideUrl
=
'./'
;
$referenceFile
=
$targetDir
.
'/'
.
BaseRenderer
::
GUIDE_PREFIX
.
'references.txt'
;
}
if
(
file_exists
(
$referenceFile
))
{
$renderer
->
guideUrl
=
$guideUrl
;
$renderer
->
guideReferences
=
[];
foreach
(
explode
(
"
\n
"
,
file_get_contents
(
$referenceFile
))
as
$reference
)
{
$renderer
->
guideReferences
[
BaseRenderer
::
GUIDE_PREFIX
.
$reference
]
=
$renderer
->
generateGuideUrl
(
$reference
);
}
}
}
// search for files to process
// search for files to process
...
...
extensions/apidoc/commands/GuideController.php
View file @
acde64c8
<?php
<?php
/**
/**
* @author Carsten Brandt <mail@cebe.cc>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\apidoc\commands
;
namespace
yii\apidoc\commands
;
use
yii\apidoc\components\BaseController
;
use
yii\apidoc\models\Context
;
use
yii\apidoc\models\Context
;
use
yii\apidoc\renderers\BaseRenderer
;
use
yii\apidoc\renderers\BaseRenderer
;
use
yii\apidoc\renderers\GuideRenderer
;
use
yii\apidoc\renderers\GuideRenderer
;
...
@@ -38,6 +41,8 @@ class GuideController extends BaseController
...
@@ -38,6 +41,8 @@ class GuideController extends BaseController
return
1
;
return
1
;
}
}
$renderer
->
guideUrl
=
'./'
;
// setup reference to apidoc
// setup reference to apidoc
if
(
$this
->
apiDocs
!==
null
)
{
if
(
$this
->
apiDocs
!==
null
)
{
$renderer
->
apiUrl
=
$this
->
apiDocs
;
$renderer
->
apiUrl
=
$this
->
apiDocs
;
...
@@ -59,8 +64,12 @@ class GuideController extends BaseController
...
@@ -59,8 +64,12 @@ class GuideController extends BaseController
}
}
$this
->
stdout
(
'done.'
.
PHP_EOL
,
Console
::
FG_GREEN
);
$this
->
stdout
(
'done.'
.
PHP_EOL
,
Console
::
FG_GREEN
);
// generate api references.txt
// TODO generate api references.txt
$references
=
[];
foreach
(
$files
as
$file
)
{
$references
[]
=
basename
(
$file
,
'.md'
);
}
file_put_contents
(
$targetDir
.
'/guide-references.txt'
,
implode
(
"
\n
"
,
$references
));
}
}
protected
function
findFiles
(
$path
,
$except
=
[
'README.md'
])
protected
function
findFiles
(
$path
,
$except
=
[
'README.md'
])
...
...
extensions/apidoc/components/BaseController.php
View file @
acde64c8
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\apidoc\com
mand
s
;
namespace
yii\apidoc\com
ponent
s
;
use
yii\apidoc\renderers\BaseRenderer
;
use
yii\apidoc\renderers\BaseRenderer
;
use
yii\console\Controller
;
use
yii\console\Controller
;
...
...
extensions/apidoc/renderers/BaseRenderer.php
View file @
acde64c8
...
@@ -31,6 +31,8 @@ use yii\helpers\Html;
...
@@ -31,6 +31,8 @@ use yii\helpers\Html;
*/
*/
abstract
class
BaseRenderer
extends
Component
abstract
class
BaseRenderer
extends
Component
{
{
const
GUIDE_PREFIX
=
'guide-'
;
public
$apiUrl
;
public
$apiUrl
;
/**
/**
* @var Context the [[Context]] currently being rendered.
* @var Context the [[Context]] currently being rendered.
...
@@ -160,4 +162,14 @@ abstract class BaseRenderer extends Component
...
@@ -160,4 +162,14 @@ abstract class BaseRenderer extends Component
* @return mixed
* @return mixed
*/
*/
public
abstract
function
generateApiUrl
(
$typeName
);
public
abstract
function
generateApiUrl
(
$typeName
);
/**
* Generate an url to a guide page
* @param string $file
* @return string
*/
public
function
generateGuideUrl
(
$file
)
{
return
rtrim
(
$this
->
guideUrl
,
'/'
)
.
'/'
.
static
::
GUIDE_PREFIX
.
basename
(
$file
,
'.md'
)
.
'.html'
;
}
}
}
\ No newline at end of file
extensions/apidoc/templates/bootstrap/layouts/api.php
View file @
acde64c8
<?php
<?php
use
yii\apidoc\templates\bootstrap\ApiRenderer
;
use
yii\apidoc\templates\bootstrap\ApiRenderer
;
use
yii\apidoc\templates\bootstrap\SideNavWidget
;
use
yii\apidoc\templates\bootstrap\SideNavWidget
;
use
yii\helpers\StringHelper
;
use
yii\helpers\StringHelper
;
...
...
extensions/apidoc/templates/bootstrap/layouts/guide.php
View file @
acde64c8
<?php
<?php
use
yii\apidoc\templates\bootstrap\SideNavWidget
;
use
yii\apidoc\templates\bootstrap\SideNavWidget
;
/**
/**
...
@@ -15,20 +16,13 @@ $this->beginContent('@yii/apidoc/templates/bootstrap/layouts/main.php'); ?>
...
@@ -15,20 +16,13 @@ $this->beginContent('@yii/apidoc/templates/bootstrap/layouts/main.php'); ?>
$nav
=
[];
$nav
=
[];
$nav
[]
=
[
$nav
[]
=
[
'label'
=>
'Index'
,
'label'
=>
'Index'
,
'url'
=>
'./guide_index.html'
,
'url'
=>
$this
->
context
->
generateGuideUrl
(
'index.md'
)
,
'active'
=>
isset
(
$currentFile
)
&&
(
basename
(
$currentFile
)
==
'index.md'
),
'active'
=>
isset
(
$currentFile
)
&&
(
basename
(
$currentFile
)
==
'index.md'
),
];
];
foreach
(
$headlines
as
$file
=>
$headline
)
{
foreach
(
$headlines
as
$file
=>
$headline
)
{
// if (!isset($nav[$namespace])) {
$nav
[]
=
[
// $nav[$namespace] = [
// 'label' => $namespace,
// 'url' => '#',
// 'items' => [],
// ];
// }
$nav
/*[$namespace]['items']*/
[]
=
[
'label'
=>
$headline
,
'label'
=>
$headline
,
'url'
=>
'./guide_'
.
str_replace
(
'.md'
,
'.html'
,
basename
(
$file
)
),
'url'
=>
$this
->
context
->
generateGuideUrl
(
$file
),
'active'
=>
isset
(
$currentFile
)
&&
(
$file
==
$currentFile
),
'active'
=>
isset
(
$currentFile
)
&&
(
$file
==
$currentFile
),
];
];
}
?>
}
?>
...
...
extensions/apidoc/templates/bootstrap/layouts/main.php
View file @
acde64c8
<?php
<?php
use
yii\apidoc\renderers\BaseRenderer
;
use
yii\bootstrap\Nav
;
use
yii\bootstrap\Nav
;
use
yii\bootstrap\NavBar
;
use
yii\bootstrap\NavBar
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
...
@@ -17,7 +19,7 @@ $this->registerJs(<<<JS
...
@@ -17,7 +19,7 @@ $this->registerJs(<<<JS
window.addEventListener("hashchange", shiftWindow);
window.addEventListener("hashchange", shiftWindow);
JS
JS
,
,
\yii\web\View
::
POS_
HEAD
\yii\web\View
::
POS_
READY
);
);
$this
->
beginPage
();
$this
->
beginPage
();
...
@@ -38,16 +40,17 @@ $this->beginPage();
...
@@ -38,16 +40,17 @@ $this->beginPage();
<?php
<?php
NavBar
::
begin
([
NavBar
::
begin
([
'brandLabel'
=>
$this
->
context
->
pageTitle
,
'brandLabel'
=>
$this
->
context
->
pageTitle
,
'brandUrl'
=>
'./index.html'
,
'brandUrl'
=>
(
$this
->
context
->
apiUrl
===
null
&&
$this
->
context
->
guideUrl
!==
null
)
?
'./guide-index.html'
:
'./index.html'
,
'options'
=>
[
'options'
=>
[
'class'
=>
'navbar-inverse navbar-fixed-top'
,
'class'
=>
'navbar-inverse navbar-fixed-top'
,
],
],
'renderInnerContainer'
=>
false
,
'renderInnerContainer'
=>
false
,
'view'
=>
$this
,
'view'
=>
$this
,
]);
]);
$nav
=
[
$nav
=
[];
[
'label'
=>
'Class reference'
,
'url'
=>
'./index.html'
],
];
if
(
$this
->
context
->
apiUrl
!==
null
)
{
$nav
[]
=
[
'label'
=>
'Class reference'
,
'url'
=>
rtrim
(
$this
->
context
->
apiUrl
,
'/'
)
.
'/index.html'
];
if
(
!
empty
(
$this
->
context
->
extensions
))
if
(
!
empty
(
$this
->
context
->
extensions
))
{
{
$extItems
=
[];
$extItems
=
[];
...
@@ -59,9 +62,10 @@ $this->beginPage();
...
@@ -59,9 +62,10 @@ $this->beginPage();
}
}
$nav
[]
=
[
'label'
=>
'Extensions'
,
'items'
=>
$extItems
];
$nav
[]
=
[
'label'
=>
'Extensions'
,
'items'
=>
$extItems
];
}
}
}
if
(
$this
->
context
->
guideUrl
!==
null
)
{
if
(
$this
->
context
->
guideUrl
!==
null
)
{
$nav
[]
=
[
'label'
=>
'Guide'
,
'url'
=>
$this
->
context
->
guideUrl
.
'guide_
index.html'
];
$nav
[]
=
[
'label'
=>
'Guide'
,
'url'
=>
rtrim
(
$this
->
context
->
guideUrl
,
'/'
)
.
'/'
.
BaseRenderer
::
GUIDE_PREFIX
.
'
index.html'
];
}
}
echo
Nav
::
widget
([
echo
Nav
::
widget
([
...
...
extensions/apidoc/templates/html/GuideRenderer.php
View file @
acde64c8
...
@@ -115,10 +115,9 @@ abstract class GuideRenderer extends BaseGuideRenderer
...
@@ -115,10 +115,9 @@ abstract class GuideRenderer extends BaseGuideRenderer
}
}
}
}
// TODO move these to guide renderer
protected
function
generateGuideFileName
(
$file
)
protected
function
generateGuideFileName
(
$file
)
{
{
return
'guide_'
.
basename
(
$file
,
'.md'
)
.
'.html'
;
return
static
::
GUIDE_PREFIX
.
basename
(
$file
,
'.md'
)
.
'.html'
;
}
}
public
function
getGuideReferences
()
public
function
getGuideReferences
()
...
@@ -134,7 +133,7 @@ abstract class GuideRenderer extends BaseGuideRenderer
...
@@ -134,7 +133,7 @@ abstract class GuideRenderer extends BaseGuideRenderer
protected
function
fixMarkdownLinks
(
$content
)
protected
function
fixMarkdownLinks
(
$content
)
{
{
$content
=
preg_replace
(
'/href\s*=\s*"([^"\/]+)\.md(#.*)?"/i'
,
'href="
guide_
\1.html\2"'
,
$content
);
$content
=
preg_replace
(
'/href\s*=\s*"([^"\/]+)\.md(#.*)?"/i'
,
'href="
'
.
static
::
GUIDE_PREFIX
.
'
\1.html\2"'
,
$content
);
return
$content
;
return
$content
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment