Selaa lähdekoodia

Switch to pastel

shalvah 5 vuotta sitten
vanhempi
commit
6cc5127bce
4 muutettua tiedostoa jossa 39 lisäystä ja 53 poistoa
  1. 12 6
      composer.json
  2. 7 6
      config/apidoc.php
  3. 2 2
      resources/views/partials/frontmatter.blade.php
  4. 18 39
      src/Writing/Writer.php

+ 12 - 6
composer.json

@@ -1,5 +1,5 @@
 {
-    "name": "mpociot/laravel-apidoc-generator",
+    "name": "knuckleswtf/scribe",
     "license": "MIT",
     "description": "Generate beautiful API documentation from your Laravel application",
     "keywords": [
@@ -21,8 +21,8 @@
         "illuminate/console": "^5.7|^6.0|^7.0",
         "illuminate/routing": "^5.7|^6.0|^7.0",
         "illuminate/support": "^5.7|^6.0|^7.0",
+        "knuckleswtf/pastel": "^1.1",
         "league/flysystem": "^1.0",
-        "mpociot/documentarian": "^0.4.0",
         "mpociot/reflection-docblock": "^1.0.1",
         "nunomaduro/collision": "^3.0|^4.0",
         "ramsey/uuid": "^3.8|^4.0",
@@ -59,13 +59,19 @@
             "providers": [
                 "Mpociot\\ApiDoc\\ApiDocGeneratorServiceProvider"
             ]
-        },
-        "branch-alias": {
-            "dev-v4": "4.x-dev"
         }
     },
     "config": {
         "preferred-install": "dist",
         "sort-packages": true
-    }
+    },
+    "replace": {
+        "mpociot/laravel-apidoc-generator": "*"
+    },
+    "funding": [
+        {
+            "type": "patreon",
+            "url": "https://patreon.com/shalvah"
+        }
+    ]
 }

+ 7 - 6
config/apidoc.php

@@ -217,14 +217,15 @@ return [
     ],
 
     /*
-     * Custom logo path. The logo will be copied from this location
-     * during the generate process. Set this to false to use the default logo.
+     * Custom logo path. The will be used as the value of the src attribute for the <img> tag,
+     * so make sure it points to a public URL or path accessible from your web server.
+     * Set this to false to not use a logo.
      *
-     * Change to an absolute path to use your custom logo. For example:
-     * 'logo' => resource_path('views') . '/api/logo.png'
+     * For example, if your logo is in public/img:
+     * - 'logo' => 'img/logo.png' // for `laravel` type
+     * - 'logo' => '../img/logo.png' // for `static` type (output folder is public/docs)
      *
-     * If you want to use this, please be aware of the following rules:
-     * - the image size must be 230 x 52
+     * For best results the image width should be 230px.
      */
     'logo' => false,
 

+ 2 - 2
resources/views/partials/frontmatter.blade.php

@@ -7,7 +7,7 @@ language_tabs:
 
 includes:
 
-search: true
+logo: {{ $settings['logo'] ?? false }}
 
 toc_footers:
-- <a href='http://github.com/mpociot/documentarian'>Documentation Powered by Documentarian</a>
+- <a href='http://github.com/knuckleswtf/pastel'>Documentation powered by Pastel</a>

+ 18 - 39
src/Writing/Writer.php

@@ -5,8 +5,8 @@ namespace Mpociot\ApiDoc\Writing;
 use Illuminate\Console\Command;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Storage;
+use Knuckles\Pastel\Pastel;
 use Mpociot\ApiDoc\Tools\DocumentationConfig;
-use Mpociot\Documentarian\Documentarian;
 
 class Writer
 {
@@ -36,9 +36,9 @@ class Writer
     private $shouldGeneratePostmanCollection = true;
 
     /**
-     * @var Documentarian
+     * @var Pastel
      */
-    private $documentarian;
+    private $pastel;
 
     /**
      * @var bool
@@ -63,7 +63,7 @@ class Writer
         $this->forceIt = $forceIt;
         $this->output = $output;
         $this->shouldGeneratePostmanCollection = $this->config->get('postman.enabled', false);
-        $this->documentarian = new Documentarian();
+        $this->pastel = new Pastel();
         $this->isStatic = $this->config->get('type') === 'static';
         $this->sourceOutputPath = 'resources/docs';
         $this->outputPath = $this->isStatic ? 'public/docs' : 'resources/views/apidoc';
@@ -98,7 +98,10 @@ class Writer
             ->with('outputPath', 'docs')
             ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection);
 
-        $settings = ['languages' => $this->config->get('example_languages')];
+        $settings = [
+            'languages' => $this->config->get('example_languages'),
+            'logo' => $this->config->get('logo')
+        ];
         // Generate Markdown for each route
         $parsedRouteOutput = $this->generateMarkdownOutputForEachRoute($parsedRoutes, $settings);
 
@@ -146,11 +149,10 @@ class Writer
             ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection)
             ->with('parsedRoutes', $parsedRouteOutput);
 
-        $this->output->info('Writing index.md and source files to: ' . $this->sourceOutputPath);
+        $this->output->info('Writing index.md to: ' . $this->sourceOutputPath);
 
-        if (! is_dir($this->sourceOutputPath)) {
-            $documentarian = new Documentarian();
-            $documentarian->create($this->sourceOutputPath);
+        if (! is_dir($this->sourceOutputPath. '/source')) {
+            mkdir($this->sourceOutputPath . '/source', 0777, true);
         }
 
         // Write output file
@@ -169,7 +171,7 @@ class Writer
 
         file_put_contents($compareFile, $compareMarkdown);
 
-        $this->output->info('Wrote index.md and source files to: ' . $this->sourceOutputPath);
+        $this->output->info('Wrote index.md to: ' . $this->sourceOutputPath);
     }
 
     public function generateMarkdownOutputForEachRoute(Collection $parsedRoutes, array $settings): Collection
@@ -250,34 +252,13 @@ class Writer
         return $appendFileContents;
     }
 
-    protected function copyAssetsFromSourceFolderToPublicFolder(): void
+    protected function moveOutputFromPublicFolderToResourcesFolder(): void
     {
-        $publicPath = 'public/docs';
-        if (! is_dir($publicPath)) {
-            mkdir($publicPath, 0777, true);
-            mkdir("{$publicPath}/css");
-            mkdir("{$publicPath}/js");
-        }
-        copy("{$this->sourceOutputPath}/js/all.js", "{$publicPath}/js/all.js");
-        rcopy("{$this->sourceOutputPath}/images", "{$publicPath}/images");
-        rcopy("{$this->sourceOutputPath}/css", "{$publicPath}/css");
-
-        if ($logo = $this->config->get('logo')) {
-            copy($logo, "{$publicPath}/images/logo.png");
-        }
-    }
-
-    protected function moveOutputFromSourceFolderToTargetFolder(): void
-    {
-        if ($this->isStatic) {
-            // Move output (index.html, css/style.css and js/all.js) to public/docs
-            rename("{$this->sourceOutputPath}/index.html", "{$this->outputPath}/index.html");
-        } else {
             // Move output to resources/views
             if (! is_dir($this->outputPath)) {
                 mkdir($this->outputPath);
             }
-            rename("{$this->sourceOutputPath}/index.html", "$this->outputPath/index.blade.php");
+            rename("public/docs/index.html", "$this->outputPath/index.blade.php");
             $contents = file_get_contents("$this->outputPath/index.blade.php");
             //
             $contents = str_replace('href="css/style.css"', 'href="/docs/css/style.css"', $contents);
@@ -285,19 +266,17 @@ class Writer
             $contents = str_replace('src="images/', 'src="/docs/images/', $contents);
             $contents = preg_replace('#href="https?://.+?/docs/collection.json"#', 'href="{{ route("apidoc.json") }}"', $contents);
             file_put_contents("$this->outputPath/index.blade.php", $contents);
-        }
     }
 
     public function writeHtmlDocs(): void
     {
         $this->output->info('Generating API HTML code');
 
-        $this->documentarian->generate($this->sourceOutputPath);
+        $this->pastel->generate($this->sourceOutputPath. '/source/index.md', 'public/docs');
 
-        // Move assets to public folder
-        $this->copyAssetsFromSourceFolderToPublicFolder();
-
-        $this->moveOutputFromSourceFolderToTargetFolder();
+        if (! $this->isStatic) {
+            $this->moveOutputFromPublicFolderToResourcesFolder();
+        }
 
         $this->output->info("Wrote HTML documentation to: {$this->outputPath}");
     }