Skip to content

Commit

Permalink
Add back in rendering methods - will probably be removed in v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidesu committed Dec 4, 2015
1 parent 25dd733 commit dc396a8
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,61 @@ public function guard()
return $this;
}

/*
|--------------------------------------------------------------------------
| Rendering Methods
|--------------------------------------------------------------------------
|
*/

/**
* Renders the menu as an unordered list.
*
* @param array $attributes
* @return string
*/
public function asUl($attributes = array())
{
return "<ul{$this->attributes($attributes)}>{$this->render('ul')}</ul>";
}

/**
* Generate the menu items as list items, recursively.
*
* @param string $type
* @param int $parent
* @return string
*/
protected function render($type = 'ul', $parent = null)
{
$items = '';
$itemTag = in_array($type, ['ul', 'ol']) ? 'li' : $type;

foreach ($this->whereParent($parent) as $item) {
$items .= "<{$itemTag}{$item->attributes()}>";

if ($item->link) {
$items .= "<a{$this->attributes($item->link->attr())} href=\"{$item->url()}\">{$item->title}</a>";
} else {
$items .= $item->title;
}

if ($item->hasChildren()) {
$items .= "<{$type}>";
$items .= $this->render($type, $item->id);
$items .= "</{$type}>";
}

$items .= "</{$itemTag}>";

if ($item->divider) {
$items .= "<{$itemTag}{$this->attributes($item->divider)}></{$itemTag}>";
}
}

return $items;
}

/**
* Dynamic search method against a menu attribute.
*
Expand Down

0 comments on commit dc396a8

Please sign in to comment.