Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vite function #435

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions config/twigbridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@

// 'TwigBridge\Extension\Laravel\Form',
// 'TwigBridge\Extension\Laravel\Html',
// 'TwigBridge\Extension\Laravel\Vite',
// 'TwigBridge\Extension\Laravel\Legacy\Facades',
],

Expand Down
84 changes: 84 additions & 0 deletions src/Extension/Laravel/Vite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/**
* This file is part of the TwigBridge package.
*
* @copyright Robert Crowe <hello@vivalacrowe.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace TwigBridge\Extension\Laravel;

use Illuminate\Foundation\Vite as IlluminateVite;
use Twig\TwigFunction;
use Twig\Extension\AbstractExtension;

/**
* Access Laravels string class in your Twig templates.
*/
class Vite extends AbstractExtension
{
/**
* @var string|object
*/
protected $callback = 'Illuminate\Foundation\Vite';

/**
* Return the string object callback.
*
* @return string|object
*/
public function getCallback()
{
return $this->callback;
}

/**
* Set a new string callback.
*
* @param string|object
*
* @return void
*/
public function setCallback($callback)
{
$this->callback = $callback;
}

/**
* {@inheritDoc}
*/
public function getName()
{
return 'TwigBridge_Extension_Laravel_Vite';
}

/**
* {@inheritDoc}
*/
public function getFunctions()
{
return [
new TwigFunction(
'vite',
function (...$arguments) {
$arguments ??= '()';

$html = app(IlluminateVite::class)($arguments);

return $html->toHtml();
}
),
];
}

/**
* {@inheritDoc}
*/
public function getFilters()
{
return [];
}
}