Skip to content

Commit

Permalink
[1.x] Add a new @featureany directive (#122)
Browse files Browse the repository at this point in the history
* Blade: Add new featureany directive

* Tests/Blade: Add tests for new featureany directive
  • Loading branch information
ryangjchandler authored Sep 30, 2024
1 parent 9d8c003 commit 7d66966
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/PennantServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function boot()

return Feature::active($feature);
});

$blade->if('featureany', function ($features) {
return Feature::someAreActive($features);
});
});

$this->listenForEvents();
Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/FeatureDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,27 @@ public function test_it_checks_features_against_default_scope_by_default()
$output = trim(Blade::render($blade));
$this->assertSame('foo is 888', $output);
}

public function test_it_renders_any_active_features()
{
$blade = <<<'BLADE'
@featureany(['foo', 'bar'])
foo or bar is active
@else
foo and bar are inactive
@endfeatureany
BLADE;

$output = trim(Blade::render($blade));
$this->assertSame('foo and bar are inactive', $output);

Feature::activate('foo');
$output = trim(Blade::render($blade));
$this->assertSame('foo or bar is active', $output);

Feature::deactivate('foo');
Feature::activate('bar');
$output = trim(Blade::render($blade));
$this->assertSame('foo or bar is active', $output);
}
}

0 comments on commit 7d66966

Please sign in to comment.