Skip to content

Commit

Permalink
update name space, struct
Browse files Browse the repository at this point in the history
  • Loading branch information
oxycoder committed Apr 29, 2018
1 parent e7239fc commit 95e3f4b
Show file tree
Hide file tree
Showing 79 changed files with 9,310 additions and 59 deletions.
23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
"name": "mpociot/laravel-apidoc-generator",
"name": "oxycoder/laravel-apidoc-generator",
"license": "MIT",
"description": "Generate beautiful API documentation from your Laravel application",
"keywords": [
"API",
"Documentation",
"Laravel"
],
"homepage": "http://github.com/mpociot/laravel-apidoc-generator",
"homepage": "http://github.com/oxycoder/laravel-apidoc-generator",
"authors": [
{
"name": "Marcel Pociot",
"name": "Tung",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.5.0",
"fzaninotto/faker": "~1.0",
"laravel/framework": "~5.4",
"mpociot/documentarian": "^0.2.0",
"mpociot/reflection-docblock": "^1.0",
"ramsey/uuid": "^3.0"
"ramsey/uuid": "^3.0",
"mnapoli/front-yaml": "^1.5",
"windwalker/renderer": "3.*",
"mnapoli/silly": "~1.0",
"illuminate/view": "5.*"
},
"require-dev": {
"orchestra/testbench": "~3.0",
Expand All @@ -29,19 +31,22 @@
"mockery/mockery": "^0.9.5"
},
"autoload": {
"files": [
"src/Oxycoder/ApiDoc/Documentarian/helpers.php"
],
"psr-0": {
"Mpociot\\ApiDoc": "src/"
"Oxycoder\\ApiDoc": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Mpociot\\ApiDoc\\Tests\\": "tests/"
"Oxycoder\\ApiDoc\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Mpociot\\ApiDoc\\ApiDocGeneratorServiceProvider"
"Oxycoder\\ApiDoc\\ApiDocGeneratorServiceProvider"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Mpociot\ApiDoc;
namespace Oxycoder\ApiDoc;

use Illuminate\Support\ServiceProvider;
use Mpociot\ApiDoc\Commands\UpdateDocumentation;
use Mpociot\ApiDoc\Commands\GenerateDocumentation;
use Oxycoder\ApiDoc\Commands\UpdateDocumentation;
use Oxycoder\ApiDoc\Commands\GenerateDocumentation;

class ApiDocGeneratorServiceProvider extends ServiceProvider
{
Expand All @@ -21,6 +21,7 @@ public function boot()
$this->publishes([
__DIR__.'/../../resources/lang' => $this->resource_path('lang/vendor/apidoc'),
__DIR__.'/../../resources/views' => $this->resource_path('views/vendor/apidoc'),
__DIR__.'/../../resources/assets' => $this->resource_path('views/vendor/assets'),
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

namespace Mpociot\ApiDoc\Commands;
namespace Oxycoder\ApiDoc\Commands;

use ReflectionClass;
use Illuminate\Console\Command;
use Mpociot\Reflection\DocBlock;
use Oxycoder\Reflection\DocBlock;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Route;
use Mpociot\Documentarian\Documentarian;
use Mpociot\ApiDoc\Postman\CollectionWriter;
use Mpociot\ApiDoc\Generators\DingoGenerator;
use Mpociot\ApiDoc\Generators\LaravelGenerator;
use Mpociot\ApiDoc\Generators\AbstractGenerator;
use Oxycoder\Documentarian\Documentarian;
use Oxycoder\ApiDoc\Postman\CollectionWriter;
use Oxycoder\ApiDoc\Generators\DingoGenerator;
use Oxycoder\ApiDoc\Generators\LaravelGenerator;
use Oxycoder\ApiDoc\Generators\AbstractGenerator;

class GenerateDocumentation extends Command
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Mpociot\ApiDoc\Commands;
namespace Oxycoder\ApiDoc\Commands;

use Illuminate\Console\Command;
use Mpociot\Documentarian\Documentarian;
use Oxycoder\Documentarian\Documentarian;

class UpdateDocumentation extends Command
{
Expand Down
104 changes: 104 additions & 0 deletions src/Oxycoder/ApiDoc/Documentarian/Documentarian.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Oxycoder\Documentarian;

use Mni\FrontYAML\Parser;
use Windwalker\Renderer\BladeRenderer;

/**
* Class Documentarian
* @package Mpociot\Documentarian
*/
class Documentarian
{

/**
* Returns a config value
*
* @param string $key
* @return mixed
*/
public function config($folder, $key = null)
{
$config = include($folder . '/source/config.php');

return is_null($key) ? $config : array_get($config, $key);
}

/**
* Create a new API documentation folder and copy all needed files/stubs
*
* @param $folder
*/
public function create($folder)
{
$folder = $folder . '/source';
if (!is_dir($folder)) {
mkdir($folder, 0777, true);
mkdir($folder . '/../css');
mkdir($folder . '/../js');
mkdir($folder . '/includes');
mkdir($folder . '/assets');
}

// copy stub files
copy(__DIR__ . '/../../resources/assets/stubs/index.md', $folder . '/index.md');
copy(__DIR__ . '/../../resources/assets/stubs/gitignore.stub', $folder . '/.gitignore');
copy(__DIR__ . '/../../resources/assets/stubs/includes/_errors.md', $folder . '/includes/_errors.md');
copy(__DIR__ . '/../../resources/assets/stubs/package.json', $folder . '/package.json');
copy(__DIR__ . '/../../resources/assets/stubs/gulpfile.js', $folder . '/gulpfile.js');
copy(__DIR__ . '/../../resources/assets/stubs/config.php', $folder . '/config.php');
copy(__DIR__ . '/../../resources/assets/stubs/js/all.js', $folder . '/../js/all.js');
copy(__DIR__ . '/../../resources/assets/stubs/css/style.css', $folder . '/../css/style.css');

// copy resources
rcopy(__DIR__ . '/../../resources/assets/images/', $folder . '/assets/images');
rcopy(__DIR__ . '/../../resources/assets/js/', $folder . '/assets/js');
rcopy(__DIR__ . '/../../resources/assets/stylus/', $folder . '/assets/stylus');
}

/**
* Generate the API documentation using the markdown and include files
*
* @param $folder
* @return false|null
*/
public function generate($folder)
{
$source_dir = $folder . '/source';

if (!is_dir($source_dir)) {
return false;
}

$parser = new Parser();

$document = $parser->parse(file_get_contents($source_dir . '/index.md'));

$frontmatter = $document->getYAML();
$html = $document->getContent();

$renderer = new BladeRenderer([__DIR__ . '/../../resources/views'], ['cache_path' => $source_dir . '/_tmp']);

// Parse and include optional include markdown files
if (isset($frontmatter['includes'])) {
foreach ($frontmatter['includes'] as $include) {
if (file_exists($include_file = $source_dir . '/includes/_' . $include . '.md')) {
$document = $parser->parse(file_get_contents($include_file));
$html .= $document->getContent();
}
}
}

$output = $renderer->render('index', [
'page' => $frontmatter,
'content' => $html
]);

file_put_contents($folder . '/index.html', $output);

// Copy assets
rcopy($source_dir . '/assets/images/', $folder . '/images');
rcopy($source_dir . '/assets/stylus/fonts/', $folder . '/css/fonts');
}
}
66 changes: 66 additions & 0 deletions src/Oxycoder/ApiDoc/Documentarian/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Output the given text to the console.
*
* @param string $output
* @return void
*/
if (!function_exists('info')) {
function info($output)
{
output('<info>' . $output . '</info>');
}
}

/**
* Output the given text to the console.
*
* @param string $output
* @return void
*/
if (!function_exists('output')) {
function output($output)
{
if (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] == 'testing') {
return;
}
(new Symfony\Component\Console\Output\ConsoleOutput)->writeln($output);
}
}

/**
* Recursively copy files from one directory to another
*
* @param String $src - Source of files being moved
* @param String $dest - Destination of files being moved
* @return bool
*/

if (!function_exists('rcopy')) {
function rcopy($src, $dest)
{

// If source is not a directory stop processing
if (!is_dir($src)) {
return false;
}

// If the destination directory does not exist create it
if (!is_dir($dest)) {
if (!mkdir($dest)) {
// If the destination directory could not be created stop processing
return false;
}
}

// Open the source directory to read in files
$i = new DirectoryIterator($src);
foreach ($i as $f) {
if ($f->isFile()) {
copy($f->getRealPath(), "$dest/" . $f->getFilename());
} elseif (!$f->isDot() && $f->isDir()) {
rcopy($f->getRealPath(), "$dest/$f");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace Mpociot\ApiDoc\Generators;
namespace Oxycoder\ApiDoc\Generators;

use Faker\Factory;
use ReflectionClass;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Mpociot\Reflection\DocBlock;
use Mpociot\Reflection\DocBlock\Tag;
use Oxycoder\Reflection\DocBlock;
use Oxycoder\Reflection\DocBlock\Tag;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Mpociot\ApiDoc\Parsers\RuleDescriptionParser as Description;
use Oxycoder\ApiDoc\Parsers\RuleDescriptionParser as Description;

abstract class AbstractGenerator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Mpociot\ApiDoc\Generators;
namespace Oxycoder\ApiDoc\Generators;

use Exception;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Mpociot\ApiDoc\Generators;
namespace Oxycoder\ApiDoc\Generators;

use ReflectionClass;
use League\Fractal\Manager;
use Illuminate\Routing\Route;
use League\Fractal\Resource\Item;
use Illuminate\Support\Facades\App;
use Mpociot\Reflection\DocBlock\Tag;
use Oxycoder\Reflection\DocBlock\Tag;
use Illuminate\Support\Facades\Request;
use League\Fractal\Resource\Collection;
use Illuminate\Foundation\Http\FormRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Mpociot\ApiDoc\Parsers;
namespace Oxycoder\ApiDoc\Parsers;

class RuleDescriptionParser
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Mpociot\ApiDoc\Postman;
namespace Oxycoder\ApiDoc\Postman;

use Ramsey\Uuid\Uuid;
use Illuminate\Support\Collection;
Expand Down
Loading

0 comments on commit 95e3f4b

Please sign in to comment.