11<?php declare (strict_types = 1 );
22namespace 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 ;
77use Templado \Engine \FileName ;
88use 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 ());
0 commit comments