2017 © Pedro Peláez
 

yii2-module yii2-docs-module

Yii2 Documentaiton Viewer Module

image

webkadabra/yii2-docs-module

Yii2 Documentaiton Viewer Module

  • Friday, March 9, 2018
  • by Webkadabra
  • Repository
  • 1 Watchers
  • 0 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 15 % Grown

The README.md

yii2-docs-module

Advanced documentation viewer for Markdown or TXT files:, (*1)

  • automatically injects list of pages to index of each folder
  • supports multiple languages
  • callbacks for custom UI, breadcrumbs etc.

, (*2)

Installation via Composer

You can install package with a command:, (*3)

composer require webkadabra/yii2-docs-module, (*4)

Example usage with Yii2 Advanced App

Assume the following structure of your applicaiton's folders:, (*5)


/backend /docs /user /orders /fulfillment.md /frontend

Where fulfillment.md is your user documentaiton for (example) "Fulfillment operations". Anyways, add this module to your backend config first:, (*6)

// ...
'modules' => [
        // ...
        'docs' => [
            'class' => 'webkadabra\yii\modules\docs\Module',  
        ],
        // ...
],
// ...

Advanced configuration example (e.g. add breadcrumbs):, (*7)

// ...
'modules' => [
        // ...
        'docs' => [
            'class' => 'webkadabra\yii\modules\docs\Module',
            'layout' => '/docs',
            'on beforeAction' => function ($event) {
                /** @var yii\base\ActionEvent $event */
                Yii::$app->view->params['breadcrumbs'][] = [
                    'label' => Yii::t('app', ucfirst($event->sender->id)),
                    'url' => ['docs/docs/index'],
                ];
                $exs = explode('/', Yii::$app->request->getQueryParam('page'));
                $current = array_pop($exs);
                $path = [];
                foreach ($exs as $ex) {
                    $path[] = $ex;
                    Yii::$app->view->params['breadcrumbs'][] = [
                        'label' => ucwords(str_replace(['/', '_'], ['/', ' '], $ex)),
                        'url' => rawurldecode(\common\helpers\Url::toRoute(
                            [
                                'docs/docs/index',
                                'page' => implode('/', $path),
                            ]
                        )), 
                    ];
                }
                Yii::$app->view->params['breadcrumbs'][] = ucwords(str_replace(
                    ['/', '_'],
                    ['/', ' '],
                    $current
                ));
            },
        ],
        // ...
],
// ...

Add custom rule in urlManager component:, (*8)

// ...
'components' => [
  // ...
    'urlManager' => [
      'rules' => [
        'docs/<page:[\w\d\/_-]*>' => 'docs/docs/index',
      ],
    ],
  ],

Now you have your documentaiton available at http://backend.website.test/docs/user/orders/fulfillment, and going up a tree structure would bring index of documents in that directory, e.g.: http://backend.website.test/docs/user/ will bring list of documents in 'docs/user` directory (recursively)., (*9)

TODO

  • [x] Multilanguage support
  • [ ] Unit tests

Thanks, pull requests are welcome!, (*10)

  • Sergii

The Versions

09/03 2018

dev-master

9999999-dev

Yii2 Documentaiton Viewer Module

  Sources   Download

MIT

The Requires

 

yii2 documentation module wiki