diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index e047b1dbb9..844db98847 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -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() diff --git a/app/Support/TwigSupport.php b/app/Support/TwigSupport.php new file mode 100644 index 0000000000..9e09690a3a --- /dev/null +++ b/app/Support/TwigSupport.php @@ -0,0 +1,90 @@ +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'; + } + +} \ No newline at end of file diff --git a/resources/twig/auth/login.twig b/resources/twig/auth/login.twig index 6853a7f764..b8a75141db 100644 --- a/resources/twig/auth/login.twig +++ b/resources/twig/auth/login.twig @@ -22,7 +22,7 @@