Skip to content

Commit

Permalink
add snake case function
Browse files Browse the repository at this point in the history
  • Loading branch information
foo99 committed Jan 12, 2018
1 parent 7764750 commit e4e59a6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
32 changes: 26 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@ Using boolean `true` or `false` is convenient if you need to display some conten

## API

There are two ways of using Ekko in your application, by using a facade `Ekko::isActiveURL('/about')` or by using a helper function `isActiveURL('/about')`.
There are two ways of using Ekko in your application, by using a facade `Ekko::isActiveURL('/about')` or by using a helper function `isActiveURL('/about')` or `is_active_route('/about')`.

### isActiveRoute
### isActiveRoute, is_active_route

Compares given route name with current route name.

```php
isActiveRoute($routeName, $output = "active")
```

```php
is_active_route($routeName, $output = "active")
```

**Examples:**

If the current route is `home`, function `isActiveRoute('home')` would return *string* `active`.
Expand All @@ -104,38 +108,50 @@ _The `*` wildcard can be used for resource routes._

Function `isActiveRoute('user.*')` would return *string* `active` for any current route which begins with `user`.

### isActiveURL
### isActiveURL, is_active_url

Compares given URL path with current URL path.

```php
isActiveURL($url, $output = "active")
```

```php
is_active_url($url, $output = "active")
```

**Examples:**

If the current URL path is `/about`, function `isActiveURL('/about')` would return *string* `active`.

### isActiveMatch
### isActiveMatch, is_active_match

Detects if the given string is found in the current URL.

```php
isActiveMatch($string, $output = "active")
```

```php
is_active_match($string, $output = "active")
```

**Examples:**

If the current URL path is `/about` or `/insideout`, function `isActiveMatch('out')` would return *string* `active`.

### areActiveRoutes
### areActiveRoutes, are_active_routes

Compares given array of route names with current route name.

```php
areActiveRoutes(array $routeNames, $output = "active")
```

```php
are_active_routes(array $routeNames, $output = "active")
```

**Examples:**

If the current route is `product.index` or `product.show`, function `areActiveRoutes(['product.index', 'product.show'])` would return *string* `active`.
Expand All @@ -144,14 +160,18 @@ _The `*` wildcard can be used for resource routes, including nested routes._

Function `areActiveRoutes(['user.*', 'product.*'])` would return *string* `active` for any current route which begins with `user` or `product`.

### areActiveURLs
### areActiveURLs, are_active_urls

Compares given array of URL paths with current URL path.

```php
areActiveURLs(array $urls, $output = "active")
```

```php
are_active_urls(array $urls, $output = "active")
```

**Examples:**

If the current URL path is `/product` or `/product/create`, function `areActiveURLs(['/product', '/product/create'])` would return *string* `active`.
Expand Down
65 changes: 65 additions & 0 deletions src/Laravelista/Ekko/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ function isActiveRoute($routeName, $output = "active")
}
}

if (!function_exists('is_active_route')) {
/**
* @param $routeName
* @param string $output
*
* @return string
*/
function is_active_route($routeName, $output = "active")
{
return isActiveRoute($routeName, $output);
}
}

if (!function_exists('isActiveURL')) {
/**
* @param $url
Expand All @@ -28,6 +41,19 @@ function isActiveURL($url, $output = "active")
}
}

if (!function_exists('is_active_url')) {
/**
* @param $url
* @param string $output
*
* @return string
*/
function is_active_url($url, $output = "active")
{
return isActiveURL($url, $output);
}
}

if (!function_exists('isActiveMatch')) {
/**
* @param $string
Expand All @@ -41,6 +67,19 @@ function isActiveMatch($string, $output = "active")
}
}

if (!function_exists('is_active_match')) {
/**
* @param $string
* @param string $output
*
* @return string
*/
function is_active_match($string, $output = "active")
{
return isActiveMatch($string, $output);
}
}

if (!function_exists('areActiveRoutes')) {
/**
* @param array $routeNames
Expand All @@ -54,6 +93,19 @@ function areActiveRoutes(array $routeNames, $output = "active")
}
}

if (!function_exists('are_active_routes')) {
/**
* @param array $routeNames
* @param string $output
*
* @return string
*/
function are_active_routes(array $routeNames, $output = "active")
{
return areActiveRoutes($routeNames, $output);
}
}

if (!function_exists('areActiveURLs')) {
/**
* @param array $urls
Expand All @@ -66,3 +118,16 @@ function areActiveURLs(array $urls, $output = "active")
return app(Ekko::class)->areActiveURLs($urls, $output);
}
}

if (!function_exists('are_active_urls')) {
/**
* @param array $urls
* @param string $output
*
* @return string
*/
function are_active_urls(array $urls, $output = "active")
{
return areActiveURLs($urls, $output);
}
}

0 comments on commit e4e59a6

Please sign in to comment.