Skip to content

Commit

Permalink
fix asset problem
Browse files Browse the repository at this point in the history
  • Loading branch information
reziamini committed Dec 25, 2020
1 parent 54c7fed commit 7ad39bd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/Directives/ScriptDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ public static function handle($parameter)
{
$parameter = str_replace(['"', "'"], null, $parameter);
$array = explode(',', $parameter);
$secure = trim(@$array[1]) == 'true' ? true : null;
$url = asset(trim($array[0]), $secure);
$url = trim($array[0]);
$defer = trim(@$array[1]) ?? null;

$defer = trim(@$array[2]) ?? null;
if ($defer) {
return "<script src='{$url}' defer></script>";
}
Expand Down
5 changes: 1 addition & 4 deletions src/Directives/StyleDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ class StyleDirective implements Directive
public static function handle($parameter)
{
$parameter = str_replace(['"', "'"], null, $parameter);
$array = explode(',', $parameter);
$secure = trim(@$array[1]) == 'true' ? true : null;
$url = asset(trim($array[0]), $secure);

return "<link href='{$url}' rel='stylesheet'>";
return "<link href='{$parameter}' rel='stylesheet'>";
}
}
9 changes: 3 additions & 6 deletions tests/DirectivesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,13 @@ public function testImageDirective()

public function testStyleDirective()
{
$this->assertEquals("<link href='http://localhost/style.css' rel='stylesheet'>", $this->compiler->compileString("@style('style.css')"));
$this->assertEquals("<link href='https://localhost/style.css' rel='stylesheet'>", $this->compiler->compileString("@style('style.css', true)"));
$this->assertEquals("<link href='/css/style.css' rel='stylesheet'>", $this->compiler->compileString("@style('/css/style.css')"));
}

public function testScriptDirective()
{
$this->assertEquals("<script src='http://localhost/script.js' defer></script>", $this->compiler->compileString("@script('script.js', false, true)"));
$this->assertEquals("<script src='http://localhost/script.js'></script>", $this->compiler->compileString("@script('script.js')"));
$this->assertEquals("<script src='https://localhost/script.js'></script>", $this->compiler->compileString("@script('script.js', true)"));
$this->assertEquals("<script src='https://localhost/script.js' defer></script>", $this->compiler->compileString("@script('script.js', true, true)"));
$this->assertEquals("<script src='/js/script.js'></script>", $this->compiler->compileString("@script('/js/script.js')"));
$this->assertEquals("<script src='/js/script.js' defer></script>", $this->compiler->compileString("@script('/js/script.js', true)"));
}

public function testConfigDirectiveStyle()
Expand Down

0 comments on commit 7ad39bd

Please sign in to comment.