Skip to content

Commit

Permalink
Remove HTML generators (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaesung2061 authored and kaidesu committed Sep 26, 2018
1 parent e6e1b3d commit a8d588b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 106 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"illuminate/support": "5.5.*|5.6.*|5.7.*",
"illuminate/config": "5.5.*|5.6.*|5.7.*",
"illuminate/routing": "5.5.*|5.6.*|5.7.*",
"illuminate/view": "5.5.*|5.6.*|5.7.*",
"laravelcollective/html": "5.5.*|5.6.*|5.7.*"
"illuminate/view": "5.5.*|5.6.*|5.7.*"
},
"autoload": {
"psr-4": {
Expand Down
79 changes: 1 addition & 78 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace Caffeinated\Menus;

use BadMethodCallException;
use Collective\Html\HtmlBuilder;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Str;

Expand All @@ -18,11 +17,6 @@ class Builder
*/
protected $groupStack = [];

/**
* @var Collective\Html\HtmlBuilder
*/
protected $html;

/**
* @var string
*/
Expand Down Expand Up @@ -53,14 +47,12 @@ class Builder
*
* @param string $name
* @param array $config
* @param Collective\Html\HtmlBuilder $html
* @param Illuminate\Routing\UrlGenerator $url
*/
public function __construct($name, $config, HtmlBuilder $html, UrlGenerator $url)
public function __construct($name, $config, UrlGenerator $url)
{
$this->name = $name;
$this->config = $config;
$this->html = $html;
$this->url = $url;
$this->items = new Collection;
}
Expand Down Expand Up @@ -114,18 +106,6 @@ public function extractAttributes($options = array())
return array();
}

/**
* Converts the defined attributes into HTML.
*
* @param array $attributes
*
* @return string
*/
public function attributes($attributes = array())
{
return $this->html->attributes($attributes);
}

/**
* Insert a divider after the item.
*
Expand Down Expand Up @@ -498,63 +478,6 @@ public function guard()
return $this;
}

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

/**
* Renders the menu as an unordered list.
*
* @deprecated
*
* @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
12 changes: 0 additions & 12 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ public function add($title, $options = '')
return $this->builder->add($title, $options);
}

/**
* Fetch the formatted attributes for the item in HTML.
*
* @deprecated
*
* @return string
*/
public function attributes()
{
return $this->builder->attributes($this->attributes);
}

/**
* Get all attributes.
*
Expand Down
12 changes: 2 additions & 10 deletions src/Menu.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Caffeinated\Menus;

use Collective\Html\HtmlBuilder;
use Illuminate\Config\Repository;
use Illuminate\Routing\UrlGenerator;
use Illuminate\View\Factory;
Expand All @@ -18,11 +17,6 @@ class Menu
*/
protected $config;

/**
* @var \Collective\Html\HtmlBuilder
*/
protected $html;

/**
* @var \Illuminate\Routing\UrlGenerator
*/
Expand All @@ -38,14 +32,12 @@ class Menu
*
* @param \Illuminate\Config\Repository $config
* @param \Illuminate\View\Factory $view
* @param \Collective\Html\HtmlBuilder $html
* @param \Illuminate\Routing\UrlGenerator $url
*/
public function __construct(Repository $config, Factory $view, HtmlBuilder $html, UrlGenerator $url)
public function __construct(Repository $config, Factory $view, UrlGenerator $url)
{
$this->config = $config;
$this->view = $view;
$this->html = $html;
$this->url = $url;
$this->collection = new Collection;
}
Expand All @@ -60,7 +52,7 @@ public function __construct(Repository $config, Factory $view, HtmlBuilder $html
public function make($name, $callback)
{
if (is_callable($callback)) {
$menu = new Builder($name, $this->loadConfig($name), $this->html, $this->url);
$menu = new Builder($name, $this->loadConfig($name), $this->url);

call_user_func($callback, $menu);

Expand Down
5 changes: 1 addition & 4 deletions src/MenusServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ public function provides()
*/
protected function registerServices()
{
// Register the Laravel Collective HTML Service Provider
$this->app->register('Collective\Html\HtmlServiceProvider');

// Bind our Menu class to the IoC container
$this->app->singleton('menu', function($app) {
return new Menu($app['config'], $app['view'], $app['html'], $app['url']);
return new Menu($app['config'], $app['view'], $app['url']);
});
}
}

0 comments on commit a8d588b

Please sign in to comment.