Skip to content

Commit

Permalink
Added JS and CSS capability
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkyle committed Dec 22, 2016
1 parent 9d4978c commit 4f2b5f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/WebsiteMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,9 @@ public function __invoke(Request $request, Response $response, $next)


// ---------------------------------------
// 3. After that, render 'full page' template
// 3. Create template variables
// ---------------------------------------

// Output global website template
$this->logger->debug("Render page template…");

$render = $this->render;

$vars = array_merge(
$this->defaults, [
'title' => $website->getTitle(),
Expand All @@ -104,16 +99,25 @@ public function __invoke(Request $request, Response $response, $next)
]
);

$vars['javascripts'] = isset($vars['javascripts']) ? array_merge($vars['javascripts'], $website->getJavascripts());
$vars['stylesheets'] = isset($vars['stylesheets']) ? array_merge($vars['stylesheets'], $website->getStylesheets());
$vars['javascripts'] = isset($vars['javascripts']) ? array_merge($vars['javascripts'], $website->getJavascripts()) : $website->getJavascripts();
$vars['stylesheets'] = isset($vars['stylesheets']) ? array_merge($vars['stylesheets'], $website->getStylesheets()) : $website->getStylesheets();


// ---------------------------------------
// 5. After that, render 'full page' template
// ---------------------------------------

// Output global website template
$this->logger->debug("Render page template…");

$render = $this->render;
$full_page_html = $render( $this->template, $vars);

$this->logger->debug("Finish page template render; write response");


// ---------------------------------------
// 4. Write response
// 6. Write response
// ---------------------------------------

$full_html_response_body = new ResponseBody(fopen('php://temp', 'r+'));
Expand Down
4 changes: 4 additions & 0 deletions tests/default/WebsiteMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function testInstantiation( $template, $defaults, $logger )
$website_mock = $this->prophesize( WebsiteInterface::class );
$website_mock->getTitle()->willReturn( "TheTitle" );
$website_mock->getDomId()->willReturn( "dom-id" );
$website_mock->getJavascripts()->willReturn( array("javascript") );
$website_mock->getStylesheets()->willReturn( array("stylesheet") );
$website = $website_mock->reveal();


Expand Down Expand Up @@ -50,6 +52,8 @@ public function testInvokation( $template, $defaults, $logger )
$website_mock = $this->prophesize( WebsiteInterface::class );
$website_mock->getTitle()->willReturn( "TheTitle" );
$website_mock->getDomId()->willReturn( "dom-id" );
$website_mock->getJavascripts()->willReturn( array("javascript") );
$website_mock->getStylesheets()->willReturn( array("stylesheet") );
$website = $website_mock->reveal();

$container_mock = $this->prophesize( ContainerInterface::class );
Expand Down

0 comments on commit 4f2b5f8

Please sign in to comment.