Skip to content

Commit

Permalink
#94 documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Dec 16, 2021
1 parent 60eb078 commit cdc66e2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ echo $renderer->render($parser->parse());
- flatten_import: process @import directive and import the content into the css. default to false.
- allow_duplicate_rules: allow duplicated rules. By default duplicate rules except @font-face are merged
- allow_duplicate_declarations: allow duplicated declarations in the same rule.
- capture_errors: if false, throw an exception on parse error. Otherwise, use getErrors() method to retrieve the error details. default to true

## Renderer Options

Expand Down
14 changes: 11 additions & 3 deletions docs/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,23 @@ h1 {

### flatten_import

_boolean_. Default _['@font-face']_. Replace the @import directive with actual content
_boolean_. Default _false_. Replace the @import directive with target stylesheet content

### allow_duplicate_rules

_boolean_. Default _false_. allow duplicate rules or merge them into one rule
_boolean_|_string_|_array_. Default _['font-face']_. Allow duplicate @font-face rules by default.

- if specified as array, then allow duplicate rules that are specified in that array
- if true allow any duplicate rule.
- Otherwise, merge all duplicates into a single rule

### allow_duplicate_declarations

_boolean_|_string_|_array_. Default _['font-face']_. Remove duplicate declarations under the same rule. If you want to preserve multiple declarations for some properties, you can specify them as a string or an array.
_boolean_|_string_|_array_. Default _false_. Remove duplicate declarations under the same rule. If you want to preserve multiple declarations for some properties, you can specify them as a string or an array.

### capture_errors

_boolean_: Default _true_. if false, throw an exception on parse error. Otherwise, use getErrors() method to retrieve the error details. default to true

## Parser Methods

Expand Down
27 changes: 23 additions & 4 deletions src/TBela/CSS/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,33 @@ public function setOptions(array $options)

if (isset($options[$key])) {

$this->options[$key] = $options[$key];

if ($key == 'allow_duplicate_declarations') {

if (is_string($this->options[$key])) {

$this->options[$key] = [$this->options[$key]];
} else if (is_array($this->options[$key])) {
}

if (is_array($this->options[$key])) {

$this->options[$key] = array_flip($this->options[$key]);
}
}

else if ($key == 'allow_duplicate_rules' && is_string($v)) {

$this->options[$key] = [$v];
}

else {

$this->options[$key] = $options[$key];
}

if ($key == 'allow_duplicate_rules' && is_array($this->options[$key]) && !in_array('font-face', $this->options[$key])) {

$this->options[$key][] = 'font-face';
}
}
}

Expand Down Expand Up @@ -421,7 +436,11 @@ protected function deduplicateDeclarations($ast)

if (isset($hash[$signature])) {

$declaration->parent = null;
if (isset($declaration->parent)) {

$declaration->parent = null;
}

array_splice($ast->children, $total, 1);
continue;
}
Expand Down

0 comments on commit cdc66e2

Please sign in to comment.