diff --git a/compile.php b/compile.php index 991c58f..9436bff 100644 --- a/compile.php +++ b/compile.php @@ -1,27 +1,94 @@ dictionary = new BlogEngine\Dictionary(); - $src = __DIR__ . "/src/"; - $html = scandir($src . "views"); - $css = scandir($src . "css"); - $js = scandir($src . "js"); + // POBIERANIE ZAWARTOŚCI FOLDERU src + $this->src = __DIR__ . "/src/"; + $this->htmls = scandir($src . "views"); + $this->csss = scandir($src . "css"); + $this->jss = scandir($src . "js"); - for($i = 2; $i < count($html); $i++){ - $site = file_get_contents($src . "views/" . $html[$i]); - foreach (array_keys($dictionary->page_tags) as $page_tag){ - if($page_tag = "{CSS}"){ - for($j = 2; $j < count($css); $j++) - $dictionary->page_tags[$page_tag] .= ""; + //$this->version = + } + + public function main() : void{ + $this->checkFolders(); + $this->compileFiles(); + + echo "Done"; + } + + /* + * SPRAWDZANIE CZY SĄ FOLDERY css I js + */ + function checkFolders() : void{ + if(!file_exists("public/css")) + mkdir("public/css"); + + if(!file_exists("public/js")) + mkdir("public/js"); + } + + function compileFiles() : void{ + // KOPIOWANIE PLIKÓW HTML DO PUBLICZNEGO FOLDERU + foreach ($this->htmls as $html) { + $file = $this->src . "views/" . $html; + if(pathinfo($file, PATHINFO_EXTENSION) == "html") { + $name = basename($file); + $site = file_get_contents($file); + foreach (array_keys($this->dictionary->page_tags) as $page_tag) { + echo $page_tag; + if ($page_tag == "{CSS}") { + $this->dictionary->page_tags[$page_tag] .= ""; + for ($j = 2; $j < count($this->csss); $j++) + $this->dictionary->page_tags[$page_tag] .= "\n "; + } + + if ($page_tag == "{JS}") { + $this->dictionary->page_tags[$page_tag] .= ""; + for ($j = 2; $j < count($this->jss); $j++) + $this->dictionary->page_tags[$page_tag] .= "\n "; + } + + $site = str_replace($page_tag, $this->dictionary->page_tags[$page_tag], $site); } - if($page_tag = "{JS}"){ - for($j = 2; $j < count($js); $j++) - $dictionary->page_tags[$page_tag] .= ""; - } - - $site = str_replace($page_tag, $dictionary->page_tags[$page_tag], $site); + $site_file = fopen("public/" . $name, "w"); + fwrite($site_file, $site); + fclose($site_file); } + } - echo $site; - } \ No newline at end of file + // PRZENOSZENIE PLIKÓW CSS DO PUBLICZNEGO FOLDERU + foreach ($this->csss as $css){ + $file = $this->src . "css/" . $css; + if(pathinfo($file, PATHINFO_EXTENSION) == "css" || pathinfo($file, PATHINFO_EXTENSION) == "scss"){ + $name = basename($file);; + $style = file_get_contents($file); + + $style_file = fopen("public/css/" . $name, "w"); + fwrite($style_file, $style); + fclose($style_file); + } + } + + // PRZENOSZENIE PLIKÓW JS DO PUBLICZNEGO FOLDERU + foreach ($this->jss as $js){ + $file = $this->src . "js/" . $js; + if(pathinfo($file, PATHINFO_EXTENSION) == "js"){ + $name = basename($file); + $script = file_get_contents($file); + + $script_file = fopen("public/js/" . $name, "w"); + fwrite($script_file, $script); + fclose($script_file); + } + } + } + } + + $exec = new CompileIt(); + $exec->main(); \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..e69de29 diff --git a/public/index.html b/public/index.html index 6671ec0..b1baeda 100644 --- a/public/index.html +++ b/public/index.html @@ -1,13 +1,18 @@ - - -
- -sdf
+ + + \ No newline at end of file diff --git a/public/js/script.js b/public/js/script.js new file mode 100644 index 0000000..e69de29 diff --git a/src/views/index.html b/src/views/index.html index 52ef941..35cc510 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -4,11 +4,13 @@{DESCRIPTION}
+ {JS}