Skip to content

Commit eb3c716

Browse files
committed
Added shortcodes() helper
1 parent 574e740 commit eb3c716

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"sempro/phpunit-pretty-print": "^1.0"
2525
},
2626
"autoload": {
27+
"files": [
28+
"src/helpers.php"
29+
],
2730
"psr-4": {
2831
"Vedmant\\LaravelShortcodes\\": "src/"
2932
}

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ Or
124124
@shortcodes('[b]bold[/b]')
125125
```
126126

127+
#### Render shortcodes with `shortcodes()` helper
128+
129+
```blade
130+
<div class="some-block">
131+
{{ shortcodes('[b]bold[/b]') }}
132+
</div>
133+
```
127134

128135
### Shared attributes
129136

@@ -182,9 +189,8 @@ $ vendor/bin/phpunit
182189

183190
## TODO
184191

185-
1. shortcodes() helper
186-
1. Add Debugbar integration tests
187192
1. Shortcodes help data generator
193+
1. Add Debugbar integration tests
188194
1. Casting attributes (int, bool, array (comma separated))
189195
1. Add basic bootstrap shortcodes set
190196
1. Add commands to generate a shortcode view, generate view by default with make:shortcode

src/helpers.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use Illuminate\Support\HtmlString;
4+
5+
if (! function_exists('shortcodes')) {
6+
7+
/**
8+
* Render shortcodes
9+
*
10+
* @param string $string
11+
* @return string|HtmlString
12+
*/
13+
function shortcodes($string)
14+
{
15+
return app('shortcodes')->render($string);
16+
}
17+
}

tests/Unit/HelpersTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Vedmant\LaravelShortcodes\Tests\Unit;
4+
5+
use Vedmant\LaravelShortcodes\Tests\Resources\BShortcode;
6+
use Vedmant\LaravelShortcodes\Tests\TestCase;
7+
8+
class HelpersTest extends TestCase
9+
{
10+
public function testFunction()
11+
{
12+
$this->assertTrue(function_exists('shortcodes'));
13+
}
14+
15+
public function testRenderWithHelper()
16+
{
17+
$this->manager->add('b', BShortcode::class);
18+
19+
$rendered = \shortcodes('[b class="test"]Content[/b]');
20+
$this->assertEquals("<b class=\"test\">Content</b>", (string) $rendered);
21+
}
22+
}

0 commit comments

Comments
 (0)