From 3753baef68aa0162cec2b819ac38ea36193a4bf6 Mon Sep 17 00:00:00 2001 From: Alcindo Date: Wed, 10 Apr 2019 15:58:34 +0200 Subject: [PATCH] Add new parameter to enable the secure asset --- src/Commands/ApiDocsGenerator.php | 11 +- src/Commands/ApiDocsGeneratorCommand.php | 183 ++++++++++++----------- src/templates/includes/head.blade.php | 16 +- 3 files changed, 112 insertions(+), 98 deletions(-) diff --git a/src/Commands/ApiDocsGenerator.php b/src/Commands/ApiDocsGenerator.php index d1df325..b795e11 100644 --- a/src/Commands/ApiDocsGenerator.php +++ b/src/Commands/ApiDocsGenerator.php @@ -21,6 +21,7 @@ class ApiDocsGenerator { protected $router; protected $prefix; + protected $secure; protected $dotPrefix; protected $storagePath; @@ -54,9 +55,10 @@ public function __construct(Router $router) * @return void */ - public function make($prefix) + public function make($prefix, $secure) { $this->prefix = $prefix; + $this->secure = $secure; $this->dotPrefix = str_replace('/', '.', $this->prefix); $this->routes = $this->getRoutes(); @@ -196,7 +198,6 @@ protected function generateHTMLCode($endpoints) /* * Head */ - $this->updatePrefixAndSaveTemplate('includes', Config::get('apidocs.head_template_path')); /* @@ -238,7 +239,11 @@ protected function updatePrefixAndSaveTemplate($type, $filepath) { $content = File::get($filepath); - + if ($this->secure) { + $content = str_replace('{secure}', 'secure_', $content); + }else{ + $content = str_replace('{secure}', '', $content); + } $content = str_replace('{prefix}', $this->dotPrefix, $content); $newPath = $this->viewPathForType($type) . basename($filepath); diff --git a/src/Commands/ApiDocsGeneratorCommand.php b/src/Commands/ApiDocsGeneratorCommand.php index bf18b45..8a7adfb 100644 --- a/src/Commands/ApiDocsGeneratorCommand.php +++ b/src/Commands/ApiDocsGeneratorCommand.php @@ -7,102 +7,111 @@ class ApiDocsGeneratorCommand extends Command { - /** - * The console command name. - * - * @var string - */ - protected $name = 'apidocs:generate'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Generates API Documentation.'; - - /** - * The console command description. - * - * @var DocsGenerator - */ - - protected $generator; - - /** - * Create a new command instance. - * - * @return void - */ - public function __construct(ApiDocsGenerator $generator) - { - parent::__construct(); - - $this->generator = $generator; - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() - { - if (!is_null($this->argument('prefix'))) { - // Command line argument takes 1st precedence. - $prefix = $this->argument('prefix'); - } - else { - // Check for an environment variable, so you don't have to type - // the prefix in each time. Otherwise, ask them. - if (!empty(getenv('APIDOCS_PREFIX'))) { - $prefix = getenv('APIDOCS_PREFIX'); - } else { - $prefix = $this->ask('What is the API Prefix? i.e. "api/v1"'); - } - } - $this->info('Generating ' . $prefix . ' API Documentation.'); - - // generate the docs - $this->generator->make($prefix); - - $dot_prefix = str_replace('/', '.', $prefix); + /** + * The console command name. + * + * @var string + */ + protected $name = 'apidocs:generate'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Generates API Documentation.'; + + /** + * The console command description. + * + * @var DocsGenerator + */ + + protected $generator; + + /** + * Create a new command instance. + * + * @return void + */ + public function __construct(ApiDocsGenerator $generator) + { + parent::__construct(); + + $this->generator = $generator; + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + if (!is_null($this->argument('prefix'))) { + // Command line argument takes 1st precedence. + $prefix = $this->argument('prefix'); + } + else { + // Check for an environment variable, so you don't have to type + // the prefix in each time. Otherwise, ask them. + if (!empty(getenv('APIDOCS_PREFIX'))) { + $prefix = getenv('APIDOCS_PREFIX'); + } else { + $prefix = $this->ask('What is the API Prefix? i.e. "api/v1"'); + } + } + $this->info('Generating ' . $prefix . ' API Documentation.'); + + if (!is_null($this->argument('secure'))) { + // Command line argument takes 1st precedence. + $secure = true; + }else{ + $secure = false; + } + + + // generate the docs + $this->generator->make($prefix, $secure); + + $dot_prefix = str_replace('/', '.', $prefix); $this->info('API Docs have been generated!'); $this->info(''); $this->info('Add the following Route to "app/routes.php" > '); - // All done! + // All done! $this->info(sprintf( "\n %s" . PHP_EOL, "Route::get('docs', function(){ - return View::make('docs." . $dot_prefix . ".index'); + return View::make('docs." . $dot_prefix . ".index'); });" )); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return array( - array('prefix', InputArgument::OPTIONAL, 'Api Prefix (i.e. "api/v1"'), - ); - } - - /** - * Get the console command options. - * - * @return array - */ - // protected function getOptions() - // { - // return array( - // array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null), - // ); - // } + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return array( + array('prefix', InputArgument::OPTIONAL, 'Api Prefix (i.e. "api/v1"'), + array('secure', InputArgument::OPTIONAL, 'Enable the secure asset'), + ); + } + + /** + * Get the console command options. + * + * @return array + */ + // protected function getOptions() + // { + // return array( + // array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null), + // ); + // } } diff --git a/src/templates/includes/head.blade.php b/src/templates/includes/head.blade.php index a782f46..b66e99a 100644 --- a/src/templates/includes/head.blade.php +++ b/src/templates/includes/head.blade.php @@ -2,15 +2,15 @@ API DOCS - - - - + + + + - - - - + + + +