Skip to content

Commit

Permalink
initial class names support!
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafał Pośpiech committed Mar 8, 2019
1 parent 13a086c commit 0f7535b
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 121 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"phenx/php-font-lib": "^0.5.1",
"guzzlehttp/guzzle": "^6.3",
"composer/ca-bundle": "^1.1",
"milon/barcode": "^5.3"
"milon/barcode": "^5.3",
"sabberworm/php-css-parser": "^8.3"
},
"autoload": {
"psr-4": {
Expand Down
58 changes: 55 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions lib/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ class Document
* @var array
*/
protected $ordCache = [];
/**
* Css selectors like classes ids.
*
* @var array
*/
protected $cssSelectors = [];

/**
* Are we debugging?
Expand Down Expand Up @@ -877,4 +883,51 @@ public function render(): string

return $this->buffer;
}

/**
* Get css selector rules.
*
* @param string $selector
*
* @return array
*/
public function getCssSelectorRules(string $selector)
{
$rules = [];
foreach(explode(' ',$selector) as $className){
if ($className && isset($this->cssSelectors[$className])) {
$rules = array_merge($rules,$this->cssSelectors[$className]);
}
}

return $rules;
}

/**
* Get css selectors.
*
* @return array
*/
public function getCssSelectors()
{
return $this->cssSelectors;
}

/**
* Add css selector rules.
*
* @param string $selector .className or #id
* @param array $rules
*
* @return $this
*/
public function addCssSelectorRules(string $selector, array $rules): self
{
if (isset($this->cssSelectors[$selector])) {
$this->cssSelectors[$selector] = array_merge($this->cssSelectors[$selector], $rules);
} else {
$this->cssSelectors[$selector] = $rules;
}
return $this;
}
}
30 changes: 30 additions & 0 deletions lib/Html/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class Element extends \YetiForcePDF\Base
* @var \DOMElement
*/
protected $domElement;
/**
* Class names for element
*
* @var string
*/
protected $classNames = '';

/**
* Initialisation.
Expand Down Expand Up @@ -170,4 +176,28 @@ public function isTextNode()
}
return false;
}

/**
* Set class names for element
*
* @param string $classNames Class names for element
*
* @return self
*/
public function setClassNames(string $classNames)
{
$this->classNames = $classNames;

return $this;
}

/**
* Get class names for element
*
* @return string[]
*/
public function getClassNames()
{
return $this->classNames;
}
}
Loading

0 comments on commit 0f7535b

Please sign in to comment.