Skip to content

Commit cf54b85

Browse files
committed
removed css-to-inline in favor of css-selector
1 parent d478249 commit cf54b85

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"tijsverkoyen/css-to-inline-styles": "^2.2",
15+
"symfony/css-selector": "^2.7|~3.0",
1616
"twig/twig": "^1.26"
1717
},
1818
"autoload": {

src/CssStore.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace PageSpecificCss;
4+
5+
class CssStore
6+
{
7+
/** @var string[] */
8+
private $styles = [];
9+
10+
public function addCssStyle($cssRules)
11+
{
12+
$this->styles[] = $cssRules;
13+
}
14+
15+
public function getStyles()
16+
{
17+
return $this->styles;
18+
}
19+
20+
public function compileStyles()
21+
{
22+
return join(';', $this->styles);
23+
}
24+
25+
/**
26+
* @param string $path
27+
*
28+
* @return bool whether the dumping was successful
29+
*/
30+
public function dumpStyles($path)
31+
{
32+
return file_put_contents($path, $this->compileStyles()) === false;
33+
}
34+
35+
36+
}

src/PageSpecificCss.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,44 @@
33
namespace PageSpecificCss;
44

55
use TijsVerkoyen\CssToInlineStyles\Css\Processor;
6+
use TijsVerkoyen\CssToInlineStyles\Css\Rule\Rule;
67
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
78

89
class PageSpecificCss extends CssToInlineStyles
910
{
1011

11-
public function extractCss($page)
12+
/**
13+
* @var CssStore
14+
*/
15+
private $cssStore;
16+
17+
/**
18+
* PageSpecificCss constructor.
19+
*/
20+
public function __construct()
21+
{
22+
parent::__construct();
23+
24+
$this->cssStore = new CssStore();
25+
26+
}
27+
28+
/**
29+
* @param string $html the raw html
30+
*/
31+
public function processHtmlToStore($html)
32+
{
33+
$this->cssStore->addCssStyle($this->extractCss($html));
34+
}
35+
36+
/**
37+
* @param $html
38+
*
39+
* @return string
40+
*/
41+
public function extractCss($html)
1242
{
13-
$processor = new Processor();
14-
return $processor->getRules($processor->getCssFromStyleTags($page));
43+
// Do something..
44+
return '';
1545
}
1646
}

0 commit comments

Comments
 (0)