Skip to content

Commit

Permalink
Allow adding an array of Shortcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
JayBizzle committed Jan 12, 2019
1 parent 9e8da78 commit ca986a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ class Shortcodes
/**
* Add shortcode hooks.
*
* @param string $tag
* @param string $class
* @param array|string $classes
*/
public function add($class)
public function add($classes)
{
$this->shortcodeTags[$class::$shortcode] = $class;
if (! is_array($classes)) {
$classes = [$classes];
}

foreach ($classes as $class) {
$this->shortcodeTags[$class::$shortcode] = $class;
}
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ public function no_tags_added()
);
}

/** @test */
public function we_can_add_a_single_shortcode()
{
$this->shortcodes->add(FooShortcode::class);

$this->assertCount(1, $this->shortcodes->shortcodeTags);
}

/** @test */
public function we_can_add_multiple_shorcodes()
{
$this->shortcodes->add([
FooShortcode::class,
BarShortcode::class,
]);

$this->assertCount(2, $this->shortcodes->shortcodeTags);
}

/** @test */
public function tags_with_closing_slash()
{
Expand Down

0 comments on commit ca986a8

Please sign in to comment.