Skip to content

Commit

Permalink
#124 remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Aug 12, 2022
1 parent a8f2993 commit 72219d2
Show file tree
Hide file tree
Showing 13 changed files with 775 additions and 775 deletions.
1,427 changes: 719 additions & 708 deletions README.md

Large diffs are not rendered by default.

43 changes: 27 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,53 +624,64 @@ echo $renderer->render($parser->parse());
the command line utility is located at './cli/css-parser'

```bash

$ ./cli/css-parser -h

Usage:
$ css-parser [OPTIONS] [PARAMETERS]

-v, --version print version number
-h print help
--help print extended help

parse options:
Parse options:

-e, --capture-errors ignore parse error

-f, --file css file or url
-f, --file input css file or url

-m, --flatten-import process @import

-I, --input-format input format: json (ast), serialize (PHP serialized ast)

-d, --parse-allow-duplicate-declarations allow duplicate declaration

-p, --parse-allow-duplicate-rules allow duplicate rule

render options:
-P, --parse-children-process maximum children process

-M, --parse-multi-processing enable multi-processing parser

Render options:

-a, --ast dump ast as JSON

-S, --charset remove @charset

-a, --ast dump ast as JSON
-c, --compress minify output

-S, --charset remove @charset
-u, --compute-shorthand compute shorthand properties

-c, --compress minify output
-t, --convert-color convert colors

-u, --compute-shorthand compute shorthand properties
-l, --css-level css color module

-l, --css-level css color module
-G, --legacy-rendering convert nested css syntax

-G, --legacy-rendering legacy rendering
-o, --output output file name

-o, --output output file name
-F, --output-format output export format. string (css), json (ast), serialize (PHP serialized ast), json-array, serialize-array, requires --input-format

-L, --preserve-license preserve license comments
-L, --preserve-license preserve license comments

-C, --remove-comments remove comments
-C, --remove-comments remove comments

-E, --remove-empty-nodes remove empty nodes
-E, --remove-empty-nodes remove empty nodes

-r, --render-duplicate-declarations render duplicate declarations
-r, --render-allow-duplicate-declarations render duplicate declarations

-s, --sourcemap generate sourcemap, require -o
-R, --render-multi-processing enable multi-processing renderer

-s, --sourcemap generate sourcemap, requires --file
```

### Minify inline css
Expand Down
5 changes: 3 additions & 2 deletions src/Element/AtRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ public function isLeaf () {
* test if this at-rule node contains declaration
* @return bool
*/
public function hasDeclarations () {
public function hasDeclarations (): bool
{

return !empty($this->ast->hasDeclarations);
}

/**
* @inheritDoc
*/
public function support (ElementInterface $child) {
public function support (ElementInterface $child): bool {

if (!empty($this->ast->isLeaf)) {

Expand Down
41 changes: 12 additions & 29 deletions src/Element/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@ protected function parseSelector($selectors)
$selectors = Value::parse($selectors, null, true, '', '');
}

// $comments = [];
// $k = count($selectors);

// while ($k--) {
//
// if ($selectors[$k]->type == 'Comment') {
//
// $comments[] = $selectors[$k]->value;
// array_splice($selectors, $k, 1);
// }
// }
//
// if (!empty($comments)) {
//
// $this->setLeadingComments(array_reverse($comments));
// }

$selectors = Value::split(Value::renderTokens($selectors, ['omit_unit' => false]), ',');

$result = [];
Expand All @@ -67,8 +50,8 @@ protected function parseSelector($selectors)
* @param string|array $selectors
* @return $this
*/
public function setSelector($selectors)
{
public function setSelector($selectors): static
{

$this->ast->selector = $this->parseSelector($selectors);
return $this;
Expand All @@ -79,8 +62,8 @@ public function setSelector($selectors)
* @param array|string $selector
* @return $this
*/
public function addSelector($selector)
{
public function addSelector($selector): static
{

$result = [];

Expand All @@ -104,8 +87,8 @@ public function addSelector($selector)
* @return Rule
* @throws Exception
*/
public function removeSelector($selector)
{
public function removeSelector($selector): static
{

if (!is_array($selector)) {

Expand All @@ -131,8 +114,8 @@ public function removeSelector($selector)
* @return Declaration
* @throws Exception
*/
public function addDeclaration($name, $value)
{
public function addDeclaration(string $name, string $value): Declaration
{

$declaration = new Declaration();

Expand All @@ -148,8 +131,8 @@ public function addDeclaration($name, $value)
* @return Rule $this
* @throws Exception
*/
public function merge(Rule $rule)
{
public function merge(Rule $rule): static
{

$this->addSelector($rule->getSelector());

Expand All @@ -164,8 +147,8 @@ public function merge(Rule $rule)
/**
* @inheritDoc
*/
public function support(ElementInterface $child)
{
public function support(ElementInterface $child): bool
{

if ($child instanceof Comment) {

Expand Down
2 changes: 1 addition & 1 deletion src/Element/RuleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function setChildren(array $elements) {
/**
* @inheritDoc
*/
public function support(ElementInterface $child)
public function support(ElementInterface $child): bool
{

$element = $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/RuleListInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function addComment($value);
* @param ElementInterface $child
* @return bool
*/
public function support(ElementInterface $child);
public function support(ElementInterface $child): bool;

/**
* append child nodes
Expand Down
18 changes: 6 additions & 12 deletions src/Value/LineHeight.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class LineHeight extends Value

protected static array $defaults = ['normal'];

/**
* @inheritDoc
*/
/**
* @inheritDoc
* @throws Exception
*/
public static function matchToken($token, $previousToken = null, $previousValue = null, $nextToken = null, $nextValue = null, int $index = null, array $tokens = []): bool
{

Expand Down Expand Up @@ -61,10 +62,8 @@ public function render(array $options = []): string
return static::doRender($this->data, $options);
}

public static function doRender(object $data, array $options = [])
{
// $prefix = func_num_args() > 1 && func_get_arg(1) == 'font' ? '/ ' : '';

public static function doRender(object $data, array $options = []): string
{
$value = $data->value;

if ($value == '0') {
Expand All @@ -74,11 +73,6 @@ public static function doRender(object $data, array $options = [])

if (!empty($options['compress'])) {

// if ($prefix !== '') {
//
// $prefix = '/';
// }

if(is_numeric($value)) {

$value = Number::compress($value);
Expand Down
2 changes: 1 addition & 1 deletion test/sourcemap/generated/nested.test.css.map

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

2 changes: 1 addition & 1 deletion test/sourcemap/generated/nested.test.min.css.map

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

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

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

2 changes: 1 addition & 1 deletion test/sourcemap/generated/sourcemap.generated.test.css.map

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

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

0 comments on commit 72219d2

Please sign in to comment.