Skip to content

Commit

Permalink
Added shortcodes() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
vedmant committed May 5, 2019
1 parent 574e740 commit eb3c716
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"sempro/phpunit-pretty-print": "^1.0"
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Vedmant\\LaravelShortcodes\\": "src/"
}
Expand Down
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ Or
@shortcodes('[b]bold[/b]')
```

#### Render shortcodes with `shortcodes()` helper

```blade
<div class="some-block">
{{ shortcodes('[b]bold[/b]') }}
</div>
```

### Shared attributes

Expand Down Expand Up @@ -182,9 +189,8 @@ $ vendor/bin/phpunit

## TODO

1. shortcodes() helper
1. Add Debugbar integration tests
1. Shortcodes help data generator
1. Add Debugbar integration tests
1. Casting attributes (int, bool, array (comma separated))
1. Add basic bootstrap shortcodes set
1. Add commands to generate a shortcode view, generate view by default with make:shortcode
Expand Down
17 changes: 17 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Illuminate\Support\HtmlString;

if (! function_exists('shortcodes')) {

/**
* Render shortcodes
*
* @param string $string
* @return string|HtmlString
*/
function shortcodes($string)
{
return app('shortcodes')->render($string);
}
}
22 changes: 22 additions & 0 deletions tests/Unit/HelpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Vedmant\LaravelShortcodes\Tests\Unit;

use Vedmant\LaravelShortcodes\Tests\Resources\BShortcode;
use Vedmant\LaravelShortcodes\Tests\TestCase;

class HelpersTest extends TestCase
{
public function testFunction()
{
$this->assertTrue(function_exists('shortcodes'));
}

public function testRenderWithHelper()
{
$this->manager->add('b', BShortcode::class);

$rendered = \shortcodes('[b class="test"]Content[/b]');
$this->assertEquals("<b class=\"test\">Content</b>", (string) $rendered);
}
}

0 comments on commit eb3c716

Please sign in to comment.