-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
215 additions
and
648 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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store | ||
/coverage | ||
.phpunit.result.cache |
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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
- 7.3 | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --prefer-dist --no-interaction --dev | ||
- travis_retry composer install --prefer-dist --no-interaction | ||
|
||
script: | ||
- vendor/bin/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,19 @@ | ||
# Contributing | ||
|
||
There are no strict rules when contributing, but here are my suggestions. | ||
|
||
> I use a combination of [Gitflow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) and [Forking Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow). | ||
## Steps | ||
|
||
1. Fork the repository. | ||
2. Create a branch depending on the issue that you are working on. *See reference table bellow.* | ||
3. Do you work and commit. | ||
4. Create a Pull Request to the `develop` branch. | ||
|
||
### Branch naming reference | ||
|
||
- `feature` - New functionality or refactoring. | ||
- `bugfix` - Fixes existing code | ||
- `hotfix` - Urgent production fix. Use this if there is a huge bug. | ||
- `support` - Documentation updates & stuff like that. |
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
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,118 @@ | ||
# Ekko | ||
|
||
PHP function for marking navigation items active. | ||
|
||
[![Become a Patron](https://img.shields.io/badge/Become%20a-Patron-f96854.svg?style=for-the-badge)](https://www.patreon.com/laravelista) | ||
|
||
> Starting with version `2.0.0`, there is no backward compatibility with the previous releases. | ||
The default output value is for [Bootstrap](http://getbootstrap.com), but it can be changed to anything. | ||
|
||
## Features | ||
|
||
- Single function | ||
- Five lines of code | ||
- Framework agnostic | ||
- Supports wildcards & arrays | ||
- Documented | ||
- Tested | ||
|
||
## Installation | ||
|
||
From the command line: | ||
|
||
```bash | ||
composer require laravelista/ekko | ||
``` | ||
|
||
## Overview | ||
|
||
To mark a menu item active in [Bootstrap](http://getbootstrap.com/components/#navbar), you need to add a `active` CSS class to the `<li>` tag: | ||
|
||
```html | ||
<ul class="nav navbar-nav"> | ||
<li class="active"><a href="/">Home</a></li> | ||
<li><a href="/about">About</a></li> | ||
</ul> | ||
``` | ||
|
||
You could do it manually with Laravel, but you will end up with a sausage: | ||
|
||
```html | ||
<ul class="nav navbar-nav"> | ||
<li class="@if(URL::current() == URL::to('/')) active @endif"><a href="/">Home</a></li> | ||
<li><a href="/about">About</a></li> | ||
</ul> | ||
``` | ||
|
||
With Ekko your code will look like this: | ||
|
||
```html | ||
<ul class="nav navbar-nav"> | ||
<li class="{{ is_active('/') }}"><a href="/">Home</a></li> | ||
<li><a href="/about">About</a></li> | ||
</ul> | ||
``` | ||
|
||
What if you are not using Bootstrap, but some other framework or a custom design? Instead of returning `active` CSS class, you can make Ekko return anything you want including boolean `true` or `false`: | ||
|
||
```html | ||
<ul class="nav navbar-nav"> | ||
<li class="{{ is_active('/', 'highlight') }}"><a href="/">Home</a></li> | ||
<li><a href="/about">About</a></li> | ||
</ul> | ||
``` | ||
|
||
Using boolean `true` or `false` is convenient if you need to display some content depending on which page you are in your layout view: | ||
|
||
```html | ||
@if(is_active('/about', true)) | ||
<p>Something that is only visible on the `about` page.</p> | ||
@endif | ||
``` | ||
|
||
## Usage | ||
|
||
This package consists of only one function `is_active`. The function accepts an `input` which can be a string or an array of strings, and an `output` which can be anything. The default output is `active`. | ||
|
||
### Static URLs | ||
|
||
You will use this for your static (non changing) pages. | ||
|
||
``` | ||
<li class="{{ is_active('/') }}"><a href="/">Home</a></li> | ||
<li class="{{ is_active('/about') }}"><a href="/">About</a></li> | ||
<li class="{{ is_active('/contact') }}"><a href="/">Contact</a></li> | ||
``` | ||
|
||
### Dynamic URLs | ||
|
||
Most useful when dealing with resources that contain either slugs or IDs. Useful for blogs, portfolio, model CRUD... | ||
|
||
``` | ||
<li class="{{ is_active('/user/*') }}"><a href="/">User Management</a></li> | ||
<li class="{{ is_active('/portfolio/*') }}"><a href="/">Project</a></li> | ||
<li class="{{ is_active('/user/*/edit') }}"><a href="/">Edit User X</a></li> | ||
``` | ||
|
||
### Array | ||
|
||
You can combine "Static" and "Dynamic" in an array. | ||
|
||
``` | ||
<li class="{{ is_active(['/home', '/']) }}"><a href="/">Home</a></li> | ||
<li class="{{ is_active(['/blog/*', '/a-super-cool-post-slug']) }}"><a href="/">Blog</a></li> | ||
``` | ||
|
||
## Credits | ||
|
||
Many thanks to: | ||
|
||
- [@judgej](https://github.com/judgej) for route wildcards. | ||
- [@Jono20201](https://github.com/Jono20201) for helper functions. | ||
- [@JasonMillward](https://github.com/JasonMillward) for improving wildcards in nested route names. | ||
- [@it-can](https://github.com/it-can) for Laravel 5.5+ auto-discovery. | ||
- [@foo99](https://github.com/foo99) for snake_case function names. | ||
- [@Turboveja](https://github.com/Turboveja) for a PR that I did not merge. Sry. | ||
|
||
I know that this new version includes very little of your contributions, but you will not be forgotten. Thank you. |
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 |
---|---|---|
@@ -1,40 +1,21 @@ | ||
{ | ||
"name": "laravelista/ekko", | ||
"description": "Laravel helper for detecting active navigation menu items and applying bootstrap classes.", | ||
"keywords": ["navigation", "bootstrap", "laravel", "helper"], | ||
"description": "PHP function for marking navigation items active.", | ||
"license": "MIT", | ||
"keywords": ["php", "function", "active", "bootstrap", "helper"], | ||
"authors": [ | ||
{ | ||
"name": "Mario Basic", | ||
"email": "mario.basic@outlook.com" | ||
} | ||
{ | ||
"name": "Mario Bašić", | ||
"email": "mario@laravelista.hr" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.6.0", | ||
"illuminate/routing": "~4.0|~5.0", | ||
"illuminate/support": "~4.0|~5.0" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Laravelista\\Ekko\\": "src/" | ||
}, | ||
"files" : [ | ||
"src/Laravelista/Ekko/helpers.php" | ||
] | ||
"files" : [ | ||
"src/is_active.php" | ||
] | ||
}, | ||
"minimum-stability": "stable", | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.3", | ||
"mockery/mockery": "^0.9.4" | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Laravelista\\Ekko\\EkkoServiceProvider" | ||
], | ||
"aliases": { | ||
"Ekko": "Laravelista\\Ekko\\Facades\\Ekko" | ||
} | ||
} | ||
"phpunit/phpunit": "^8" | ||
} | ||
} |
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
Oops, something went wrong.