Skip to content

Commit

Permalink
Change default resource name source, and use relative path if necesary
Browse files Browse the repository at this point in the history
  • Loading branch information
drmad committed Jan 14, 2022
1 parent 4493b2c commit d9fa105
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit d9fa105

Please sign in to comment.