From 7a44701f21141101552071e1a5bf819199a44a4f Mon Sep 17 00:00:00 2001 From: Sergio Compean Date: Tue, 27 Dec 2022 02:57:00 -0500 Subject: [PATCH] Generate new version v3.6.0 --- app/Commands/RenderCommand.php | 24 +++++++++++++++++------- composer.json | 5 +++-- tests/Feature/BladeTest.php | 24 ++++++++++++++++++++++++ version.php | 2 +- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/app/Commands/RenderCommand.php b/app/Commands/RenderCommand.php index 88e396c..b247f63 100644 --- a/app/Commands/RenderCommand.php +++ b/app/Commands/RenderCommand.php @@ -2,20 +2,21 @@ namespace App\Commands; +use SplFileInfo; use Dotenv\Dotenv; -use Illuminate\Filesystem\Filesystem; +use Surgiie\Blade\Blade; use Illuminate\Support\Arr; use Illuminate\Support\Str; use InvalidArgumentException; -use SplFileInfo; -use Surgiie\Blade\Blade; -use Surgiie\Console\Command as ConsoleCommand; +use Symfony\Component\Yaml\Yaml; +use Symfony\Component\Finder\Finder; +use Illuminate\Filesystem\Filesystem; use Surgiie\Console\Concerns\LoadsEnvFiles; use Surgiie\Console\Concerns\LoadsJsonFiles; -use Surgiie\Console\Concerns\WithTransformers; use Surgiie\Console\Concerns\WithValidation; +use Surgiie\Console\Command as ConsoleCommand; +use Surgiie\Console\Concerns\WithTransformers; use Surgiie\Console\Rules\FileOrDirectoryExists; -use Symfony\Component\Finder\Finder; class RenderCommand extends ConsoleCommand { @@ -29,7 +30,8 @@ class RenderCommand extends ConsoleCommand protected $signature = 'render {path : The file or directory path to compile and save file(s) for. } {--save-to= : The custom file or directory path to save the rendered file(s) to. } - {--from-json=* : A json file to load variable data from. } + {--from-yaml=* : A yaml file path to load variable data from. } + {--from-json=* : A json file path to load variable data from. } {--from-env=* : A .env file to load variable data from. } {--dry-run : Dump out compiled file contents only. } {--force : Force render or overwrite files.}'; @@ -60,6 +62,7 @@ protected function transformers() return [ 'path' => ['trim', 'normalize_path', 'rtrim::value:,'.DIRECTORY_SEPARATOR], 'from-json' => [fn ($v) => Arr::wrap($v)], + 'from-yaml' => [fn ($v) => Arr::wrap($v)], 'from-env' => [fn ($v) => Arr::wrap($v)], 'save-to' => ['trim', 'normalize_path', 'rtrim::value:,'.DIRECTORY_SEPARATOR], ]; @@ -319,6 +322,13 @@ protected function normalizeVariableNames(array $vars = []) protected function gatherVariables() { $variables = []; + // laod from yaml files. + $yamlFiles = $this->data->get('from-yaml', []); + + foreach ($yamlFiles as $file) { + $vars = Yaml::parseFile($file); + $variables = array_merge($variables, $this->normalizeVariableNames($vars)); + } // laod from json files. $jsonFiles = $this->data->get('from-json', []); diff --git a/composer.json b/composer.json index ff93095..90080d6 100755 --- a/composer.json +++ b/composer.json @@ -6,10 +6,11 @@ "require": { "php": "^8.0", "guzzlehttp/guzzle": "^7.4", - "laravel-zero/framework": "^9.2", "illuminate/http": "^9.0", "intonate/tinker-zero": "^1.2", - "surgiie/console": "~1.0.0" + "laravel-zero/framework": "^9.2", + "surgiie/console": "~1.0.0", + "symfony/yaml": "^6.2" }, "require-dev": { "laravel/pint": "^1.2", diff --git a/tests/Feature/BladeTest.php b/tests/Feature/BladeTest.php index 25811be..07c0ead 100755 --- a/tests/Feature/BladeTest.php +++ b/tests/Feature/BladeTest.php @@ -207,6 +207,30 @@ EOL); }); +it('can load variable data from yaml files', function () { + $path = blade_cli_test_path('example.txt'); + + put_blade_cli_test_file('example.txt', <<<'EOL' + name: {{ $name }} + last_name: {{ $lastName }} + EOL); + + put_blade_cli_test_file('vars.yaml', <<<'EOL' + "name": "Doug" + "last_name": "Thompson" + EOL); + + $this->artisan('render', [ + 'path' => $path, + '--from-yaml' => blade_cli_test_path('vars.yaml'), + ])->assertExitCode(0); + + expect(file_get_contents(blade_cli_test_path('example.rendered.txt')))->toBe(<<<'EOL' + name: Doug + last_name: Thompson + EOL); +}); + it('can load variable data from env files', function () { $path = blade_cli_test_path('example.yaml'); diff --git a/version.php b/version.php index 78a17ff..898f632 100644 --- a/version.php +++ b/version.php @@ -1 +1 @@ -