Define assets in a more appropriate spot, make extensible

This commit is contained in:
Toby Zerner 2015-05-02 08:10:06 +09:30
parent 4c42be1362
commit 40715203a5
5 changed files with 31 additions and 26 deletions

View File

@ -7,6 +7,7 @@ use Cookie;
use Config;
use View;
use DB;
use Flarum\Forum\Events\RenderView;
class IndexAction extends BaseAction
{
@ -32,14 +33,25 @@ class IndexAction extends BaseAction
}
}
return View::make('flarum.forum::index')
$view = View::make('flarum.forum::index')
->with('title', Config::get('flarum::forum_title', 'Flarum Demo Forum'))
->with('styles', app('flarum.forum.assetManager')->getCSSFiles())
->with('scripts', app('flarum.forum.assetManager')->getJSFiles())
->with('config', $config)
->with('layout', View::make('flarum.forum::forum'))
->with('layout', 'flarum.forum::forum')
->with('data', $data)
->with('session', $session)
->with('alert', $alert);
$assetManager = app('flarum.forum.assetManager');
$root = __DIR__.'/../../..';
$assetManager->addFile([
$root.'/js/forum/dist/app.js',
$root.'/less/forum/app.less'
]);
event(new RenderView($view, $assetManager));
return $view
->with('styles', $assetManager->getCSSFiles())
->with('scripts', $assetManager->getJSFiles());
}
}

View File

@ -1,11 +0,0 @@
<?php namespace Flarum\Forum\Events;
class BootForum
{
public $app;
public function __construct($app)
{
$this->app = $app;
}
}

View File

@ -0,0 +1,14 @@
<?php namespace Flarum\Forum\Events;
class RenderView
{
public $view;
public $assets;
public function __construct(&$view, $assets)
{
$this->view = &$view;
$this->assets = $assets;
}
}

View File

@ -2,7 +2,6 @@
use Illuminate\Support\ServiceProvider;
use Flarum\Support\AssetManager;
use Flarum\Forum\Events\BootForum;
class ForumServiceProvider extends ServiceProvider
{
@ -17,15 +16,6 @@ class ForumServiceProvider extends ServiceProvider
$this->loadViewsFrom($root.'/views', 'flarum.forum');
$assetManager = $this->app['flarum.forum.assetManager'];
$assetManager->addFile([
$root.'/js/forum/dist/app.js',
$root.'/less/forum/app.less'
]);
event(new BootForum($this->app));
$this->publishes([
$root.'/public/fonts' => public_path('flarum/fonts')
]);

View File

@ -13,7 +13,7 @@
</head>
<body>
{!! $layout !!}
@include($layout)
<div id="modal"></div>
<div id="alerts"></div>