Skip to content

Commit

Permalink
create sui_breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
ramadani committed Aug 3, 2016
1 parent f1e51d5 commit 068ad38
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions resources/views/breadcrumb/semantic-ui.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="ui breadcrumb">
{!! implode($divider, $items) !!}
</div>
69 changes: 69 additions & 0 deletions src/Breadcrumb/SemanticUIBreadcrumb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Laravolt\Support\Breadcrumb;

use Laravolt\Support\Contracts\Breadcrumb;

/**
* Class SemanticUIBreadcrumb
*
* @package Laravolt\Support\Breadcrumb
*/
class SemanticUIBreadcrumb implements Breadcrumb
{
/**
* @var string
*/
protected $divider;

/**
* @var array
*/
protected $items = [];

/**
* Set divider
*
* @param string $divider
* @return mixed
*/
public function divider($divider = '<div class="divider"> / </div>')
{
$this->divider = $divider;

return $this;
}

/**
* Add item for breadcrumn
*
* @param $name
* @param string $url
* @return mixed
*/
public function addItem($name, $url = '')
{
if (! empty($url)) {
$item = sprintf('<a href="%s" class="section">%s</a>', $url, $name);
} else {
$item = sprintf('<div class="active section">%s</div>', $name);
}

array_push($this->items, $item);

return $this;
}

/**
* Render breadcrumb view
*
* @return mixed
*/
public function render()
{
return view('support::breadcrumb.semantic-ui', [
'divider' => $this->divider,
'items' => $this->items
])->render();
}
}
35 changes: 35 additions & 0 deletions src/Contracts/Breadcrumb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Laravolt\Support\Contracts;

/**
* Interface Breadcrumb
*
* @package Laravolt\Support\Contracts
*/
interface Breadcrumb
{
/**
* Set divider
*
* @param string $divider
* @return mixed
*/
public function divider($divider = '');

/**
* Add item for breadcrumn
*
* @param $name
* @param string $url
* @return mixed
*/
public function addItem($name, $url = '');

/**
* Render breadcrumb view
*
* @return mixed
*/
public function render();
}
4 changes: 4 additions & 0 deletions src/SupportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function boot()
$this->registerBladeExtensions();
$this->registerTranslations();
$this->registerConfigurations();
$this->loadViewsFrom(realpath(__DIR__.'/../resources/views'), 'support');
}

/**
Expand All @@ -32,6 +33,9 @@ public function register()
{
// timezone
$this->app->bind(Contracts\TimezoneRepository::class, Repositories\TimezoneRepositoryArray::class);

// breadcrumb
$this->app->bind(Contracts\Breadcrumb::class, Breadcrumb\SemanticUIBreadcrumb::class);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ function sui_pagination($collection)
}
}

if (!function_exists('sui_breadcrumb')) {

/**
* @return \Illuminate\Foundation\Application|mixed
*/
function sui_breadcrumb()
{
return app(Laravolt\Support\Contracts\Breadcrumb::class);
}
}

if (!function_exists('render')) {

/**
Expand Down

0 comments on commit 068ad38

Please sign in to comment.