File tree Expand file tree Collapse file tree 5 files changed +73
-15
lines changed Expand file tree Collapse file tree 5 files changed +73
-15
lines changed Original file line number Diff line number Diff line change 22
33namespace TeachMe \Components ;
44
5+ use Illuminate \Contracts \Config \Repository as Config ;
6+ use Illuminate \Contracts \View \Factory as View ;
57use Collective \Html \HtmlBuilder as CollectiveHtmlBuilder ;
8+ use Illuminate \Routing \UrlGenerator ;
69
710class HtmlBuilder extends CollectiveHtmlBuilder {
811
9- public function menu ()
12+ /**
13+ * @var Config
14+ */
15+ private $ config ;
16+ /**
17+ * @var View
18+ */
19+ private $ view ;
20+
21+ public function __construct (Config $ config , View $ view , UrlGenerator $ url )
22+ {
23+ $ this ->config = $ config ;
24+ $ this ->view = $ view ;
25+ $ this ->url = $ url ;
26+ }
27+
28+ public function menu ($ items )
29+ {
30+ if ( ! is_array ($ items ))
31+ {
32+ $ items = $ this ->config ->get ($ items , array ());
33+ }
34+
35+ return $ this ->view ->make ('partials/menu ' , compact ('items ' ));
36+ }
37+
38+ /**
39+ * Builds an HTML class attribute dynamically
40+ * Usage:
41+ * {!! Html::classes(['home' => true, 'main', 'dont-use-this' => false]) !!}
42+ * Returns:
43+ * class="home main".
44+ *
45+ * @param array $classes
46+ *
47+ * @return string
48+ */
49+ public function classes (array $ classes )
1050 {
11- return view ('partials/menu ' );
51+ $ html = '' ;
52+ foreach ($ classes as $ name => $ bool ) {
53+ if (is_int ($ name )) {
54+ $ name = $ bool ;
55+ $ bool = true ;
56+ }
57+ if ($ bool ) {
58+ $ html .= $ name .' ' ;
59+ }
60+ }
61+ if (! empty ($ html )) {
62+ return ' class=" ' .trim ($ html ).'" ' ;
63+ }
64+ return '' ;
1265 }
1366
1467}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ protected function registerHtmlBuilder()
1515 {
1616 $ this ->app ->bindShared ('html ' , function ($ app )
1717 {
18- return new HtmlBuilder ($ app ['url ' ]);
18+ return new HtmlBuilder ($ app ['config ' ], $ app [ ' view ' ], $ app [ ' url ' ]);
1919 });
2020 }
2121
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ return array (
4+
5+ 'menu ' => array (
6+ 'tickets.latest ' => 'Recientes ' ,
7+ 'tickets.popular ' => 'Populares ' ,
8+ 'tickets.open ' => 'Abiertas ' ,
9+ 'tickets.closed ' => 'Finalizadas '
10+ )
11+
12+ );
Original file line number Diff line number Diff line change 3838
3939 <div class =" collapse navbar-collapse" id =" bs-example-navbar-collapse-1" >
4040
41- {!! Html:: menu () ! !}
41+ {!! Html:: menu (' teachme.menu ' ) ! !}
4242
4343 <ul class =" nav navbar-nav navbar-right" >
4444 <li class =" dropdown" >
Original file line number Diff line number Diff line change 11<ul class =" nav navbar-nav" >
2- <li role =" presentation" >
3- <a href =" http://teachme.dev/" >Recientes</a >
4- </li >
5- <li role =" presentation" >
6- <a href =" http://teachme.dev/populares" >Populares</a >
7- </li >
8- <li role =" presentation" >
9- <a href =" http://teachme.dev/pendientes" >Abiertas</a >
10- </li >
11- <li role =" presentation" >
12- <a href =" http://teachme.dev/tutoriales" >Finalizadas</a >
2+ @foreach ($items as $route => $text )
3+ <li role =" presentation" {!! Html:: classes ([' active' => Route:: is ($route )]) ! !} >
4+ <a href =" {{ route ($route ) } }" >{{ $text } } </a >
135 </li >
6+ @endforeach
147</ul >
You can’t perform that action at this time.
0 commit comments