瀏覽代碼

Refactor themes and examples

shalvah 4 年之前
父節點
當前提交
c353248f5d
共有 4 個文件被更改,包括 44 次插入7 次删除
  1. 0 1
      resources/js/highlight.pack.js
  2. 8 0
      src/ScribeServiceProvider.php
  3. 22 1
      src/Tools/WritingUtils.php
  4. 14 5
      src/Writing/HtmlWriter.php

File diff suppressed because it is too large
+ 0 - 1
resources/js/highlight.pack.js


+ 8 - 0
src/ScribeServiceProvider.php

@@ -34,6 +34,14 @@ class ScribeServiceProvider extends ServiceProvider
             __DIR__ . '/../resources/views' => $this->app->basePath('resources/views/vendor/scribe'),
         ], 'scribe-views');
 
+        $this->publishes([
+            __DIR__ . '/../resources/views/partials/example-requests' => $this->app->basePath('resources/views/vendor/scribe/partials/example-requests'),
+        ], 'scribe-examples');
+
+        $this->publishes([
+            __DIR__ . '/../resources/views/themes' => $this->app->basePath('resources/views/vendor/scribe/themes'),
+        ], 'scribe-themes');
+
         $this->publishes([
             __DIR__ . '/../config/scribe.php' => $this->app->configPath('scribe.php'),
         ], 'scribe-config');

+ 22 - 1
src/Tools/WritingUtils.php

@@ -7,7 +7,7 @@ use Symfony\Component\VarExporter\VarExporter;
 class WritingUtils
 {
 
-    public static $httpMethodToCssColour = [
+    public static array $httpMethodToCssColour = [
         'GET' => 'green',
         'HEAD' => 'darkgreen',
         'POST' => 'black',
@@ -66,6 +66,26 @@ class WritingUtils
         return rtrim($qs, '&');
     }
 
+    /**
+     * Print key-value query params as a hash { "key1": "value1", "key2": "value2" }
+     * Supports custom delimiters (eg "=>", default: ":"),
+     *   custom braces (eg "[]", default: "{}"),
+     *   custom quotes (eg ', default: "),
+     *   custom indentation, line endings etc.
+     * Expands/simplifies arrays {key: [1, 2,]} becomes {"key[]": "1"}
+     * Expands hashes {key: {a: 1, b: 2}} becomes {"key[a]": "1", "key[b]": "2"}
+     *
+     * @param array $cleanQueryParams
+     * @param string $quote
+     * @param string $delimiter
+     * @param int $spacesIndentation
+     * @param string $braces
+     * @param int $closingBraceIndentation
+     * @param string $startLinesWith
+     * @param string $endLinesWith
+     *
+     * @return string
+     */
     public static function printQueryParamsAsKeyValue(
         array $cleanQueryParams,
         string $quote = '"',
@@ -81,6 +101,7 @@ class WritingUtils
         foreach ($cleanQueryParams as $parameter => $value) {
             if (!is_array($value)) {
                 $output .= str_repeat(" ", $spacesIndentation);
+                // Example: -----"param_name": "value"----
                 $output .= "$startLinesWith$quote$parameter$quote$delimiter $quote$value$quote$endLinesWith\n";
             } else {
                 if (count($value) == 0) {

+ 14 - 5
src/Writing/HtmlWriter.php

@@ -55,13 +55,22 @@ class HtmlWriter
         if (!is_dir($destinationFolder . "/js")) {
             mkdir($destinationFolder."/js", 0777, true);
         }
-        Utils::copyDirectory($assetsFolder . '/images/', $destinationFolder . '/images');
-        Utils::copyDirectory($assetsFolder . '/css/', $destinationFolder . '/css');
-        copy($assetsFolder . "/js/theme-$theme.js", $destinationFolder . WritingUtils::getVersionedAsset("/js/theme-$theme.js"));
-        copy($assetsFolder . "/js/highlight.pack.js", $destinationFolder . "/js/highlight.pack.js");
+        Utils::copyDirectory("{$assetsFolder}/images/", "{$destinationFolder}/images");
+
+        $assets = [
+            "{$assetsFolder}/css/theme-$theme.style.css" => "{$destinationFolder}/css/theme-$theme.style.css",
+            "{$assetsFolder}/css/theme-$theme.print.css" => "{$destinationFolder}/css/theme-$theme.print.css",
+            "{$assetsFolder}/js/theme-$theme.js" => $destinationFolder . WritingUtils::getVersionedAsset("/js/theme-$theme.js"),
+        ];
+
+        foreach ($assets as $path => $destination) {
+            if (file_exists($path)) {
+                copy($path, $destination);
+            }
+        }
 
         if ($this->config->get('try_it_out.enabled', true)) {
-            copy($assetsFolder . '/js/tryitout.js', $destinationFolder . WritingUtils::getVersionedAsset('/js/tryitout.js'));
+            copy("{$assetsFolder}/js/tryitout.js", $destinationFolder . WritingUtils::getVersionedAsset('/js/tryitout.js'));
         }
     }
 

Some files were not shown because too many files changed in this diff