Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
Update for Engine 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Aug 2, 2017
1 parent afe35f9 commit b2207ee
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require" : {
"php" : "^7.0",
"ext-dom" : "*",
"templado/engine": "^1.1"
"templado/engine": "^2.0"
},
"autoload": {
"classmap": [
Expand Down
17 changes: 9 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions src/Generator.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types = 1);
namespace Templado\Cli;

use Templado\Engine\AssetListCollection;
use Templado\Engine\AssetLoader;
use Templado\Engine\AssetLoaderException;
use Templado\Engine\SnippetListCollection;
use Templado\Engine\SnippetLoader;
use Templado\Engine\SnippetLoaderException;
use Templado\Engine\FileName;
use Templado\Engine\Templado;

Expand All @@ -17,7 +17,7 @@ class Generator {
/**
* @var Directory
*/
private $assetsDirectory;
private $snippetsDirectory;

/**
* @var Directory
Expand All @@ -37,14 +37,14 @@ class Generator {
public function __construct(GeneratorConfig $config, Logger $logger) {

$this->srcDirectory = $config->getSourceDirectory();
$this->assetsDirectory = $config->getAssetDirectory();
$this->snippetsDirectory = $config->getSnippetDirectory();
$this->targetDirectory = $config->getTargetDirectory();
$this->clearFirst = $config->clearFirst();
$this->logger = $logger;
}

public function run(): int {
$assets = $this->loadAssets();
$snippets = $this->loadSnippets();

if ($this->clearFirst) {
$this->logger->log(
Expand All @@ -62,47 +62,47 @@ public function run(): int {
if (!$src->isFile()) {
continue;
}
$this->processFile($src, $assets);
$this->processFile($src, $snippets);
}

return Runner::RC_OK;
}

private function loadAssets(): AssetListCollection {
$assets = new AssetListCollection();
$loader = new AssetLoader();
private function loadSnippets(): SnippetListCollection {
$snippets = new SnippetListCollection();
$loader = new SnippetLoader();

$this->logger->log(
sprintf('Loading assets from directory "%s"', $this->assetsDirectory->asString())
sprintf('Loading snippets from directory "%s"', $this->snippetsDirectory->asString())
);
foreach($this->assetsDirectory as $file) {
foreach($this->snippetsDirectory as $file) {
/** @var \SplFileInfo $file */
if (!$file->isFile()) {
continue;
}

try {
$assets->addAsset($loader->load(new FileName($file->getRealPath())));
$snippets->addSnippet($loader->load(new FileName($file->getRealPath())));
$this->logger->log(
sprintf('🗸 %s', $file->getPathname())
);
} catch (AssetLoaderException $e) {
} catch (SnippetLoaderException $e) {
$this->logger->log(
sprintf('🗴 %s: %s', $file->getPathname(), $e->getMessage())
);
}
}

return $assets;
return $snippets;
}

/**
* @param \SplFileInfo $src
* @param AssetListCollection $assets
* @param SnippetListCollection $snippets
*/
private function processFile(\SplFileInfo $src, AssetListCollection $assets) {
$page = Templado::loadFile(new FileName($src->getPathname()));
$page->applyAssets($assets);
private function processFile(\SplFileInfo $src, SnippetListCollection $snippets) {
$page = Templado::loadHtmlFile(new FileName($src->getPathname()));
$page->applySnippets($snippets);
$target = $this->targetPath($src);
@mkdir(dirname($target), 0777, true);
file_put_contents($target, $page->asString());
Expand Down
4 changes: 2 additions & 2 deletions src/GeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function getSourceDirectory(): Directory {
return $this->request->getSourceDirectory();
}

public function getAssetDirectory(): Directory {
return $this->request->getAssetDirectory();
public function getSnippetDirectory(): Directory {
return $this->request->getSnippetDirectory();
}

public function getTargetDirectory(): Directory {
Expand Down
2 changes: 1 addition & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getSourceDirectory(): Directory {
return new Directory($this->arguments[0]);
}

public function getAssetDirectory(): Directory {
public function getSnippetDirectory(): Directory {
$this->parse();

return new Directory($this->arguments[1]);
Expand Down
4 changes: 2 additions & 2 deletions src/help.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Usage: templado [options] <src> <assets> <target>
Usage: templado [options] <src> <snippets> <target>

<src> Directory containing HTML files
<assets> Directory containing assets to be applied on HTML files found in <src>
<snippets> Directory containing snippets to be applied on HTML files found in <src>

<target> Output directory for the result

Expand Down

0 comments on commit b2207ee

Please sign in to comment.