Skip to content

Commit

Permalink
Merge pull request CouscousPHP#113 from MontealegreLuis/master
Browse files Browse the repository at this point in the history
Add images outside the template folder to the current project.
  • Loading branch information
mnapoli committed Jul 21, 2015
2 parents 513a0d8 + ee72472 commit 128f4f3
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/Module/Core/Step/AddImages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Couscous\Module\Core\Step;

use Couscous\Model\LazyFile;
use Couscous\Model\Project;
use Couscous\Step;

/**
* Add images to the project
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
class AddImages implements Step
{
/**
* Add images to the given project.
*
* @param Project $project
*/
public function __invoke(Project $project)
{
$files = $project->sourceFiles();
$files
->name('*.gif')
->name('*.png')
->name('*.jpg')
;

$project->watchlist->watchFiles($files);

foreach ($files as $file) {
/** @var SplFileInfo $file */
$project->addFile(new LazyFile($file->getPathname(), $file->getRelativePathname()));
}
}
}
5 changes: 3 additions & 2 deletions src/Module/Core/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
return [

'steps.after' => DI\add([
DI\get('Couscous\Module\Core\Step\ClearTargetDirectory'),
DI\get('Couscous\Module\Core\Step\WriteFiles'),
DI\link('Couscous\Module\Core\Step\AddImages'),
DI\link('Couscous\Module\Core\Step\ClearTargetDirectory'),
DI\link('Couscous\Module\Core\Step\WriteFiles'),
]),

];
12 changes: 12 additions & 0 deletions tests/FunctionalTest/Fixture/images/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Documentation</title>
</head>
<body>
<p>Hello, this is a test!</p>
<p><img src="/logos/couscous.jpg" alt="Couscous logo" title="Couscous logo (.jpg)" /></p>
<p><img src="/logos/couscous.png" alt="Couscous logo" title="Couscous logo (.png)" /></p>
<p><img src="/logos/couscous.gif" alt="Couscous logo" title="Couscous logo (.gif)" /></p>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions tests/FunctionalTest/Fixture/images/source/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Hello, this is a test!


![Couscous logo](/logos/couscous.jpg "Couscous logo (.jpg)")

![Couscous logo](/logos/couscous.png "Couscous logo (.png)")

![Couscous logo](/logos/couscous.gif "Couscous logo (.gif)")
2 changes: 2 additions & 0 deletions tests/FunctionalTest/Fixture/images/source/couscous.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exclude:
- exclude
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Documentation</title>
</head>
<body>
{{ content|raw }}
</body>
</html>
8 changes: 8 additions & 0 deletions tests/FunctionalTest/GenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public function testPageList()
{
$this->assertGeneratedWebsite('page-list');
}

/**
* Test that the images referenced by documentation are copied.
*/
public function testDocumentationImages()
{
$this->assertGeneratedWebsite('images');
}
}

0 comments on commit 128f4f3

Please sign in to comment.