Skip to content

Commit

Permalink
Fixed bugs after composite the web app
Browse files Browse the repository at this point in the history
  • Loading branch information
benatespina committed Sep 25, 2015
1 parent 14bdaaa commit 4d63130
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 19 deletions.
5 changes: 5 additions & 0 deletions spec/ConfigurationSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ function it_gets_template(TemplateInterface $template)
{
$this->template()->shouldReturn($template);
}

function it_assets_base_url()
{
$this->assetsBaseUrl()->shouldReturn('/templates');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Beñat Espiña <benatespina@gmail.com>
*/
class DefaultLoaderSpec extends ObjectBehavior
class HtmlLoaderSpec extends ObjectBehavior
{
function let(Configuration $configuration)
{
Expand All @@ -31,16 +31,16 @@ function let(Configuration $configuration)

function it_is_initializable()
{
$this->shouldHaveType('LIN3S\KnowledgeBase\Loader\DefaultLoader');
$this->shouldHaveType('LIN3S\KnowledgeBase\Loader\HtmlLoader');
}

function it_implements_loader_interface()
{
$this->shouldImplement('LIN3S\KnowledgeBase\Loader\Interfaces\LoaderInterface');
}

function it_gets_templates()
function it_gets()
{
$this->getTemplateData('build')->shouldBeArray();
$this->get('build');
}
}
46 changes: 46 additions & 0 deletions spec/Loader/MenuLoaderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Knowledge Base package.
*
* Copyright (c) 2015 LIN3S <info@lin3s.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\LIN3S\KnowledgeBase\Loader;

use LIN3S\KnowledgeBase\Configuration;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

/**
* Spec class of menu loader.
*
* @author Beñat Espiña <benatespina@gmail.com>
*/
class MenuLoaderSpec extends ObjectBehavior
{
function let(Configuration $configuration)
{
$configuration->buildPath()->willReturn(__DIR__ . '/../fixtures/');

$this->beConstructedWith($configuration);
}

function it_is_initializable()
{
$this->shouldHaveType('LIN3S\KnowledgeBase\Loader\MenuLoader');
}

function it_implements_loader_interface()
{
$this->shouldImplement('LIN3S\KnowledgeBase\Loader\Interfaces\LoaderInterface');
}

function it_get()
{
$this->get('build');
}
}
18 changes: 14 additions & 4 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class Configuration
/**
* Constructor.
*
* @param string $docsPath Path where the docs are located
* @param string $buildPath Path where the generated docs will be placed
* @param \LIN3S\KnowledgeBase\Templating\TemplateInterface $template The template
* @param string $assetsBaseUrl Base url templates will use to find assets
* @param string $docsPath Path where the docs are located
* @param string $buildPath Path where the generated docs will be placed
* @param TemplateInterface $template The template
* @param string $assetsBaseUrl Base url templates will use to find assets
*/
public function __construct($docsPath, $buildPath, TemplateInterface $template, $assetsBaseUrl = '/templates')
{
Expand Down Expand Up @@ -87,4 +87,14 @@ public function template()
{
return $this->template;
}

/**
* The assets base url.
*
* @return string
*/
public function assetsBaseUrl()
{
return $this->assetsBaseUrl;
}
}
2 changes: 1 addition & 1 deletion src/Generator/HTMLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function generate()

if (!file_exists($this->configuration->buildPath() . 'html' . $file->getPath())) {
mkdir($this->configuration->buildPath() . 'html' . $file->getPath(), 0755, true);
file_put_contents($path, $content);
}
file_put_contents($path, $content);
}
}

Expand Down
57 changes: 57 additions & 0 deletions src/Loader/DashboardLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Knowledge Base package.
*
* Copyright (c) 2015 LIN3S <info@lin3s.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LIN3S\KnowledgeBase\Loader;

use LIN3S\KnowledgeBase\Configuration;
use LIN3S\KnowledgeBase\Loader\Interfaces\LoaderInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* Dashboard loader with basic content fetching.
*
* @author Gorka Laucirica <gorka.lauzirika@gmail.com>
* @author Beñat Espiña <benatespina@gmail.com>
*/
class DashboardLoader implements LoaderInterface
{
/**
* The configuration.
*
* @var \LIN3S\KnowledgeBase\Configuration
*/
protected $configuration;

/**
* Constructor.
*
* @param \LIN3S\KnowledgeBase\Configuration $configuration
*/
public function __construct(Configuration $configuration)
{
$this->configuration = $configuration;
}

/**
* {@inheritdoc}
*/
public function get($path)
{
$filename = $this->configuration->buildPath() . 'html/' . $path . '.html';
$filesystem = new Filesystem();
if (false === $filesystem->exists($filename)) {
throw new NotFoundHttpException();
}

return file_get_contents($filename);
}
}
57 changes: 57 additions & 0 deletions src/Loader/HtmlLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Knowledge Base package.
*
* Copyright (c) 2015 LIN3S <info@lin3s.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LIN3S\KnowledgeBase\Loader;

use LIN3S\KnowledgeBase\Configuration;
use LIN3S\KnowledgeBase\Loader\Interfaces\LoaderInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* HTML loader with basic content fetching.
*
* @author Gorka Laucirica <gorka.lauzirika@gmail.com>
* @author Beñat Espiña <benatespina@gmail.com>
*/
class HtmlLoader implements LoaderInterface
{
/**
* The configuration.
*
* @var \LIN3S\KnowledgeBase\Configuration
*/
protected $configuration;

/**
* Constructor.
*
* @param \LIN3S\KnowledgeBase\Configuration $configuration
*/
public function __construct(Configuration $configuration)
{
$this->configuration = $configuration;
}

/**
* {@inheritdoc}
*/
public function get($path)
{
$filename = $this->configuration->buildPath() . 'html/' . $path . '.html';
$filesystem = new Filesystem();
if (false === $filesystem->exists($filename)) {
throw new \Exception('This page does not exist');
}

return file_get_contents($filename);
}
}
2 changes: 1 addition & 1 deletion src/Loader/Interfaces/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ interface LoaderInterface
*
* @return mixed
*/
public function getTemplateData($path);
public function get($path);
}
15 changes: 6 additions & 9 deletions src/Loader/DefaultLoader.php → src/Loader/MenuLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
use LIN3S\KnowledgeBase\Loader\Interfaces\LoaderInterface;

/**
* Default loader with basic content fetching
* Menu loader with basic content fetching.
*
* @author Gorka Laucirica <gorka.lauzirika@gmail.com>
* @author Beñat Espiña <benatespina@gmail.com>
*/
class DefaultLoader implements LoaderInterface
class MenuLoader implements LoaderInterface
{
/**
* The configuration.
*
* @var \LIN3S\KnowledgeBase\Configuration
*/
protected $configuration;
Expand All @@ -40,13 +42,8 @@ public function __construct(Configuration $configuration)
/**
* {@inheritdoc}
*/
public function getTemplateData($path)
public function get($path)
{
return [
'menu' => json_decode(file_get_contents($this->configuration->buildPath() . 'menu.json'), true),
'html' => null === $path ?:
file_get_contents($this->configuration->buildPath() . 'html/' . $path . '.html'),
'configuration' => $this->configuration
];
return json_decode(file_get_contents($this->configuration->buildPath() . 'menu.json'), true);
}
}

0 comments on commit 4d63130

Please sign in to comment.