diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php
index 610ad4418f..0574f00b80 100644
--- a/app/Http/breadcrumbs.php
+++ b/app/Http/breadcrumbs.php
@@ -22,6 +22,14 @@ Breadcrumbs::register(
}
);
+Breadcrumbs::register(
+ 'index',
+ function (Generator $breadcrumbs) {
+
+ $breadcrumbs->push('Home', route('index'));
+ }
+);
+
// accounts
Breadcrumbs::register(
'accounts.index', function (Generator $breadcrumbs, $what) {
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index bfff79a9f2..af0a5a5b8e 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -35,6 +35,7 @@ class AppServiceProvider extends ServiceProvider
'Illuminate\Contracts\Auth\Registrar',
'FireflyIII\Services\Registrar'
);
+
}
}
diff --git a/app/Providers/ConfigServiceProvider.php b/app/Providers/ConfigServiceProvider.php
index 94d9ee03fd..c4deebb1d1 100644
--- a/app/Providers/ConfigServiceProvider.php
+++ b/app/Providers/ConfigServiceProvider.php
@@ -23,7 +23,212 @@ class ConfigServiceProvider extends ServiceProvider
{
config(
[
- //
+ 'twigbridge' => [
+
+ 'twig' => [
+ /*
+ |--------------------------------------------------------------------------
+ | Extension
+ |--------------------------------------------------------------------------
+ |
+ | File extension for Twig view files.
+ |
+ */
+ 'extension' => 'twig',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Accepts all Twig environment configuration options
+ |--------------------------------------------------------------------------
+ |
+ | http://twig.sensiolabs.org/doc/api.html#environment-options
+ |
+ */
+ 'environment' => [
+
+ // When set to true, the generated templates have a __toString() method
+ // that you can use to display the generated nodes.
+ // default: false
+ 'debug' => config('app.debug', false),
+
+ // The charset used by the templates.
+ // default: utf-8
+ 'charset' => 'utf-8',
+
+ // The base template class to use for generated templates.
+ // default: TwigBridge\Twig\Template
+ 'base_template_class' => 'TwigBridge\Twig\Template',
+
+ // An absolute path where to store the compiled templates, or false to disable caching. If null
+ // then the cache file path is used.
+ // default: cache file storage path
+ 'cache' => null,
+
+ // When developing with Twig, it's useful to recompile the template
+ // whenever the source code changes. If you don't provide a value
+ // for the auto_reload option, it will be determined automatically based on the debug value.
+ 'auto_reload' => true,
+
+ // If set to false, Twig will silently ignore invalid variables
+ // (variables and or attributes/methods that do not exist) and
+ // replace them with a null value. When set to true, Twig throws an exception instead.
+ // default: false
+ 'strict_variables' => false,
+
+ // If set to true, auto-escaping will be enabled by default for all templates.
+ // default: true
+ 'autoescape' => true,
+
+ // A flag that indicates which optimizations to apply
+ // (default to -1 -- all optimizations are enabled; set it to 0 to disable)
+ 'optimizations' => -1,
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Global variables
+ |--------------------------------------------------------------------------
+ |
+ | These will always be passed in and can be accessed as Twig variables.
+ | NOTE: these will be overwritten if you pass data into the view with the same key.
+ |
+ */
+ 'globals' => [],
+ ],
+
+ 'extensions' => [
+
+ /*
+ |--------------------------------------------------------------------------
+ | Extensions
+ |--------------------------------------------------------------------------
+ |
+ | Enabled extensions.
+ |
+ | `Twig_Extension_Debug` is enabled automatically if twig.debug is TRUE.
+ |
+ */
+ 'enabled' => [
+ 'TwigBridge\Extension\Loader\Facades',
+ 'TwigBridge\Extension\Loader\Filters',
+ 'TwigBridge\Extension\Loader\Functions',
+
+ 'TwigBridge\Extension\Laravel\Auth',
+ 'TwigBridge\Extension\Laravel\Config',
+ 'TwigBridge\Extension\Laravel\Dump',
+ 'TwigBridge\Extension\Laravel\Input',
+ 'TwigBridge\Extension\Laravel\Session',
+ 'TwigBridge\Extension\Laravel\String',
+ 'TwigBridge\Extension\Laravel\Translator',
+ 'TwigBridge\Extension\Laravel\Url',
+
+ // 'TwigBridge\Extension\Laravel\Form',
+ // 'TwigBridge\Extension\Laravel\Html',
+ // 'TwigBridge\Extension\Laravel\Legacy\Facades',
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Facades
+ |--------------------------------------------------------------------------
+ |
+ | Available facades. Access like `{{ Config.get('foo.bar') }}`.
+ |
+ | Each facade can take an optional array of options. To mark the whole facade
+ | as safe you can set the option `'is_safe' => true`. Setting the facade as
+ | safe means that any HTML returned will not be escaped.
+ |
+ | It is advisable to not set the whole facade as safe and instead mark the
+ | each appropriate method as safe for security reasons. You can do that with
+ | the following syntax:
+ |
+ |
+ | 'Form' => [
+ | 'is_safe' => [
+ | 'open'
+ | ]
+ | ]
+ |
+ |
+ | The values of the `is_safe` array must match the called method on the facade
+ | in order to be marked as safe.
+ |
+ */
+ 'facades' => [
+ 'Breadcrumbs' => [
+ 'is_safe' => [
+ 'renderIfExists'
+ ]
+ ],
+ 'Session',
+ 'Route'
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Functions
+ |--------------------------------------------------------------------------
+ |
+ | Available functions. Access like `{{ secure_url(...) }}`.
+ |
+ | Each function can take an optional array of options. These options are
+ | passed directly to `Twig_SimpleFunction`.
+ |
+ | So for example, to mark a function as safe you can do the following:
+ |
+ |
+ | 'link_to' => [
+ | 'is_safe' => ['html']
+ | ]
+ |
+ |
+ | The options array also takes a `callback` that allows you to name the
+ | function differently in your Twig templates than what it's actually called.
+ |
+ |
+ | 'link' => [
+ | 'callback' => 'link_to'
+ | ]
+ |
+ |
+ */
+ 'functions' => [
+ 'elixir',
+ 'head',
+ 'last',
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Filters
+ |--------------------------------------------------------------------------
+ |
+ | Available filters. Access like `{{ variable|filter }}`.
+ |
+ | Each filter can take an optional array of options. These options are
+ | passed directly to `Twig_SimpleFilter`.
+ |
+ | So for example, to mark a filter as safe you can do the following:
+ |
+ |
+ | 'studly_case' => [
+ | 'is_safe' => ['html']
+ | ]
+ |
+ |
+ | The options array also takes a `callback` that allows you to name the
+ | filter differently in your Twig templates than what is actually called.
+ |
+ |
+ | 'snake' => [
+ | 'callback' => 'snake_case'
+ | ]
+ |
+ |
+ */
+ 'filters' => [],
+ ],
+ ]
]
);
}
diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php
index 1b57c3508e..e047b1dbb9 100644
--- a/app/Providers/FireflyServiceProvider.php
+++ b/app/Providers/FireflyServiceProvider.php
@@ -3,6 +3,7 @@
namespace FireflyIII\Providers;
use App;
+use FireflyIII\Models\Account;
use FireflyIII\Support\Amount;
use FireflyIII\Support\ExpandedForm;
use FireflyIII\Support\Navigation;
@@ -10,7 +11,10 @@ use FireflyIII\Support\Preferences;
use FireflyIII\Support\Steam;
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;
@@ -28,14 +32,89 @@ class FireflyServiceProvider extends ServiceProvider
return new FireflyValidator($translator, $data, $rules, $messages);
}
);
+ /*
+ * 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);
}
public function register()
{
- $config = App::make('config');
- Twig::addExtension(new Functions($config));
$this->app->bind(
'preferences', function () {
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index b886074aa9..b8cf753024 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -13,6 +13,7 @@ use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Validation\Validator;
use Log;
use Navigation;
+use Symfony\Component\Translation\TranslatorInterface;
/**
* Class FireflyValidator
@@ -22,6 +23,18 @@ use Navigation;
class FireflyValidator extends Validator
{
+ /**
+ * @param TranslatorInterface $translator
+ * @param array $data
+ * @param array $rules
+ * @param array $messages
+ * @param array $customAttributes
+ */
+ public function __construct(TranslatorInterface $translator, array $data, array $rules, array $messages = [], array $customAttributes = [])
+ {
+ parent::__construct($translator, $data, $rules, $messages);
+ }
+
/**
* @param $attribute
* @param $value
diff --git a/resources/twig/index.twig b/resources/twig/index.twig
new file mode 100644
index 0000000000..c767243e4c
--- /dev/null
+++ b/resources/twig/index.twig
@@ -0,0 +1,215 @@
+{% extends "./layout/default.twig" %}
+{% block content %}
+{{ Breadcrumbs.renderIfExists }}
+
+{% if count == 0 %}
+
Welcome to Firefly III.
+ ++ Create a new asset account to get started. +
+Mark your asset accounts as "Savings account" to fill this panel.
+ {% else %} + {% for account in savings %} + +Create piggy banks to fill this panel.
+ {% else %} + {% for account in piggyBankAccounts %} +