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

Commit b2207ee

Browse files
committed
Update for Engine 2.0.0
1 parent afe35f9 commit b2207ee

6 files changed

Lines changed: 34 additions & 33 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require" : {
1616
"php" : "^7.0",
1717
"ext-dom" : "*",
18-
"templado/engine": "^1.1"
18+
"templado/engine": "^2.0"
1919
},
2020
"autoload": {
2121
"classmap": [

composer.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Generator.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php declare(strict_types = 1);
22
namespace Templado\Cli;
33

4-
use Templado\Engine\AssetListCollection;
5-
use Templado\Engine\AssetLoader;
6-
use Templado\Engine\AssetLoaderException;
4+
use Templado\Engine\SnippetListCollection;
5+
use Templado\Engine\SnippetLoader;
6+
use Templado\Engine\SnippetLoaderException;
77
use Templado\Engine\FileName;
88
use Templado\Engine\Templado;
99

@@ -17,7 +17,7 @@ class Generator {
1717
/**
1818
* @var Directory
1919
*/
20-
private $assetsDirectory;
20+
private $snippetsDirectory;
2121

2222
/**
2323
* @var Directory
@@ -37,14 +37,14 @@ class Generator {
3737
public function __construct(GeneratorConfig $config, Logger $logger) {
3838

3939
$this->srcDirectory = $config->getSourceDirectory();
40-
$this->assetsDirectory = $config->getAssetDirectory();
40+
$this->snippetsDirectory = $config->getSnippetDirectory();
4141
$this->targetDirectory = $config->getTargetDirectory();
4242
$this->clearFirst = $config->clearFirst();
4343
$this->logger = $logger;
4444
}
4545

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

4949
if ($this->clearFirst) {
5050
$this->logger->log(
@@ -62,47 +62,47 @@ public function run(): int {
6262
if (!$src->isFile()) {
6363
continue;
6464
}
65-
$this->processFile($src, $assets);
65+
$this->processFile($src, $snippets);
6666
}
6767

6868
return Runner::RC_OK;
6969
}
7070

71-
private function loadAssets(): AssetListCollection {
72-
$assets = new AssetListCollection();
73-
$loader = new AssetLoader();
71+
private function loadSnippets(): SnippetListCollection {
72+
$snippets = new SnippetListCollection();
73+
$loader = new SnippetLoader();
7474

7575
$this->logger->log(
76-
sprintf('Loading assets from directory "%s"', $this->assetsDirectory->asString())
76+
sprintf('Loading snippets from directory "%s"', $this->snippetsDirectory->asString())
7777
);
78-
foreach($this->assetsDirectory as $file) {
78+
foreach($this->snippetsDirectory as $file) {
7979
/** @var \SplFileInfo $file */
8080
if (!$file->isFile()) {
8181
continue;
8282
}
8383

8484
try {
85-
$assets->addAsset($loader->load(new FileName($file->getRealPath())));
85+
$snippets->addSnippet($loader->load(new FileName($file->getRealPath())));
8686
$this->logger->log(
8787
sprintf('🗸 %s', $file->getPathname())
8888
);
89-
} catch (AssetLoaderException $e) {
89+
} catch (SnippetLoaderException $e) {
9090
$this->logger->log(
9191
sprintf('🗴 %s: %s', $file->getPathname(), $e->getMessage())
9292
);
9393
}
9494
}
9595

96-
return $assets;
96+
return $snippets;
9797
}
9898

9999
/**
100100
* @param \SplFileInfo $src
101-
* @param AssetListCollection $assets
101+
* @param SnippetListCollection $snippets
102102
*/
103-
private function processFile(\SplFileInfo $src, AssetListCollection $assets) {
104-
$page = Templado::loadFile(new FileName($src->getPathname()));
105-
$page->applyAssets($assets);
103+
private function processFile(\SplFileInfo $src, SnippetListCollection $snippets) {
104+
$page = Templado::loadHtmlFile(new FileName($src->getPathname()));
105+
$page->applySnippets($snippets);
106106
$target = $this->targetPath($src);
107107
@mkdir(dirname($target), 0777, true);
108108
file_put_contents($target, $page->asString());

src/GeneratorConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public function getSourceDirectory(): Directory {
1616
return $this->request->getSourceDirectory();
1717
}
1818

19-
public function getAssetDirectory(): Directory {
20-
return $this->request->getAssetDirectory();
19+
public function getSnippetDirectory(): Directory {
20+
return $this->request->getSnippetDirectory();
2121
}
2222

2323
public function getTargetDirectory(): Directory {

src/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getSourceDirectory(): Directory {
5353
return new Directory($this->arguments[0]);
5454
}
5555

56-
public function getAssetDirectory(): Directory {
56+
public function getSnippetDirectory(): Directory {
5757
$this->parse();
5858

5959
return new Directory($this->arguments[1]);

src/help.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Usage: templado [options] <src> <assets> <target>
1+
Usage: templado [options] <src> <snippets> <target>
22

33
<src> Directory containing HTML files
4-
<assets> Directory containing assets to be applied on HTML files found in <src>
4+
<snippets> Directory containing snippets to be applied on HTML files found in <src>
55

66
<target> Output directory for the result
77

0 commit comments

Comments
 (0)