File tree Expand file tree Collapse file tree 9 files changed +45
-32
lines changed
Expand file tree Collapse file tree 9 files changed +45
-32
lines changed Original file line number Diff line number Diff line change 33namespace LaravelViews \Actions ;
44
55use LaravelViews \Views \View ;
6+ use Illuminate \Support \Str ;
67
78abstract class Action
89{
@@ -35,12 +36,7 @@ public function isRedirect()
3536
3637 public function getId ()
3738 {
38- return $ this ->camelToDashCase ((new \ReflectionClass ($ this ))->getShortName ());
39- }
40-
41- private function camelToDashCase ($ camelStr )
42- {
43- return strtolower (preg_replace ('%([a-z])([A-Z])% ' , '\1-\2 ' , $ camelStr ));
39+ return Str::camelToDash ((new \ReflectionClass ($ this ))->getShortName ());
4440 }
4541
4642 public function renderIf ($ item , View $ view )
Original file line number Diff line number Diff line change 44
55trait Confirmable
66{
7- public function getConfirmationMessage ($ item = null )
7+ /**
8+ * Model instance who fired the action, it is null if it
9+ * was a bulk action
10+ */
11+ public function getConfirmationMessage ($ model = null )
812 {
913 return __ ('Do you really want to perform this action? ' );
1014 }
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ public function getBulkActionsProperty()
8686 private function confirmAction ($ action , $ modelId = null )
8787 {
8888 $ actionData = [
89- 'message ' => $ action ->getConfirmationMessage (),
89+ 'message ' => $ action ->getConfirmationMessage ($ modelId ? $ this -> getModelWhoFiredAction ( $ modelId ) : null ),
9090 'id ' => $ action ->getId ()
9191 ];
9292
Original file line number Diff line number Diff line change 22
33namespace LaravelViews \Filters ;
44
5- use LaravelViews \Views \View ;
6- use Illuminate \Http \Request ;
5+ use Illuminate \Support \Str ;
76
87class BaseFilter
98{
@@ -52,28 +51,15 @@ public function value()
5251 public function getTitle ()
5352 {
5453 if (!$ this ->title ) {
55- return $ this -> camelToTitle ((new \ReflectionClass ($ this ))->getShortName ());
54+ return Str:: classNameAsSentence ((new \ReflectionClass ($ this ))->getShortName ());
5655 }
5756
5857 return $ this ->title ;
5958 }
6059
6160 public function getId ()
6261 {
63- return $ this ->camelToDashCase ((new \ReflectionClass ($ this ))->getShortName ());
64- }
65-
66- private function camelToTitle ($ camelStr )
67- {
68- $ intermediate = preg_replace ('/(?!^)([[:upper:]][[:lower:]]+)/ ' , ' $0 ' , $ camelStr );
69- $ titleStr = preg_replace ('/(?!^)([[:lower:]])([[:upper:]])/ ' , '$1 $2 ' , $ intermediate );
70-
71- return $ titleStr ;
72- }
73-
74- private function camelToDashCase ($ camelStr )
75- {
76- return strtolower (preg_replace ('%([a-z])([A-Z])% ' , '\1-\2 ' , $ camelStr ));
62+ return Str::camelToDash ((new \ReflectionClass ($ this ))->getShortName ());
7763 }
7864
7965 public function passValuesFromRequestToFilter ($ values )
Original file line number Diff line number Diff line change 1414use LaravelViews \UI \Header ;
1515use Illuminate \Support \ServiceProvider ;
1616use Illuminate \Support \Facades \Blade ;
17+ use Illuminate \Support \Str ;
1718use LaravelViews \Console \GridViewMakeCommand ;
1819use LaravelViews \Console \ListViewMakeCommand ;
1920use LaravelViews \Console \MakeViewCommand ;
@@ -70,7 +71,8 @@ public function boot()
7071 ->publish ()
7172 ->bladeDirectives ()
7273 ->loadComponents ()
73- ->configFiles ();
74+ ->configFiles ()
75+ ->macros ();
7476 }
7577
7678 private function publish ()
@@ -159,4 +161,20 @@ private function configFiles()
159161
160162 return $ this ;
161163 }
164+
165+ private function macros ()
166+ {
167+ Str::macro ('classNameAsSentence ' , function ($ className ) {
168+ $ intermediate = preg_replace ('/(?!^)([[:upper:]][[:lower:]]+)/ ' , ' $0 ' , $ className );
169+ $ titleStr = preg_replace ('/(?!^)([[:lower:]])([[:upper:]])/ ' , '$1 $2 ' , $ intermediate );
170+
171+ return $ titleStr ;
172+ });
173+
174+ Str::macro ('camelToDash ' , function ($ str ) {
175+ return strtolower (preg_replace ('%([a-z])([A-Z])% ' , '\1-\2 ' , $ str ));
176+ });
177+
178+ return $ this ;
179+ }
162180}
Original file line number Diff line number Diff line change 22
33namespace LaravelViews \Test ;
44
5+ use Illuminate \Translation \TranslationServiceProvider ;
6+ use LaravelViews \Facades \UI ;
57use LaravelViews \LaravelViewsServiceProvider ;
6- use Livewire \Livewire ;
78use Livewire \LivewireServiceProvider ;
89use Livewire \Testing \TestableLivewire ;
910use Orchestra \Testbench \TestCase as TestbenchTestCase ;
@@ -47,8 +48,16 @@ protected function getPackageProviders($app)
4748 {
4849 return [
4950// \Spatie\LaravelRay\RayServiceProvider::class,
51+ TranslationServiceProvider::class,
5052 LivewireServiceProvider::class,
5153 LaravelViewsServiceProvider::class,
5254 ];
5355 }
56+
57+ protected function getPackageAliases ($ app )
58+ {
59+ return [
60+ 'UI ' => UI ::class
61+ ];
62+ }
5463}
Original file line number Diff line number Diff line change 44
55use LaravelViews \Actions \Action ;
66use LaravelViews \Actions \Confirmable ;
7- use PHPUnit \ Framework \TestCase as FrameworkTestCase ;
7+ use LaravelViews \ Test \TestCase ;
88
9- class ActionTest extends FrameworkTestCase
9+ class ActionTest extends TestCase
1010{
1111 public function testShouldBeConfirmed ()
1212 {
Original file line number Diff line number Diff line change 33namespace LaravelViews \Test \Unit ;
44
55use LaravelViews \Filters \Filter ;
6- use PHPUnit \ Framework \TestCase as FrameworkTestCase ;
6+ use LaravelViews \ Test \TestCase ;
77
88class ExampleTest extends Filter
99{
@@ -14,7 +14,7 @@ class ExampleTestWithTitle extends Filter
1414 protected $ title = 'My custom title ' ;
1515}
1616
17- class FilterTest extends FrameworkTestCase
17+ class FilterTest extends TestCase
1818{
1919 /**
2020 * A basic unit test example.
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public function testButtonVariants()
1717 {
1818 $ this ->assertTrue (
1919 Variants::button ('primary ' )->class () ===
20- 'text-white bg-blue-600 hover:bg-blue-500 focus:bg-blue-500 active:bg -blue-500 '
20+ 'text-white bg-blue-600 hover:bg-blue-700 focus:ring -blue-500 '
2121 );
2222 $ this ->assertEquals (
2323 Variants::button ('primary-light ' )->class (),
You can’t perform that action at this time.
0 commit comments