File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,17 @@ Enable it globally:
1313\Phug\Component\ComponentExtension::enable();
1414```
1515
16+ To enable it automatically when calling static methods ` render ` , ` renderFile ` ,
17+ ` display ` , ` displayFile ` etc. on either ` \Pug\Facade ` or ` \Phug\Phug ` class.
18+
19+ If using in a ` \Pug\Pug ` or ` \Phug\Renderer ` instance, add the ` ComponentExtension `
20+ class to modules:
21+ ``` php
22+ $pug = new \Pug\Pug([
23+ 'modules' => [\Phug\Component\ComponentExtension::class],
24+ ]);
25+ ```
26+
1627## Usage
1728
1829``` pug
Original file line number Diff line number Diff line change 2121 "minimum-stability" : " stable" ,
2222 "require" : {
2323 "php" : " >=7.2" ,
24- "phug/renderer " : " ^1.3"
24+ "phug/phug " : " ^1.3"
2525 },
2626 "require-dev" : {
27- "phpunit/phpunit" : " ^8"
27+ "phpunit/phpunit" : " ^8" ,
28+ "pug-php/pug" : " ^3"
2829 },
2930 "autoload" : {
3031 "psr-4" : {
Original file line number Diff line number Diff line change 33namespace Phug \Test \Component ;
44
55use PHPUnit \Framework \TestCase ;
6+ use Phug \Phug ;
67
78class ComponentExtensionTest extends TestCase
89{
10+ /**
11+ * @var string
12+ */
13+ protected $ readme = null ;
14+
15+ protected function getReadmeContents (): string
16+ {
17+ if ($ this ->readme === null ) {
18+ $ this ->readme = file_get_contents (__DIR__ . '/../../../README.md ' );
19+ }
20+
21+ return $ this ->readme ;
22+ }
23+
24+ protected function setUp (): void
25+ {
26+ preg_match (
27+ '/```php\n(?<php>[\s\S]+)\n```/U ' ,
28+ $ this ->getReadmeContents (),
29+ $ install
30+ );
31+
32+ eval ($ install ['php ' ]);
33+ }
34+
935 public function getReadmeExamples ()
1036 {
1137 preg_match_all (
1238 '/```pug\n(?<pug>[\s\S]+)\n```[\s\S]*```html\n(?<html>[\s\S]+)\n```/U ' ,
13- file_get_contents ( __DIR__ . ' /../../../README.md ' ),
39+ $ this -> getReadmeContents ( ),
1440 $ examples ,
1541 PREG_SET_ORDER
1642 );
@@ -25,6 +51,6 @@ public function getReadmeExamples()
2551 */
2652 public function testReadme ($ htmlCode , $ pugCode )
2753 {
28- $ this ->assertSame ($ htmlCode , $ pugCode );
54+ $ this ->assertSame ($ htmlCode , Phug:: render ( $ pugCode) );
2955 }
3056}
You can’t perform that action at this time.
0 commit comments