GithubHelp home page GithubHelp logo

menu-generator's Introduction

Menu Generator for Laravel

A class for Laravel to easily generate HTML menus.

Readme is a work in progress...

Install

Via Composer

$ composer require taylornetwork/menu-generator

Setup

Add the service provider to the providers array in config/app.php

'providers' => [

	TaylorNetwork\MenuGenerator\MenuGeneratorServiceProvider::class,

],

Publish config to your config directory

$ php artisan vendor:publish

Usage

Command

This package comes with an artisan command menu:definition to easily generate menu definitions

To generate a menu definition

$ php artisan menu:definition MenuName

This will create App\Menus\MenuName.php

The menu definitions extend the TaylorNetwork\MenuGenerator\Definition class which has some functionality for rendering the menu once defined.

Add all the items on your menu in the define() function

namespace App\Menus;

use TaylorNetwork\MenuGenerator\Definition;

class MenuName extends Definition
{
	public function define()
	{
		$this->generator->newMenu();
		$this->generator->addItem('Home', route('home'));
		$this->generator->closeMenu();
	}
}

Would generate a very simple menu with only a Home link.

See the generator instance documentation below.

Generator Instance

The definition class uses the TaylorNetwork\MenuGenerator\Generator class to generate menus. In any class that extends TaylorNetwork\MenuGenerator\Definition the generator instance can be accessed by the protected property generator or by the public function getGenerator().

Methods

newMenu()

Every menu must start with a newMenu() call to open the menu HTML tags.

addItem(string [, string, bool, string ])

The addItem method accepts a minimum of 1 parameter, the text to display on the link. See table for parameter details.

# Name Description Type Default Value Required
1 Text The text to display for the link string - Yes
2 Href The link destination URL string '#' No
3 Show Icon Show an icon in the link bool false No
4 Icon The icon to display (usually a font-awesome name ie: 'fa-dashboard') string null No

Note: when using font-awesome, by default fa fa-fw is prepended to the name so it is not required, only the fa-dashboard is required.

addSubMenu(string [, bool, string ])

closeSubMenu()

closeMenu()

closeIfNotClosed()

renderMenu()

setCallback(string, Closure)

Sets a callback function by a key name. See generator callbacks for a list of keys.

$menuOpen = false;

$generator->setCallback('menu.after.open', function () use ($menuOpen) {
	$menuOpen = true;
});

Generator Callbacks

There are a number of callback functions that the generator will call if they exist. You can set a callback by adding it to your config/menu_generator.php in the callbacks array or by using the setCallback method.

Menu Callbacks

menu.before.open

Called when newMenu() is called, before opening the HTML tag.

menu.after.open

Called when newMenu() is called, after opening the HTML tag.

menu.before.close

Called when the menu is being closed but before the closing HTML tag is added.

menu.after.close

Called after the menu is fully closed and processing is done.

menu.before.render

Called right before the menu is rendered to HTML.

Sub Menu Callbacks

sub-menu.before.open

Called when adding a sub menu but before processing the add.

sub-menu.after.open

Called when adding a sub menu after it has been added.

sub-menu.before.close

Called when closing a sub menu before processing the close has started.

sub-menu.after.close

Called after sub menu was closed.

Item Callbacks

item.before.add

Called before adding an item.

item.after.add

Called after item has been added.

Credits

License

The MIT License (MIT). Please see License File for more information.

menu-generator's People

Contributors

samueljtaylor avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.