Skip to content

Commit

Permalink
feat: add dom() method
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed May 10, 2023
1 parent a705851 commit a564290
Show file tree
Hide file tree
Showing 3 changed files with 485 additions and 26 deletions.
23 changes: 23 additions & 0 deletions RockFrontend.module.php
Expand Up @@ -17,6 +17,7 @@
use Sabberworm\CSS\Rule\Rule;
use Sabberworm\CSS\RuleSet\AtRuleSet;
use Sabberworm\CSS\RuleSet\RuleSet;
use Wa72\HtmlPageDom\HtmlPageCrawler;

/**
* @author Bernhard Baumrock, 05.01.2022
Expand Down Expand Up @@ -597,6 +598,28 @@ private function createPermission($name, $title)
$p->setAndSave('title', $title);
}

/**
* Load HtmlPageDom
*
* If you have plain HTML like from TinyMCE field some methods will not work
* because they need a hierarchy with a single root element. That's why by
* default the dom() method will add a wrapping div unless you specify
* FALSE as second param.
*
* Usage:
* $rockfrontend->dom("your html string")
* ->filter("img")
* ->each(function($img) {
* $img->attr('src', '/foo/bar.png');
* });
*/
public function dom($data, $addWrapperDiv = true): HtmlPageCrawler
{
require_once __DIR__ . "/vendor/autoload.php";
if ($addWrapperDiv) $data = "<div>$data</div>";
return HtmlPageCrawler::create($data);
}

/**
* Download uikit
* @return void
Expand Down
11 changes: 6 additions & 5 deletions composer.json
@@ -1,7 +1,8 @@
{
"require": {
"latte/latte": "^3.0",
"sabberworm/php-css-parser": "^8.4",
"matthiasmullie/minify": "^1.3"
}
"require": {
"latte/latte": "^3",
"sabberworm/php-css-parser": "^8.4",
"matthiasmullie/minify": "^1.3",
"wa72/htmlpagedom": "^3.0"
}
}

0 comments on commit a564290

Please sign in to comment.