From d9fa1058b27f3aa3d977a4f009213655c257f5d2 Mon Sep 17 00:00:00 2001 From: Oliver Etchebarne Date: Fri, 14 Jan 2022 02:46:59 -0500 Subject: [PATCH] Change default resource name source, and use relative path if necesary --- src/View.php | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/View.php b/src/View.php index d473892..193ab57 100644 --- a/src/View.php +++ b/src/View.php @@ -12,8 +12,11 @@ */ class View { + /** Source name for default resources */ + private $source = null; + /** View source file */ - private $view; + private $view = null; /** Processed view file name */ private $view_file = null; @@ -37,16 +40,28 @@ public function __construct( } /** - * Sets a source file + * Sets a source file for all resources. + * + * This method will always overwrite the view source. + */ + public function setSource($source): self + { + $this->source = $source; + $this->view = $source; + return $this; + } + + /** + * Sets a view file source */ - public function setSource($file): self + public function setView($file): self { $this->view = $file; return $this; } /** - * Sets a layout file + * Sets a layout file source */ public function setLayout($file) { @@ -101,26 +116,28 @@ public function render(): string ); // Si hay un CSS con el mismo nombre del método, lo añadimos - if ($this->project->method) { + if ($this->source) { $found = $this->resource_locator->find( - $this->project->method, + $this->source, type: 'css', ext: ['css', 'scss'], + return_relative_resource_name: true, ); if ($found) { - $html->addCss($this->project->method); + $html->addCss($found); } // Si hay un JS con el mismo nombre del método, lo añadimos $found = $this->resource_locator->find( - $this->project->method, + $this->source, type: 'js', ext: ['js'], + return_relative_resource_name: true, ); if ($found) { - $html->addJs($this->project->method); + $html->addJs($found); } }