mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 15:37:53 +00:00
Compare commits
No commits in common. "770b511290a4199c571334f85f07eae75c7cea2f" and "6d7968a7b0465591bc504cb59adcaff69e98b2f0" have entirely different histories.
770b511290
...
6d7968a7b0
7 changed files with 23 additions and 101 deletions
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Liquid\Filters;
|
|
||||||
|
|
||||||
class StandardFilters extends \Keepsuit\Liquid\Filters\StandardFilters
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Converts any URL-unsafe characters in a string to the
|
|
||||||
* [percent-encoded](https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding) equivalent.
|
|
||||||
*/
|
|
||||||
public function urlEncode(string|int|float|array|null $input): string
|
|
||||||
{
|
|
||||||
|
|
||||||
if (is_array($input)) {
|
|
||||||
$input = json_encode($input);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::urlEncode($input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -7,7 +7,6 @@ use App\Liquid\Filters\Data;
|
||||||
use App\Liquid\Filters\Date;
|
use App\Liquid\Filters\Date;
|
||||||
use App\Liquid\Filters\Localization;
|
use App\Liquid\Filters\Localization;
|
||||||
use App\Liquid\Filters\Numbers;
|
use App\Liquid\Filters\Numbers;
|
||||||
use App\Liquid\Filters\StandardFilters;
|
|
||||||
use App\Liquid\Filters\StringMarkup;
|
use App\Liquid\Filters\StringMarkup;
|
||||||
use App\Liquid\Filters\Uniqueness;
|
use App\Liquid\Filters\Uniqueness;
|
||||||
use App\Liquid\Tags\TemplateTag;
|
use App\Liquid\Tags\TemplateTag;
|
||||||
|
|
@ -19,7 +18,6 @@ use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Keepsuit\LaravelLiquid\LaravelLiquidExtension;
|
|
||||||
use Keepsuit\Liquid\Exceptions\LiquidException;
|
use Keepsuit\Liquid\Exceptions\LiquidException;
|
||||||
use Keepsuit\Liquid\Extensions\StandardExtension;
|
use Keepsuit\Liquid\Extensions\StandardExtension;
|
||||||
|
|
||||||
|
|
@ -266,7 +264,6 @@ class Plugin extends Model
|
||||||
|
|
||||||
// Use the Liquid template engine to resolve variables
|
// Use the Liquid template engine to resolve variables
|
||||||
$environment = App::make('liquid.environment');
|
$environment = App::make('liquid.environment');
|
||||||
$environment->filterRegistry->register(StandardFilters::class);
|
|
||||||
$liquidTemplate = $environment->parseString($template);
|
$liquidTemplate = $environment->parseString($template);
|
||||||
$context = $environment->newRenderContext(data: $variables);
|
$context = $environment->newRenderContext(data: $variables);
|
||||||
|
|
||||||
|
|
@ -288,7 +285,7 @@ class Plugin extends Model
|
||||||
$inlineFileSystem = new InlineTemplatesFileSystem();
|
$inlineFileSystem = new InlineTemplatesFileSystem();
|
||||||
$environment = new \Keepsuit\Liquid\Environment(
|
$environment = new \Keepsuit\Liquid\Environment(
|
||||||
fileSystem: $inlineFileSystem,
|
fileSystem: $inlineFileSystem,
|
||||||
extensions: [new StandardExtension(), new LaravelLiquidExtension()]
|
extensions: [new StandardExtension()]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Register all custom filters
|
// Register all custom filters
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use App\Services\PluginImportService;
|
use App\Services\PluginImportService;
|
||||||
use Livewire\Volt\Component;
|
use Livewire\Volt\Component;
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
@ -27,40 +26,21 @@ new class extends Component {
|
||||||
$catalogContent = $response->body();
|
$catalogContent = $response->body();
|
||||||
$catalog = Yaml::parse($catalogContent);
|
$catalog = Yaml::parse($catalogContent);
|
||||||
|
|
||||||
$currentVersion = config('app.version');
|
return collect($catalog)->map(function ($plugin, $key) {
|
||||||
|
|
||||||
return collect($catalog)
|
|
||||||
->filter(function ($plugin) use ($currentVersion) {
|
|
||||||
// Check if Laravel compatibility is true
|
|
||||||
if (!Arr::get($plugin, 'byos.byos_laravel.compatibility', false)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check minimum version if specified
|
|
||||||
$minVersion = Arr::get($plugin, 'byos.byos_laravel.min_version');
|
|
||||||
if ($minVersion && $currentVersion && version_compare($currentVersion, $minVersion, '<')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
->map(function ($plugin, $key) {
|
|
||||||
return [
|
return [
|
||||||
'id' => $key,
|
'id' => $key,
|
||||||
'name' => Arr::get($plugin, 'name', 'Unknown Plugin'),
|
'name' => $plugin['name'] ?? 'Unknown Plugin',
|
||||||
'description' => Arr::get($plugin, 'author_bio.description', ''),
|
'description' => $plugin['author_bio']['description'] ?? '',
|
||||||
'author' => Arr::get($plugin, 'author.name', 'Unknown Author'),
|
'author' => $plugin['author']['name'] ?? 'Unknown Author',
|
||||||
'github' => Arr::get($plugin, 'author.github'),
|
'github' => $plugin['author']['github'] ?? null,
|
||||||
'license' => Arr::get($plugin, 'license'),
|
'license' => $plugin['license'] ?? null,
|
||||||
'zip_url' => Arr::get($plugin, 'trmnlp.zip_url'),
|
'zip_url' => $plugin['trmnlp']['zip_url'] ?? null,
|
||||||
'repo_url' => Arr::get($plugin, 'trmnlp.repo'),
|
'repo_url' => $plugin['trmnlp']['repo'] ?? null,
|
||||||
'logo_url' => Arr::get($plugin, 'logo_url'),
|
'logo_url' => $plugin['logo_url'] ?? null,
|
||||||
'screenshot_url' => Arr::get($plugin, 'screenshot_url'),
|
'screenshot_url' => $plugin['screenshot_url'] ?? null,
|
||||||
'learn_more_url' => Arr::get($plugin, 'author_bio.learn_more_url'),
|
'learn_more_url' => $plugin['author_bio']['learn_more_url'] ?? null,
|
||||||
];
|
];
|
||||||
})
|
})->toArray();
|
||||||
->sortBy('name')
|
|
||||||
->toArray();
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error('Failed to load catalog from URL: ' . $e->getMessage());
|
Log::error('Failed to load catalog from URL: ' . $e->getMessage());
|
||||||
return [];
|
return [];
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,10 @@ new class extends Component {
|
||||||
|
|
||||||
public function refreshPlugins(): void
|
public function refreshPlugins(): void
|
||||||
{
|
{
|
||||||
$userPlugins = auth()->user()?->plugins?->makeHidden(['render_markup', 'data_payload'])->toArray();
|
$userPlugins = auth()->user()?->plugins?->map(function ($plugin) {
|
||||||
|
return $plugin->toArray();
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
$this->plugins = array_merge($this->native_plugins, $userPlugins ?? []);
|
$this->plugins = array_merge($this->native_plugins, $userPlugins ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ new class extends Component {
|
||||||
$this->addError('polling_url', 'The polling URL must be a valid URL after resolving configuration variables.');
|
$this->addError('polling_url', 'The polling URL must be a valid URL after resolving configuration variables.');
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->addError('polling_url', 'Error resolving Liquid variables: ' . $e->getMessage() . $e->getPrevious()?->getMessage());
|
$this->addError('polling_url', 'Error resolving Liquid variables: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +148,7 @@ new class extends Component {
|
||||||
$this->data_payload_updated_at = $this->plugin->data_payload_updated_at;
|
$this->data_payload_updated_at = $this->plugin->data_payload_updated_at;
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->dispatch('data-update-error', message: $e->getMessage() . $e->getPrevious()?->getMessage());
|
$this->dispatch('data-update-error', message: $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -690,10 +690,7 @@ HTML;
|
||||||
<flux:checkbox label="{{ $label }}" value="{{ $value }}"/>
|
<flux:checkbox label="{{ $label }}" value="{{ $value }}"/>
|
||||||
@endforeach
|
@endforeach
|
||||||
@else
|
@else
|
||||||
@php
|
<flux:checkbox label="{{ $option }}" value="{{ $option }}"/>
|
||||||
$key = mb_strtolower(str_replace(' ', '_', $option));
|
|
||||||
@endphp
|
|
||||||
<flux:checkbox label="{{ $option }}" value="{{ $key }}"/>
|
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,6 @@ it('loads plugins from catalog URL', function () {
|
||||||
'trmnlp' => [
|
'trmnlp' => [
|
||||||
'zip_url' => 'https://example.com/plugin.zip',
|
'zip_url' => 'https://example.com/plugin.zip',
|
||||||
],
|
],
|
||||||
'byos' => [
|
|
||||||
'byos_laravel' => [
|
|
||||||
'compatibility' => true,
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'logo_url' => 'https://example.com/logo.png',
|
'logo_url' => 'https://example.com/logo.png',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use App\Liquid\Filters\StandardFilters;
|
|
||||||
use App\Models\Plugin;
|
use App\Models\Plugin;
|
||||||
use Keepsuit\Liquid\Environment;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the Liquid where filter functionality
|
* Tests for the Liquid where filter functionality
|
||||||
|
|
@ -94,31 +92,3 @@ LIQUID
|
||||||
// Should not contain the low tide data
|
// Should not contain the low tide data
|
||||||
$this->assertStringNotContainsString('"type":"L"', $result);
|
$this->assertStringNotContainsString('"type":"L"', $result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('encodes arrays for url_encode as JSON with spaces after commas and then percent-encodes', function () {
|
|
||||||
/** @var Environment $env */
|
|
||||||
$env = app('liquid.environment');
|
|
||||||
$env->filterRegistry->register(StandardFilters::class);
|
|
||||||
|
|
||||||
$template = $env->parseString('{{ categories | url_encode }}');
|
|
||||||
|
|
||||||
$output = $template->render($env->newRenderContext([
|
|
||||||
'categories' => ['common', 'obscure'],
|
|
||||||
]));
|
|
||||||
|
|
||||||
expect($output)->toBe('%5B%22common%22%2C%22obscure%22%5D');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('keeps scalar url_encode behavior intact', function () {
|
|
||||||
/** @var Environment $env */
|
|
||||||
$env = app('liquid.environment');
|
|
||||||
$env->filterRegistry->register(StandardFilters::class);
|
|
||||||
|
|
||||||
$template = $env->parseString('{{ text | url_encode }}');
|
|
||||||
|
|
||||||
$output = $template->render($env->newRenderContext([
|
|
||||||
'text' => 'hello world',
|
|
||||||
]));
|
|
||||||
|
|
||||||
expect($output)->toBe('hello+world');
|
|
||||||
});
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue