Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
Adding PHP 8 support (#4)
Browse files Browse the repository at this point in the history
* Added PHP 8 support
* Removed Scrutinizer analysis
* Updated PHPCS checker and fixer norm to PSR-12
* Helpers naming breaking changes

:point_right: [See the upgrade guide](/docs/upgrade-guides/from-v1-to-v2.md)
  • Loading branch information
Okipa authored Nov 14, 2020
1 parent 0709abc commit 1d6d333
Show file tree
Hide file tree
Showing 25 changed files with 322 additions and 381 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: ['7.4']
php: ['7.4', '8.0']
laravel: ['7.*', '8.*']
include:
- laravel: '8.*'
Expand All @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
Expand All @@ -38,21 +38,21 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: common, curl, json, mbstring, zip, sqlite, pdo_sqlite
coverage: xdebug
extensions: curl, json, mbstring, zip, sqlite, pdo_sqlite
coverage: pcov

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-suggest
composer update --prefer-dist --no-interaction
# lower php and laravel versions
# Lower php and laravel versions.

- name: PHPUnit
if: matrix.php != '7.4' || matrix.laravel != '8.*'
run: vendor/bin/phpunit

# last php and laravel versions
# Last php and laravel versions.

- name: Code analysis
if: matrix.php == '7.4' && matrix.laravel == '8.*'
Expand Down
28 changes: 0 additions & 28 deletions .scrutinizer.yml

This file was deleted.

33 changes: 22 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,62 @@
# Changelog

## [1.4.0](https://github.com/Okipa/laravel-html-helper/compare/1.4.0...1.3.2)
## [2.0.0](https://github.com/Okipa/laravel-html-helper/compare/1.4.0...2.0.0)

2020-11-14

* Added PHP 8 support
* Removed Scrutinizer analysis
* Updated PHPCS checker and fixer norm to PSR-12
* Helpers naming breaking changes

:point_right: [See the upgrade guide](/docs/upgrade-guides/from-v1-to-v2.md)

## [1.4.0](https://github.com/Okipa/laravel-html-helper/compare/1.3.1...1.4.0)

2020-08-11

* Added support for Laravel 8.
* Added support for Laravel 8
* Dropped support for Laravel 5.8 and 6
* Dropped support for PHP 7.2 and 7.3

## [1.3.1](https://github.com/Okipa/laravel-html-helper/compare/1.3.0...1.3.1)

2020-03-03

* Added testing files to .gitattributes export-ignore.
* Added testing files to .gitattributes export-ignore

## [1.3.0](https://github.com/Okipa/laravel-html-helper/compare/1.2.0...1.3.0)

2020-02-18

* Dropped support for Laravel 5.5, 5.6 and 5.7.
* Added support for Laravel 7.
* Dropped support for Laravel 5.5, 5.6 and 5.7
* Added support for Laravel 7

## [1.2.0](https://github.com/Okipa/laravel-html-helper/compare/1.1.1...1.2.0)

2019-09-04

* Added support for Laravel 6.
* Dropped support for php 7.1.
* Added support for Laravel 6
* Dropped support for php 7.1

## [1.1.1](https://github.com/Okipa/laravel-html-helper/compare/1.1.0...1.1.1)

2019-08-02

* Fixed `htmlAttributes()` feature which was adding a space before the returned value, even if it was supposed to be an empty space.
* Fixed `html_attributes()` feature which was adding a space before the returned value, even if it was supposed to be an empty space

## [1.1.0](https://github.com/Okipa/laravel-html-helper/compare/1.0.5...1.1.0)

2019-08-02

* `classTag()` and `htmlAttributes()` helpers are now callable directly after a html tag : they do add a space if the helper returns something and no space if nothing is returned.
* `html_classes()` and `html_attributes()` helpers are now callable directly after a html tag : they do add a space if the helper returns something and no space if nothing is returned

```html
<div{{ classTag(<your dynamic classes>) }}></div>
<div{{ html_classes(<your dynamic classes>) }}></div>
```

## [1.0.5](https://github.com/Okipa/laravel-html-helper/compare/1.1.4...1.0.5)

2019-02-07

* Updated treatment to return an empty string when the classes list to return is empty.
* Updated treatment to return an empty string when the classes list to return is empty
105 changes: 59 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
# Laravel Html Helper

[![Source Code](https://img.shields.io/badge/source-okipa/laravel--html--helper-blue.svg)](https://github.com/Okipa/laravel-html-helper)
[![Latest Version](https://img.shields.io/github/release/okipa/laravel-html-helper.svg?style=flat-square)](https://github.com/Okipa/laravel-html-helper/releases)
[![Total Downloads](https://img.shields.io/packagist/dt/okipa/laravel-html-helper.svg?style=flat-square)](https://packagist.org/packages/okipa/laravel-html-helper)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Build status](https://github.com/Okipa/laravel-html-helper/workflows/CI/badge.svg)](https://github.com/Okipa/laravel-html-helper/actions)
[![Coverage Status](https://coveralls.io/repos/github/Okipa/laravel-html-helper/badge.svg?branch=master)](https://coveralls.io/github/Okipa/laravel-html-helper?branch=master)
[![Quality Score](https://img.shields.io/scrutinizer/g/Okipa/laravel-html-helper.svg?style=flat-square)](https://scrutinizer-ci.com/g/Okipa/laravel-html-helper/?branch=master)

Useful helpers to dynamically generate clean HTML with Laravel.
![Laravel HTML Helper](/docs/laravel-html-helper.png)
<p align="center">
<a href="https://github.com/Okipa/laravel-html-helper/releases" title="Latest Stable Version">
<img src="https://img.shields.io/github/release/Okipa/laravel-html-helper.svg?style=flat-square" alt="Latest Stable Version">
</a>
<a href="https://packagist.org/packages/Okipa/laravel-html-helper" title="Total Downloads">
<img src="https://img.shields.io/packagist/dt/okipa/laravel-html-helper.svg?style=flat-square" alt="Total Downloads">
</a>
<a href="https://github.com/Okipa/laravel-html-helper/actions" title="Build Status">
<img src="https://github.com/Okipa/laravel-html-helper/workflows/CI/badge.svg" alt="Build Status">
</a>
<a href="https://coveralls.io/github/Okipa/laravel-html-helper?branch=master" title="Coverage Status">
<img src="https://coveralls.io/repos/github/Okipa/laravel-html-helper/badge.svg?branch=master" alt="Coverage Status">
</a>
<a href="https://img.shields.io/badge/License-MIT-blue.svg" title="License: MIT">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT">
</a>
</p>

Easily handle conditional HTML generation with the following helpers.

## Compatibility

| Laravel | PHP | Package |
|---|---|---|
| ^7.* | ^7.4 | ^1.4 |
| ^7.* | ^7.4 | ^2.0 |
| ^5.8 | ^7.2 | ^1.3 |
| ^5.5 | ^7.2 | ^1.2 |
| ^5.5 | ^7.1 | ^1.0 |

## Upgrade guide

* [From v1 to V2](/docs/upgrade-guides/from-v1-to-v2.md)

## Table of Contents

- [Installation](#installation)
- [API](#api)
- [classTag](#classtag)
- [htmlAttributes](#htmlattributes)
- [html_classes](#html_classes)
- [html_attributes](#html_attributes)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
Expand All @@ -33,63 +46,63 @@ Useful helpers to dynamically generate clean HTML with Laravel.

## Installation

- Install the package with composer :
- Install the package with composer:

```bash
composer require "okipa/laravel-html-helper:^1.3"
composer require okipa/laravel-html-helper
```

## API

### `classTag(...$classList) : HtmlString`
### html_classes

In you view :
Calling this helper generates an HTML `class` tag encapsulating the given dynamic classes.

It accepts combination of strings, integers, arrays or null arguments.

```blade
<div{{ classTag(
'class1',
['class2', 'class3', null],
null,
[],
['class4', ['class5 ', 'class6Key' => 'class6']],
7
@php
$id = 17;
$fullScreen = false;
$darkMode = true;
@endphp
<div{{ html_classes(
['card', $id, 'text-left'],
$fullScreen ? 'full-screen' : null,
$darkMode ? ['bg-dark', 'text-white'] : null
) }}></div>
```

Will produce :

```html
<div class="class1 class2 class3 class4 class5 class6 7"></div>
<div class="card 17 text-left bg-dark text-white"></div>
```

In your code, you can do exactly the same using the `(new Okipa\LaravelHtmlHelper\HtmlClassTag)->render()` method.
You can call `app(Okipa\LaravelHtmlHelper\HtmlClasses)->toHtml($classes)` if you want to avoid helper use.

### `htmlAttributes(...$attributesList) : HtmlString`
### html_attributes

In you view :
Calling this helper generates dynamic HTML attributes, taking care about the given key-only, value-only or key-value combinations.

It accepts combination of strings, arrays or null arguments.

```blade
<div{{ htmlAttributes(
'attribute1Value',
['attribute2Key' => 'attribute2Value'],
['attribute3Key' => null],
['attribute4Value', 'attribute5Value'],
'',
null,
['' => 'attribute6Value'],
['attributes7Value', ['attribute8Value', 'attribute9Key' => 'attribute9Value']],
['attribute10Key' => ['attribute11Value']],
['attribute12Key' => '']
@php
$dragAndDrop = true;
$disabled = false;
@endphp
<div{{ html_attributes(
['data-confirm' => __('Are you sure you want to delete this line?')],
$dragAndDrop ? 'data-drag-drop' : null,
$disabled ? ['disabled', 'data-forbid-click'] : null,
'required'
) }}></div>
```

Will produce :

```html
<div attribute1Value attribute2Key="attribute2Value" attribute3Key attribute4Value attribute5Value attribute6Value attributes7Value attribute8Value attribute9Key="attribute9Value" attribute10Key attribute11Value attribute12Key></div>
<div data-confirm="Are you sure you want to delete this line?" data-drag-drop required></div>
```

In your code, you can do exactly the same using the `(new Okipa\LaravelHtmlHelper\HtmlAttributes)->render()` method.
You can call `app(Okipa\LaravelHtmlHelper\HtmlAttributes)->toHtml($attributes)` if you want to avoid helper use.

## Testing

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
],
"require": {
"php": "^7.4",
"php": "^7.4||^8.0",
"illuminate/support": "^7.0||^8.0"
},
"require-dev": {
Expand All @@ -50,8 +50,8 @@
"vendor/bin/phpcbf",
"vendor/bin/phpcs",
"vendor/bin/phpmd src text phpmd.xml",
"vendor/bin/phpstan analyse",
"vendor/bin/phpunit"
"vendor/bin/phpstan analyse --memory-limit=-1 --error-format=table",
"vendor/bin/phpunit -d memory_limit=-1 --testdox --coverage-text"
]
},
"config": {
Expand Down
Binary file added docs/laravel-html-helper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions docs/upgrade-guides/from-v1-to-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Upgrade from v1 to V2

Follow the steps below to upgrade the package.

## Naming changes

Helpers have been renamed. Make sure you replaced all following occurrences when upgrading:
* Search and replace all occurrences of `classTag(` by `html_classes(`
* Search and replace all occurrences of `HtmlClassTag(` by `HtmlClasses(`
* Search and replace all occurrences of `htmlAttributes(` by `html_attributes(`

## See all changes

See all change with the [comparison tool](https://github.com/Okipa/laravel-html-helper/compare/1.4.0...2.0.0).

## Undocumented changes

If you see any forgotten and undocumented change, please submit a PR to add them to this upgrade guide.
7 changes: 3 additions & 4 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0"?>
<ruleset name="PSR2">
<description>PSR-2 validation</description>
<ruleset name="PSR12">
<description>PSR-12 validation</description>
<file>./src</file>
<arg name="colors"></arg>
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>./tests/*</exclude-pattern>
</rule>
<rule ref="PSR2"/>
<rule ref="PSR12"/>
</ruleset>
23 changes: 13 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand All @@ -8,21 +9,23 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
</php>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<logging/>
</phpunit>
Loading

0 comments on commit 1d6d333

Please sign in to comment.