Browse Source

Allow frontmatter modifications

Marcel Pociot 8 years ago
parent
commit
576ded0dab

+ 6 - 0
src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php

@@ -94,6 +94,7 @@ class GenerateDocumentation extends Command
             ->with('outputPath', $this->option('output'))
             ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'));
 
+        $frontmatter = view('apidoc::partials.frontmatter');
         /**
          * In case the target file already exists, we should check if the documentation was modified
          * and skip the modified parts of the routes.
@@ -104,11 +105,16 @@ class GenerateDocumentation extends Command
             if (preg_match("/<!-- START_INFO -->(.*)<!-- END_INFO -->/is", $generatedDocumentation, $generatedInfoText)) {
                 $infoText = trim($generatedInfoText[1],"\n");
             }
+
+            if (preg_match("/---(.*)---\\s<!-- START_INFO -->/is", $generatedDocumentation, $generatedFrontmatter)) {
+                $frontmatter = trim($generatedFrontmatter[1],"\n");
+            }
         }
 
         $documentarian = new Documentarian();
 
         $markdown = view('apidoc::documentarian')
+            ->with('frontmatter', $frontmatter)
             ->with('infoText', $infoText)
             ->with('outputPath', $this->option('output'))
             ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'))

+ 1 - 12
src/resources/views/documentarian.blade.php

@@ -1,16 +1,5 @@
 ---
-title: API Reference
-
-language_tabs:
-- bash
-- javascript
-
-includes:
-
-search: true
-
-toc_footers:
-- <a href='http://github.com/mpociot/documentarian'>Documentation Powered by Documentarian</a>
+{!! $frontmatter !!}
 ---
 <!-- START_INFO -->
 {!! $infoText !!}

+ 12 - 0
src/resources/views/partials/frontmatter.blade.php

@@ -0,0 +1,12 @@
+title: API Reference
+
+language_tabs:
+- bash
+- javascript
+
+includes:
+
+search: true
+
+toc_footers:
+- <a href='http://github.com/mpociot/documentarian'>Documentation Powered by Documentarian</a>

+ 1 - 0
tests/Fixtures/index.md

@@ -17,6 +17,7 @@ toc_footers:
 
 Welcome to the generated API reference.
 [Get Postman Collection](public/docs/collection.json)
+
 <!-- END_INFO -->
 
 #general

+ 5 - 0
tests/GenerateDocumentationTest.php

@@ -27,6 +27,11 @@ class GenerateDocumentationTest extends TestCase
         $this->generator = new LaravelGenerator();
     }
 
+    public function tearDown()
+    {
+        exec('rm -rf ' . __DIR__.'/../public/docs');
+    }
+
     /**
      * @param \Illuminate\Foundation\Application $app
      *