Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Generate new version v3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
surgiie committed Dec 27, 2022
1 parent 4509e62 commit 7a44701
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
24 changes: 17 additions & 7 deletions app/Commands/RenderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.}';
Expand Down Expand Up @@ -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],
];
Expand Down Expand Up @@ -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', []);

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions tests/Feature/BladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return "v3.5.0";
<?php return "v3.6.0";

0 comments on commit 7a44701

Please sign in to comment.