-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * Green tests * Skip blade components on < 8.0 * Don't try to boot components in Laravel 7 * version_compare order * Minor refactor * Only test components on Laravel 8 * More tests * Trailing comma * Test all input types * Backwards-compat * Tests for radio/checkbox groups * Add support for Livewire and Alpine-style attributes to Aire Components * Changelog and readme
- Loading branch information
Showing
67 changed files
with
5,304 additions
and
47 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Changelog | ||
|
||
Starting with version 2.4.0, all notable changes will be documented in this file following | ||
the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format. This project adheres | ||
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [2.4.0] - 2021-01-22 | ||
|
||
### Added | ||
|
||
- Added support for [Laravel Blade Components](https://laravel.com/docs/8.x/blade#components) | ||
|
||
## 2.3.4 and before | ||
|
||
For all releases from 2.3.4 and below, see the [Github Releases](https://github.com/glhd/aire/releases). | ||
|
||
[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/2.4.0...HEAD | ||
[2.4.0]: https://github.com/olivierlacan/keep-a-changelog/compare/2.3.4...2.4.0 |
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,129 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
$finder = \Symfony\Component\Finder\Finder::create() | ||
->files() | ||
->in(__DIR__.'/../src/Elements') | ||
->depth(0) | ||
->name('*.php'); | ||
|
||
$ignored_concerns = ['CreatesElements', 'CreatesInputTypes']; | ||
|
||
$ignored_methods = collect($ignored_concerns) | ||
->flatMap(function($name) { | ||
return (new ReflectionClass("Galahad\\Aire\\Elements\\Concerns\\{$name}"))->getMethods(); | ||
}) | ||
->map(function(ReflectionMethod $method) { | ||
return $method->getName(); | ||
}) | ||
->values() | ||
->all(); | ||
|
||
collect($finder) | ||
->map(function(\Symfony\Component\Finder\SplFileInfo $file) { | ||
return 'Galahad\\Aire\\Elements\\'.$file->getBasename('.php'); | ||
}) | ||
->values() | ||
->filter(function($class_name) { | ||
return class_exists($class_name); | ||
}) | ||
->map(function($class_name) { | ||
return new ReflectionClass($class_name); | ||
}) | ||
->reject(function(ReflectionClass $class) { | ||
return $class->isAbstract(); | ||
}) | ||
->each(function(ReflectionClass $class) use ($ignored_methods) { | ||
$methods = collect($class->getMethods(ReflectionMethod::IS_PUBLIC)) | ||
->keyBy(function(ReflectionMethod $method) { | ||
return $method->getName(); | ||
}) | ||
->reject(function(ReflectionMethod $method) { | ||
return $method->isStatic() | ||
|| $method->isAbstract() | ||
|| $method->getDeclaringClass()->getName() === 'Galahad\\Aire\\Elements\\Concerns\\CreatesElements' | ||
|| preg_match('/^(__|(get|set|has|is)[A-Z])/', $method->getName()); | ||
}) | ||
->except([ | ||
'render', | ||
'toHtml', | ||
'hasViewData', | ||
'callMacro', | ||
'registerElement', | ||
]) | ||
->except($ignored_methods); | ||
|
||
$properties = $methods->map(function(ReflectionMethod $method) { | ||
if (0 === $method->getNumberOfParameters()) { | ||
$type = '?bool '; | ||
} elseif ($method->getNumberOfParameters() > 1) { | ||
$type = '?array '; | ||
} else { | ||
$parameter = $method->getParameters()[0]; | ||
if ($parameter->hasType()) { | ||
$type = '?'.$parameter->getType()->getName().' '; | ||
} else { | ||
$type = ''; | ||
} | ||
} | ||
|
||
return (object) [ | ||
'name' => $method->getName(), | ||
'type' => $type, | ||
]; | ||
}); | ||
|
||
// $props = $properties | ||
// ->map(function($property) { | ||
// return "public {$property->type}\${$property->name} = null;"; | ||
// }) | ||
// ->implode("\n\t\n\t"); | ||
|
||
$params = $properties | ||
->map(function($property) { | ||
return "{$property->type}\${$property->name} = null"; | ||
}) | ||
->implode(",\n\t\t"); | ||
|
||
$compact = $properties | ||
->map(function($property) { | ||
return "'{$property->name}'"; | ||
}) | ||
->implode(",\n\t\t\t"); | ||
|
||
$name = class_basename($class->getName()); | ||
|
||
$code = <<<PHP | ||
<?php | ||
namespace Galahad\Aire\Components; | ||
use Galahad\\Aire\\Elements\\{$name} as {$name}Element; | ||
class {$name} extends ElementComponent | ||
{ | ||
public function __construct( | ||
{$params} | ||
) { | ||
\$this->createElement({$name}Element::class, compact( | ||
{$compact} | ||
)); | ||
} | ||
} | ||
PHP; | ||
|
||
$filename = __DIR__.'/../src/Components/'.$name.'.php'; | ||
|
||
if (!file_exists($filename)) { | ||
file_put_contents($filename, $code); | ||
echo "Wrote $filename\n"; | ||
} else { | ||
echo "FILE ALREADY EXISTS: $filename\n\n"; | ||
echo $code; | ||
echo "\n\n"; | ||
} | ||
|
||
}); |
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,37 @@ | ||
<?php | ||
|
||
if ($write) { | ||
ob_start(); | ||
} | ||
|
||
echo "<?php\n\n"; | ||
|
||
echo "/**\n"; | ||
echo " * Portions of this code have been generated using Atom autocompletion data.\n"; | ||
echo " *\n"; | ||
echo " * @see https://github.com/atom/autocomplete-html\n"; | ||
echo " *\n"; | ||
echo " * $license_docblock\n"; | ||
echo " *\n"; | ||
echo " */\n\n"; | ||
|
||
echo "namespace Galahad\Aire\Tests\Components;\n\n"; | ||
|
||
echo "use Illuminate\Support\Str;\n\n"; | ||
|
||
echo "class GlobalAttributesTest extends ComponentTestCase\n"; | ||
echo "{\n"; | ||
|
||
foreach ($global_attributes as $attribute => $attribute_config) { | ||
print_setter_test($attribute, $attribute_config, 'form', true); | ||
} | ||
|
||
echo "}\n"; | ||
|
||
if ($write) { | ||
$php = ob_get_clean(); | ||
|
||
$file_path = __DIR__.'/../../tests/Components/GlobalAttributesTest.php'; | ||
file_put_contents($file_path, $php); | ||
echo "Wrote $file_path\n"; | ||
} |
Oops, something went wrong.