mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-14 20:33:40 +00:00
feat: add support for trmnl-liquid renderer in recipe settings
This commit is contained in:
parent
d586ecb1f2
commit
06e6fb0e84
2 changed files with 55 additions and 0 deletions
|
|
@ -17,6 +17,8 @@ new class extends Component
|
||||||
|
|
||||||
public bool $alias = false;
|
public bool $alias = false;
|
||||||
|
|
||||||
|
public bool $use_trmnl_liquid_renderer = false;
|
||||||
|
|
||||||
public int $resetIndex = 0;
|
public int $resetIndex = 0;
|
||||||
|
|
||||||
public function mount(): void
|
public function mount(): void
|
||||||
|
|
@ -27,6 +29,7 @@ new class extends Component
|
||||||
$this->trmnlp_id = $this->plugin->trmnlp_id;
|
$this->trmnlp_id = $this->plugin->trmnlp_id;
|
||||||
$this->uuid = $this->plugin->uuid;
|
$this->uuid = $this->plugin->uuid;
|
||||||
$this->alias = $this->plugin->alias ?? false;
|
$this->alias = $this->plugin->alias ?? false;
|
||||||
|
$this->use_trmnl_liquid_renderer = $this->plugin->preferred_renderer === 'trmnl-liquid';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveTrmnlpId(): void
|
public function saveTrmnlpId(): void
|
||||||
|
|
@ -43,11 +46,13 @@ new class extends Component
|
||||||
->ignore($this->plugin->id),
|
->ignore($this->plugin->id),
|
||||||
],
|
],
|
||||||
'alias' => 'boolean',
|
'alias' => 'boolean',
|
||||||
|
'use_trmnl_liquid_renderer' => 'boolean',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->plugin->update([
|
$this->plugin->update([
|
||||||
'trmnlp_id' => empty($this->trmnlp_id) ? null : $this->trmnlp_id,
|
'trmnlp_id' => empty($this->trmnlp_id) ? null : $this->trmnlp_id,
|
||||||
'alias' => $this->alias,
|
'alias' => $this->alias,
|
||||||
|
'preferred_renderer' => $this->use_trmnl_liquid_renderer ? 'trmnl-liquid' : null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Flux::modal('trmnlp-settings')->close();
|
Flux::modal('trmnlp-settings')->close();
|
||||||
|
|
@ -83,6 +88,16 @@ new class extends Component
|
||||||
<flux:description>Enable an Alias URL for this recipe. Your server does not need to be exposed to the internet, but your device must be able to reach the URL. <a href="https://help.usetrmnl.com/en/articles/10701448-alias-plugin">Docs</a></flux:description>
|
<flux:description>Enable an Alias URL for this recipe. Your server does not need to be exposed to the internet, but your device must be able to reach the URL. <a href="https://help.usetrmnl.com/en/articles/10701448-alias-plugin">Docs</a></flux:description>
|
||||||
</flux:field>
|
</flux:field>
|
||||||
|
|
||||||
|
@if(config('services.trmnl.liquid_enabled') && $plugin->markup_language === 'liquid')
|
||||||
|
<flux:field>
|
||||||
|
<flux:checkbox
|
||||||
|
wire:model.live="use_trmnl_liquid_renderer"
|
||||||
|
label="Use trmnl-liquid renderer"
|
||||||
|
/>
|
||||||
|
<flux:description>trmnl-liquid is a Ruby-based renderer that matches the Core service’s Liquid behavior for better compatibility.</flux:description>
|
||||||
|
</flux:field>
|
||||||
|
@endif
|
||||||
|
|
||||||
@if($alias)
|
@if($alias)
|
||||||
<flux:field>
|
<flux:field>
|
||||||
<flux:label>Alias URL</flux:label>
|
<flux:label>Alias URL</flux:label>
|
||||||
|
|
|
||||||
|
|
@ -109,3 +109,43 @@ test('recipe settings can clear trmnlp_id', function (): void {
|
||||||
|
|
||||||
expect($plugin->fresh()->trmnlp_id)->toBeNull();
|
expect($plugin->fresh()->trmnlp_id)->toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('recipe settings saves preferred_renderer when liquid enabled and recipe is liquid', function (): void {
|
||||||
|
config(['services.trmnl.liquid_enabled' => true]);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$plugin = Plugin::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'markup_language' => 'liquid',
|
||||||
|
'preferred_renderer' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Livewire::test('plugins.recipes.settings', ['plugin' => $plugin])
|
||||||
|
->set('use_trmnl_liquid_renderer', true)
|
||||||
|
->call('saveTrmnlpId')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
expect($plugin->fresh()->preferred_renderer)->toBe('trmnl-liquid');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('recipe settings clears preferred_renderer when checkbox unchecked', function (): void {
|
||||||
|
config(['services.trmnl.liquid_enabled' => true]);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$plugin = Plugin::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'markup_language' => 'liquid',
|
||||||
|
'preferred_renderer' => 'trmnl-liquid',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Livewire::test('plugins.recipes.settings', ['plugin' => $plugin])
|
||||||
|
->set('use_trmnl_liquid_renderer', false)
|
||||||
|
->call('saveTrmnlpId')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
expect($plugin->fresh()->preferred_renderer)->toBeNull();
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue