Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/rapidez/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,10 @@

// The path to redirect to after a failed checkout
'checkout_success_fail_redirect_path' => 'cart',

// This array should contain any turbo frames with their respective views.
// These should then be used by using @turboframe('frame-name')
'turbo_frames' => [
// 'frame-name' => 'view-path',
],
];
11 changes: 11 additions & 0 deletions resources/views/turbo-frame.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@props(['frame', 'viewPath', 'isRoute' => false])
<turbo-frame
id="menu"
@unless ($isRoute)
src="{{ route('turbo-frame', ['frame' => $frame, 'cachekey' => Rapidez::getCacheKey()]) }}"
loading="lazy"
target="_top"
@endunless
>
@includeCached($viewPath, ['complete' => $isRoute])
</turbo-frame>
11 changes: 11 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@
Route::fallback(config('rapidez.routing.controllers.fallback'));

Route::get('heartbeat', fn () => response()->json(['alive' => true]));

Route::middleware('cache.headers:public;max_age=3600;stale_while_revalidate=3600;etag')->group(function () {
Route::get('turbo/{frame}/{cachekey}', function (string $frame) {
$viewPath = config('rapidez.frontend.turbo_frames')[$frame] ?? null;
if (! $viewPath) {
abort(404);
}

return view('rapidez::turbo-frame', ['frame' => $frame, 'viewPath' => $viewPath, 'isRoute' => true]);
})->name('turbo-frame');
});
});
12 changes: 10 additions & 2 deletions src/RapidezServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function bootPublishables(): self

// We're so explicit here as otherwise the json translations will also be published.
// That will publish to /lang/vendor/rapidez/nl.json where it will not be loaded
// by default and; you should keep everyting in one place: /lang/nl.json
// by default and; you should keep everything in one place: /lang/nl.json
foreach (['en', 'nl'] as $lang) {
$this->publishes([
__DIR__ . '/../lang/' . $lang . '/frontend.php' => lang_path('vendor/rapidez/' . $lang . '/frontend.php'),
Expand Down Expand Up @@ -238,6 +238,14 @@ protected function registerBladeDirectives(): self
return "<?php echo Rapidez::config({$expression}) ?>";
});

Blade::directive('turboframe', function (string $frame) {
return "<?php
\$viewPath = config('rapidez.frontend.turbo_frames')[{$frame}] ?? null;
if (\$viewPath) { echo \$__env->make('rapidez::turbo-frame', [...\Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']), 'frame' => {$frame}, 'viewPath' => \$viewPath, 'isRoute' => false])->render(); }
elseif (!app()->environment('production')) { echo 'Turbo frame \"' . {$frame} .'\" not found'; }
?>";
});

Blade::if('storecode', function ($value) {
$value = is_array($value) ? $value : func_get_args();

Expand Down Expand Up @@ -412,7 +420,7 @@ function ($url) {

$this->setAppends(
Arr::reject(
$this->getAppends(), fn ($curentAppends) => in_array($curentAppends, $appendsToRemove)
$this->getAppends(), fn ($currentAppends) => in_array($currentAppends, $appendsToRemove)
)
);

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading