Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mabasic committed May 12, 2019
2 parents 0affc22 + 8f81b02 commit 97bed94
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 648 deletions.
4 changes: 1 addition & 3 deletions .gitignore
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
7 changes: 3 additions & 4 deletions .travis.yml
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
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
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.
2 changes: 1 addition & 1 deletion license.md → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2016 Mario Bašić
Copyright (c) 2015-2019 Mario Bašić

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
118 changes: 118 additions & 0 deletions README.md
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.
39 changes: 10 additions & 29 deletions composer.json
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"
}
}
17 changes: 3 additions & 14 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
stopOnFailure="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<testsuite name="Package">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/Laravelista/Ekko/Facades</directory>
<file>./src/Laravelista/Ekko/EkkoServiceProvider.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
Loading

0 comments on commit 97bed94

Please sign in to comment.