Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen-G committed Jan 15, 2023
0 parents commit 543c304
Show file tree
Hide file tree
Showing 17 changed files with 551 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* text=auto

/.github export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/easy-coding-standard.php export-ignore
/infection.json export-ignore
/Makefile export-ignore
/package.json export-ignore
/package-lock.json export-ignore
/phpunit.xml export-ignore
33 changes: 33 additions & 0 deletions .github/workflows/autoreview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

name: Autoreview

on:
pull_request:

jobs:
fight-mutants:
runs-on: ubuntu-latest

strategy:
matrix:
php: [8.0, 8.1, 8.2]

name: Mutation Testing Code Review Annotations ${{ matrix.php }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug

- name: Install dependencies
run: composer update --prefer-dist --no-suggest --no-interaction --no-scripts

- name: Run Infection for added and modified files only
run: |
git fetch --depth=1 origin $GITHUB_BASE_REF
php vendor/bin/infection -j2 --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

name: CI

on:
push:
pull_request:
workflow_dispatch:

jobs:
php-tests:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}

strategy:
matrix:
php: [8.0, 8.1, 8.2]
experimental: [ false ]
include:
- php: 8.3
experimental: true

name: PHP${{ matrix.php }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug

- name: Install dependencies
run: composer update --prefer-dist --no-suggest --no-interaction --no-scripts
if: ${{ matrix.experimental == false }}

- name: Install experimental dependencies
run: composer update --prefer-dist --no-suggest --no-interaction --no-scripts --ignore-platform-reqs
if: ${{ matrix.experimental == true }}

- run: composer dump-autoload -q

- name: Check codestyle
run: vendor/bin/ecs check --config=ecs.php --no-progress-bar .

- name: Execute unit tests
run: vendor/bin/phpunit --testsuite unit --testdox --colors=always

- name: Execute mutation tests
run: vendor/bin/infection --threads=4 --min-covered-msi=100 --min-msi=100
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.idea
/vendor
/node_modules
/report
.phpunit.result.cache
composer.lock
infection.log
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to `Blade macro` will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## [1.0.0]

### Added
- Everything
49 changes: 49 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "jeroen-g/blade-macro",
"description": "Create small, file-specific, macros in Blade like Twig has.",
"license": "MIT",
"authors": [
{
"name": "Jeroen",
"email": "jeroengjeroeng@gmail.com",
"homepage": "https://jeroeng.dev"
}
],
"homepage": "https://github.com/jeroen-g/blade-macro",
"keywords": ["Laravel", "Blade", "macro", "Twig"],
"require": {
"php": "8.0.*||8.1.*||8.2.*",
"illuminate/support": "^9.0"
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"mockery/mockery": "^1.5",
"infection/infection": "^0.26",
"symplify/easy-coding-standard": "^9.0"
},
"autoload": {
"psr-4": {
"JeroenG\\BladeMacro\\": "src/"
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"JeroenG\\BladeMacro\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
"JeroenG\\BladeMacro\\BladeMacroServiceProvider"
]
}
},
"config": {
"allow-plugins": {
"infection/extension-installer": false
}
}
}
27 changes: 27 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Contributing

Contributions are welcome and will be fully credited.

Contributions are accepted via Pull Requests on [Github](https://github.com/jeroeng/blademacro).

# Things you could do
If you want to contribute but do not know where to start, this list provides some starting points.
- Add license text
- Remove rewriteRules.php
- Set up TravisCI, StyleCI, ScrutinizerCI
- Write a comprehensive ReadMe

## Pull Requests

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.


**Happy coding**!
39 changes: 39 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->set(DeclareStrictTypesFixer::class);

$services->set(StrictComparisonFixer::class);

$services->set(StrictParamFixer::class);

$services->set(ReturnTypeDeclarationFixer::class);

$services->set(AssignmentInConditionSniff::class);

$services->set(MbStrFunctionsFixer::class);

$services->set(OrderedClassElementsFixer::class);

$services->set(ClassAttributesSeparationFixer::class);

$parameters = $containerConfigurator->parameters();

$parameters->set('sets', ['clean-code', 'psr12']);

$parameters->set('exclude_files', ['node_modules/*', 'vendor/*', 'docs/*']);
};
32 changes: 32 additions & 0 deletions infection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "vendor/infection/infection/resources/schema.json",
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "infection.log",
"html": "report/infection.html"
},
"mutators": {
"@arithmetic": true,
"@boolean": true,
"@cast": true,
"@conditional_boundary": true,
"@conditional_negotiation": true,
"@equal": true,
"@function_signature": true,
"IdenticalEqual": false,
"@number": true,
"@operator": true,
"@regex": true,
"@removal": true,
"@return_value": true,
"@sort": true,
"@unwrap": true,
"@loop": true,
"@extensions": true,
"@default": true
}
}
5 changes: 5 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 changes: 13 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="unit">
<directory suffix=".php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
79 changes: 79 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Blade Macro

[![Latest Version on Packagist][ico-version]][link-packagist]

Have you as a Laravel developer ever looked at [Twig macros](https://twig.symfony.com/doc/3.x/tags/macro.html) with envy?

Maybe you want to reuse a specific element twice on the same page, but you don't want to have it (supported) as a Blade component.
With a Blade macro, you can. Here is an example:

```blade
@macro(listItem)
<li class="flex justify-center all-sorts-of-tailwind-classes"> {{ $name }} </li>
@endmacro
@if($conditionIsTrue)
<ul>
@foreach($listOne as $name)
@showMacro(listItem, ['name' => $name])
@endforeach
</ul>
@else
<ul>
@foreach($listTwo as $name)
@showMacro(listItem, ['name' => $name])
@endforeach
</ul>
@endif
```

## Installation

Via Composer

``` bash
$ composer require jeroen-g/blade-macro
```

## Usage

Define a macro with the Blade directives:

```blade
@macro(myMacroName)
<fancy-code />
@endMacro
```

Call the macro elsewhere _in the same Blade file_ with the Blade directive or PHP helper:

```php
@showMacro(myMacroName)
// or
{!! m('myMacroName') !!}
```

Do you want to use a macro in another Blade view? Use a [Blade component](https://laravel.com/docs/blade#components).

## Change log

Please see the [changelog](changelog.md) for more information on what has changed recently.

## Contributing

Please see [contributing.md](contributing.md) for details and a todolist.

## Credits

- [Jeroen][link-author]
- [All Contributors][link-contributors]

## License

MIT. Please see the [license file](license.md) for more information.

[ico-version]: https://img.shields.io/packagist/v/jeroen-g/blade-macro.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/jeroen-g/blade-macro
[link-author]: https://github.com/jeroen-g
[link-contributors]: ../../contributors
26 changes: 26 additions & 0 deletions src/BladeMacroServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace JeroenG\BladeMacro;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class BladeMacroServiceProvider extends ServiceProvider
{
public function boot(): void
{
Blade::directive('macro', function ($macroName) {
return Macro::define($macroName);
});

Blade::directive('endMacro', function () {
return Macro::endDefinition();
});

Blade::directive('showMacro', function ($expression) {
return Macro::show($expression);
});
}
}
Loading

0 comments on commit 543c304

Please sign in to comment.