-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplistic, effortless menu building API originally built for Laravel use, now a seamlessly independent package.
- Loading branch information
Luke Snowden
committed
Jul 14, 2014
0 parents
commit b89e4e1
Showing
14 changed files
with
1,386 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
|
||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar install --dev | ||
|
||
script: phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Purpose Media Menu Builder for Laravel 4 | ||
|
||
|
||
## Usage | ||
|
||
|
||
Very simple method of building menus from database data (id, parent id), service provider register methods for application modules and much more. | ||
|
||
|
||
## Example 1 | ||
|
||
|
||
```php | ||
<?php | ||
Menu::addItem( array( 'text' => 'Home', 'URL' => '/', 'reference' => '0' ) ); | ||
Menu::render(); | ||
?> | ||
``` | ||
|
||
##Example 2 - Nesting Children | ||
|
||
|
||
```php | ||
<?php | ||
Menu::addItem( array( 'text' => 'Services', 'URL' => '/services/', 'reference' => '1', 'parent' => '0' ) ); | ||
Menu::render(); | ||
?> | ||
``` | ||
|
||
## Example 3 - Multiple Menus | ||
|
||
|
||
```php | ||
<?php | ||
Menu::addItem( array( 'text' => 'Services', 'URL' => '/services/', 'reference' => '1', 'parent' => '0' ) )->toMenu( 'main' ); | ||
Menu::render( 'main' ); | ||
?> | ||
``` | ||
|
||
## Auto classes | ||
|
||
|
||
I have added in some of the most used and required classes for styling menus | ||
|
||
|
||
```css | ||
.first-item {} | ||
.last-item {} | ||
.current-root {} | ||
.current-parent {} | ||
.current-ancestor {} | ||
.has-children {} | ||
``` | ||
|
||
## Output | ||
|
||
|
||
```php | ||
<?php | ||
Menu::addItem( array( 'text' => 'Home', 'URL' => '/menu-test-2/public/', 'reference' => '1', 'class' => 'home-icon', 'weight' => 0 ) )->toMenu( 'main' ); | ||
Menu::addItem( array( 'text' => 'Services', 'URL' => '/menu-test-2/public/services/', 'reference' => '2' ) )->toMenu( 'main' ); | ||
Menu::addItem( array( 'text' => 'Development', 'URL' => '/menu-test-2/public/services/development/', 'reference' => '3', 'parent' => '2' ) )->toMenu( 'main' ); | ||
Menu::addItem( array( 'text' => 'Design', 'URL' => '/menu-test-2/public/services/design/', 'reference' => '4', 'parent' => '2', 'weight' => 0 ) )->toMenu( 'main' ); | ||
Menu::render( 'main' ); | ||
?> | ||
``` | ||
|
||
```html | ||
<ul class="cf clearfix nav-main pm-menu"> | ||
<li class="home-icon current first-item container node-1"> | ||
<a href="/menu-test-2/public/">Home</a> | ||
</li> | ||
<li class=" has-children last-item container node-1"> | ||
<a href="/menu-test-2/public/services/">Services</a> | ||
<ul> | ||
<li class=" first-item nav-node node-2"> | ||
<a href="/menu-test-2/public/services/design/">Design</a> | ||
</li> | ||
<li class=" last-item nav-node node-2"> | ||
<a href="/menu-test-2/public/services/development/">Development</a> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
``` | ||
|
||
## Use with third party menu UI through L4 Model | ||
(Please note this is just a general summary of how it would work if you had 2 tables (and models) for navigations and navigation items with a standard hasMany() relationship) | ||
|
||
|
||
```php | ||
<?php | ||
$navigation = Navigation::with( 'navigationItems' )->where( 'navigation_slug', '=', 'main' )->get(); | ||
foreach( $navigation->navigationItems as $item ) | ||
{ | ||
Menu::addItem( array( 'text' => , $item->name 'URL' => $item->url, 'reference' => $item->id, 'parent' => $item->parent_id, 'weight' => $item->order ) )->toMenu( $navigation->navigation_slug ); | ||
} | ||
Menu::render( $navigation->navigation_slug ); | ||
?> | ||
``` | ||
|
||
## Install | ||
|
||
Add the following to you applications composer.json file | ||
|
||
|
||
```json | ||
"require": { | ||
... | ||
"purposemedia/menu" : "dev-master" | ||
}, | ||
``` | ||
|
||
Run the following from your terminal from your application route (make sure you have access to composer.phar) | ||
|
||
|
||
```shell | ||
php composer.phar update | ||
``` | ||
|
||
add the following to your /app/config/app.php's provider array. | ||
|
||
|
||
```php | ||
'Purposemedia\Menu\MenuServiceProvider' | ||
``` | ||
|
||
|
||
add the following to your /app/config/app.php's aliases array. | ||
|
||
|
||
```php | ||
'Menu' => 'Purposemedia\Menu\Facades\Menu' | ||
``` | ||
|
||
|
||
and finally back to your terminal and run | ||
|
||
|
||
```shell | ||
php composer.phar dump-autoload | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "purposemedia/menu", | ||
"description": "Effortless menu building for Laravel 4", | ||
"homepage": "https://bitbucket.org/purposemedia/menu/", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Luke Snowden", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Purposemedia\\Menu": "src/" | ||
} | ||
}, | ||
"scripts": { | ||
"post-update-cmd": [ | ||
"php artisan package:install purposemedia/menu" | ||
], | ||
"post-create-project-cmd": [ | ||
"php artisan key:generate", | ||
"php artisan package:install purposemedia/menu" | ||
] | ||
}, | ||
"minimum-stability": "dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"providers": [ | ||
"Purposemedia\Menu\MenuServiceProvider" | ||
], | ||
"aliases": [ | ||
{ | ||
"alias": "Menu", | ||
"facade": "Purposemedia\Menu\Facades\Menu" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php namespace Purposemedia\Menu\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class Menu extends Facade | ||
{ | ||
|
||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
|
||
protected static function getFacadeAccessor() | ||
{ | ||
return 'menu'; | ||
} | ||
|
||
} |
Oops, something went wrong.