config add to head/body

This commit is contained in:
Milos Stojanovic
2019-06-16 11:54:58 +02:00
parent da98b46f62
commit 291fa69c2b
4 changed files with 13 additions and 20 deletions

View File

@@ -25,6 +25,8 @@ class Vuejs implements Service, ViewInterface
public function init(array $config = []) public function init(array $config = [])
{ {
$this->add_to_head = isset($config['add_to_head']) ? $config['add_to_head'] : '';
$this->add_to_body = isset($config['add_to_body']) ? $config['add_to_body'] : '';
} }
public function getIndexPage() public function getIndexPage()
@@ -41,6 +43,7 @@ class Vuejs implements Service, ViewInterface
<meta name=viewport content="width=device-width,initial-scale=1"> <meta name=viewport content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex,nofollow"> <meta name="robots" content="noindex,nofollow">
<title>'.$title.'</title> <title>'.$title.'</title>
'.$this->add_to_head.'
<link rel=stylesheet href=https://use.fontawesome.com/releases/v5.2.0/css/all.css> <link rel=stylesheet href=https://use.fontawesome.com/releases/v5.2.0/css/all.css>
<link rel=stylesheet href=//cdn.materialdesignicons.com/2.5.94/css/materialdesignicons.min.css> <link rel=stylesheet href=//cdn.materialdesignicons.com/2.5.94/css/materialdesignicons.min.css>
<link href="'.$public_path.'css/app.css?'.@filemtime($public_dir.'/css/app.css').'" rel=stylesheet> <link href="'.$public_path.'css/app.css?'.@filemtime($public_dir.'/css/app.css').'" rel=stylesheet>
@@ -50,6 +53,8 @@ class Vuejs implements Service, ViewInterface
<div id=app></div> <div id=app></div>
<script src="'.$public_path.'js/app.js?'.@filemtime($public_dir.'/js/app.js').'"></script> <script src="'.$public_path.'js/app.js?'.@filemtime($public_dir.'/js/app.js').'"></script>
<script src="'.$public_path.'js/chunk-vendors.js?'.@filemtime($public_dir.'/js/chunk-vendors.js').'"></script> <script src="'.$public_path.'js/chunk-vendors.js?'.@filemtime($public_dir.'/js/chunk-vendors.js').'"></script>
'.$this->add_to_body.'
</body> </body>
</html> </html>
'; ';

View File

@@ -75,6 +75,10 @@ return [
], ],
'Filegator\Services\View\ViewInterface' => [ 'Filegator\Services\View\ViewInterface' => [
'handler' => '\Filegator\Services\View\Adapters\Vuejs', 'handler' => '\Filegator\Services\View\Adapters\Vuejs',
'config' => [
'add_to_head' => '',
'add_to_body' => '',
],
], ],
'Filegator\Services\Storage\Filesystem' => [ 'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem', 'handler' => '\Filegator\Services\Storage\Filesystem',

View File

@@ -15,7 +15,6 @@ use Filegator\Config\Config;
use Filegator\Container\Container; use Filegator\Container\Container;
use Filegator\Kernel\Request; use Filegator\Kernel\Request;
use Filegator\Kernel\Response; use Filegator\Kernel\Response;
use Filegator\Services\View\Adapters\Vuejs;
use Tests\FakeResponse; use Tests\FakeResponse;
use Tests\FakeStreamedResponse; use Tests\FakeStreamedResponse;
use Tests\TestCase; use Tests\TestCase;
@@ -39,23 +38,4 @@ class MainTest extends TestCase
$this->assertEquals($app->resolve(Request::class), $request); $this->assertEquals($app->resolve(Request::class), $request);
$this->assertInstanceOf(Response::class, $app->resolve(Response::class)); $this->assertInstanceOf(Response::class, $app->resolve(Response::class));
} }
public function testServices()
{
$config = [
'services' => [
'Service1' => [
'handler' => 'Filegator\Services\View\Adapters\Vuejs',
],
'Service2' => [
'handler' => 'Filegator\Services\View\Adapters\Vuejs',
],
],
];
$app = new App(new Config($config), new Request(), new FakeResponse(), new FakeStreamedResponse(), new Container());
$this->assertEquals($app->resolve('Service1'), new Vuejs(new Config($config)));
$this->assertEquals($app->resolve('Service2'), new Vuejs(new Config($config)));
}
} }

View File

@@ -46,6 +46,10 @@ return [
], ],
'Filegator\Services\View\ViewInterface' => [ 'Filegator\Services\View\ViewInterface' => [
'handler' => '\Filegator\Services\View\Adapters\Vuejs', 'handler' => '\Filegator\Services\View\Adapters\Vuejs',
'config' => [
'add_to_head' => '',
'add_to_body' => '',
],
], ],
'Filegator\Services\Storage\Filesystem' => [ 'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem', 'handler' => '\Filegator\Services\Storage\Filesystem',