mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Optimised Twig extensions.
This commit is contained in:
parent
c98275e73a
commit
bda18f296d
@ -9,12 +9,10 @@ use FireflyIII\Support\ExpandedForm;
|
||||
use FireflyIII\Support\Navigation;
|
||||
use FireflyIII\Support\Preferences;
|
||||
use FireflyIII\Support\Steam;
|
||||
use FireflyIII\Support\TwigSupport;
|
||||
use FireflyIII\Validation\FireflyValidator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Route;
|
||||
use Twig;
|
||||
use Twig_SimpleFilter;
|
||||
use Twig_SimpleFunction;
|
||||
use TwigBridge\Extension\Loader\Functions;
|
||||
use Validator;
|
||||
|
||||
@ -35,81 +33,10 @@ class FireflyServiceProvider extends ServiceProvider
|
||||
/*
|
||||
* Default Twig configuration:
|
||||
*/
|
||||
|
||||
$config = App::make('config');
|
||||
Twig::addExtension(new Functions($config));
|
||||
|
||||
/*
|
||||
* Amount::format
|
||||
*/
|
||||
$filter = new Twig_SimpleFilter(
|
||||
'formatAmount', function ($string) {
|
||||
return App::make('amount')->format($string);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
Twig::addFilter($filter);
|
||||
|
||||
/*
|
||||
* Amount::formatJournal
|
||||
*/
|
||||
$filter = new Twig_SimpleFilter(
|
||||
'formatJournal', function ($journal) {
|
||||
return App::make('amount')->formatJournal($journal);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
Twig::addFilter($filter);
|
||||
|
||||
/*
|
||||
* Steam::balance()
|
||||
*/
|
||||
|
||||
$filter = new Twig_SimpleFilter(
|
||||
'balance', function (Account $account = null) {
|
||||
if (is_null($account)) {
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
return App::make('amount')->format(App::make('steam')->balance($account));
|
||||
//return App::make('steam')->balance($account);
|
||||
},['is_safe' => ['html']]
|
||||
);
|
||||
Twig::addFilter($filter);
|
||||
|
||||
|
||||
/*
|
||||
* Current active route.
|
||||
*/
|
||||
$filter = new Twig_SimpleFilter(
|
||||
'activeRoute', function ($string) {
|
||||
if (Route::getCurrentRoute()->getName() == $string) {
|
||||
return 'active';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
);
|
||||
Twig::addFilter($filter);
|
||||
|
||||
/*
|
||||
* Amount::getCurrencyCode()
|
||||
*/
|
||||
$function = new Twig_SimpleFunction(
|
||||
'getCurrencyCode', function () {
|
||||
return App::make('amount')->getCurrencyCode();
|
||||
}
|
||||
);
|
||||
Twig::addFunction($function);
|
||||
|
||||
|
||||
/*
|
||||
* env
|
||||
*/
|
||||
$function = new Twig_SimpleFunction(
|
||||
'env', function ($a, $b) {
|
||||
return env($a, $b);
|
||||
}
|
||||
);
|
||||
Twig::addFunction($function);
|
||||
|
||||
Twig::addExtension(new TwigSupport);
|
||||
}
|
||||
|
||||
public function register()
|
||||
|
90
app/Support/TwigSupport.php
Normal file
90
app/Support/TwigSupport.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Support;
|
||||
|
||||
use App;
|
||||
use FireflyIII\Models\Account;
|
||||
use Route;
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFilter;
|
||||
use Twig_SimpleFunction;
|
||||
|
||||
/**
|
||||
* Class TwigSupport
|
||||
*
|
||||
* @package FireflyIII\Support
|
||||
*/
|
||||
class TwigSupport extends Twig_Extension
|
||||
{
|
||||
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
$filters = [];
|
||||
|
||||
$filters[] = new Twig_SimpleFilter(
|
||||
'formatAmount', function ($string) {
|
||||
return App::make('amount')->format($string);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
|
||||
$filters[] = new Twig_SimpleFilter(
|
||||
'formatJournal', function ($journal) {
|
||||
return App::make('amount')->formatJournal($journal);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
|
||||
$filters[] = new Twig_SimpleFilter(
|
||||
'balance', function (Account $account = null) {
|
||||
if (is_null($account)) {
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
return App::make('amount')->format(App::make('steam')->balance($account));
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
$filters[] = new Twig_SimpleFilter(
|
||||
'activeRoute', function ($string) {
|
||||
if (Route::getCurrentRoute()->getName() == $string) {
|
||||
return 'active';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
);
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
$functions = [];
|
||||
|
||||
$functions[] = new Twig_SimpleFunction(
|
||||
'getCurrencyCode', function () {
|
||||
return App::make('amount')->getCurrencyCode();
|
||||
}
|
||||
);
|
||||
|
||||
$functions[] = new Twig_SimpleFunction(
|
||||
'env', function ($name, $default) {
|
||||
return env($name, $default);
|
||||
}
|
||||
);
|
||||
|
||||
return $functions;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'FireflyIII\Support\TwigSupport';
|
||||
}
|
||||
|
||||
}
|
@ -22,7 +22,7 @@
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form role="form" method="POST" id="login" action="/auth/login">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token }}">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||
<div class="form-group">
|
||||
<label class="control-label">E-Mail</label>
|
||||
<input type="email" class="form-control" id="inputEmail" name="email" placeholder="E-Mail">
|
||||
|
Loading…
Reference in New Issue
Block a user