Skip to content

Commit

Permalink
Add new parameter to enable the secure asset
Browse files Browse the repository at this point in the history
  • Loading branch information
Alcindo authored and f2m2rd committed Apr 10, 2019
1 parent 8052837 commit 3753bae
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 98 deletions.
11 changes: 8 additions & 3 deletions src/Commands/ApiDocsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ApiDocsGenerator {
protected $router;

protected $prefix;
protected $secure;
protected $dotPrefix;
protected $storagePath;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -196,7 +198,6 @@ protected function generateHTMLCode($endpoints)
/*
* Head
*/

$this->updatePrefixAndSaveTemplate('includes', Config::get('apidocs.head_template_path'));

/*
Expand Down Expand Up @@ -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);

Expand Down
183 changes: 96 additions & 87 deletions src/Commands/ApiDocsGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
// );
// }

}
16 changes: 8 additions & 8 deletions src/templates/includes/head.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>API DOCS</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="{{ asset('/assets/docs/{prefix}/css/normalize.min.css') }}">
<link rel="stylesheet" href="{{ asset('/assets/docs/{prefix}/css/main.css') }}">
<link rel="stylesheet" href="{{ asset('/assets/docs/{prefix}/css/prettify.css') }}">
<link rel="stylesheet" href="{{ asset('/assets/docs/{prefix}/css/f2m2-grid.css') }}">
<link rel="stylesheet" href="{{ {secure}asset('/assets/docs/{prefix}/css/normalize.min.css') }}">
<link rel="stylesheet" href="{{ {secure}asset('/assets/docs/{prefix}/css/main.css') }}">
<link rel="stylesheet" href="{{ {secure}asset('/assets/docs/{prefix}/css/prettify.css') }}">
<link rel="stylesheet" href="{{ {secure}asset('/assets/docs/{prefix}/css/f2m2-grid.css') }}">

<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="//code.jquery.com/ui/1.10.2/jquery-ui.min.js"></script>
<script src="{{ asset('/assets/docs/{prefix}/js/prettify.js') }}"></script>
<script src="{{ asset('/assets/docs/{prefix}/js/waypoints.min.js') }}"></script>
<script src="{{ asset('/assets/docs/{prefix}/js/highlight.js') }}"></script>
<script src="{{ asset('/assets/docs/{prefix}/js/main.js') }}"></script>
<script src="{{ {secure}asset('/assets/docs/{prefix}/js/prettify.js') }}"></script>
<script src="{{ {secure}asset('/assets/docs/{prefix}/js/waypoints.min.js') }}"></script>
<script src="{{ {secure}asset('/assets/docs/{prefix}/js/highlight.js') }}"></script>
<script src="{{ {secure}asset('/assets/docs/{prefix}/js/main.js') }}"></script>

0 comments on commit 3753bae

Please sign in to comment.