Skip to content

Commit

Permalink
feat: add svgDom() method
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Mar 11, 2024
1 parent c8c8ab7 commit afdef7e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use HumanDates;
use Latte\Engine;
use Latte\Runtime\Html;
use LogicException;
use RockFrontend\Asset;
use RockFrontend\LiveReload;
use RockFrontend\Manifest;
Expand Down Expand Up @@ -2223,6 +2224,27 @@ public function svg($filename, $replacements = [])
return $this->html($svg);
}

/**
* Load svg as DOM element
*
* Usage:
* echo $rf->svgDom("/path/to/file.svg")->addClass("foo");
*
* @param mixed $data
* @return HtmlPageCrawler
* @throws LogicException
*/
public function svgDom($data): HtmlPageCrawler
{
$str = $data;
if ($data instanceof Pagefiles) $data = $data->first();
if ($data instanceof Pagefile) {
$str = file_get_contents($data->filename);
}
$dom = $this->dom($str)->filter("svg")->first();
return $dom;
}

/**
* Update /site/templates/.htaccess file to block direct access
* to latte/twig/blade/less files
Expand Down

0 comments on commit afdef7e

Please sign in to comment.