Skip to content

Commit

Permalink
Record filters in the current renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Jul 25, 2017
1 parent 857e304 commit 3c6e481
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"minimum-stability": "stable",
"require": {
"php": ">=5.5.0",
"phug/renderer": "^0.1.0"
"phug/renderer": "^0.2.0"
},
"require-dev": {
"phug/dev-tool": "^0.1.0"
Expand Down
18 changes: 17 additions & 1 deletion src/Phug/Phug.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ private static function normalizeExtensionClassName($name)
return ltrim('\\', strtolower($name));
}

/**
* Reset all static options, filters and extensions.
*/
public static function reset()
{
static::$renderer = null;
static::$extensions = [];
static::$filters = [];
}

/**
* Get a renderer with global options and argument options merged.
*
Expand Down Expand Up @@ -93,7 +103,7 @@ public static function display($input, array $parameters = [], array $options =
*/
public static function displayFile($path, array $parameters = [], array $options = [])
{
return static::getRenderer($options)->display($path, $parameters);
return static::getRenderer($options)->displayFile($path, $parameters);
}

/**
Expand Down Expand Up @@ -126,6 +136,12 @@ class_exists($filter) ||
}

self::$filters[$name] = $filter;

if (static::$renderer) {
static::$renderer->setOptionsRecursive([
'filters' => self::$filters,
]);
}
}

/**
Expand Down
10 changes: 7 additions & 3 deletions tests/Phug/PhugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function testRender()
/**
* @covers ::display
*/
public function testDisplay()
public function testDisplayFile()
{
ob_start();
Phug::display(__DIR__.'/../templates/test.pug');
Phug::displayFile(__DIR__.'/../templates/test.pug');
$actual = ob_get_contents();
ob_end_clean();

Expand All @@ -51,7 +51,7 @@ public function testDisplay()
/**
* @covers ::display
*/
public function testDisplayString()
public function testDisplay()
{
ob_start();
Phug::display('section: div');
Expand All @@ -65,6 +65,7 @@ public function testDisplayString()
}

/**
* @covers ::reset
* @covers ::normalizeFilterName
* @covers ::hasFilter
* @covers ::addFilter
Expand All @@ -83,6 +84,9 @@ public function testFilters()
'WORD',
Phug::render(':upper word')
);
Phug::reset();
self::assertFalse(Phug::hasFilter('upper'));
self::assertFalse(Phug::hasFilter('up-per'));
}

/**
Expand Down

0 comments on commit 3c6e481

Please sign in to comment.