Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-ro committed Jul 31, 2023
0 parents commit 522dba8
Show file tree
Hide file tree
Showing 23 changed files with 635 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
19 changes: 19 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/art export-ignore
/docs export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.php_cs.dist.php export-ignore
/psalm.xml export-ignore
/psalm.xml.dist export-ignore
/testbench.yaml export-ignore
/UPGRADING.md export-ignore
/phpstan.neon.dist export-ignore
/phpstan-baseline.neon export-ignore
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.idea
.php_cs
.php_cs.cache
.phpunit.result.cache
build
composer.lock
coverage
docs
phpunit.xml
phpstan.neon
testbench.yaml
vendor
node_modules
.php-cs-fixer.cache
**/.DS_Store
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to `filament-page-blocks` will be documented in this file.

## 1.0.0 - 2023-08-01

- initial release
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Martin Ro <[email protected]>

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.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Block-Based Page Builder for Filament

This is basically a lightweight version of [Z3d0X's](https://github.com/z3d0x) excellent [Filament Fabricator](https://filamentphp.com/plugins/fabricator) Plugin.

It only provides the blocks functionality without layouts, pages, routing, etc.

## Installation

```bash
composer require martin-ro/filament-page-blocks
```

## Creating a block

```bash
php artisan make:page-block
```

## Using blocks in your template

```html
<x-filament-page-blocks::page-blocks :blocks="$page->blocks" />
```
79 changes: 79 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "martin-ro/filament-page-blocks",
"description": "Block-Based Page Builder Skeleton for Filament Apps",
"keywords": [
"martin-ro",
"laravel",
"filament-page-blocks"
],
"homepage": "https://github.com/martin-ro/filament-page-blocks",
"license": "MIT",
"authors": [
{
"name": "Martin Ro",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^8.2",
"filament/filament": "^3.0",
"illuminate/contracts": "^9.0 | ^10.0",
"spatie/laravel-package-tools": "^1.13.5"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"pestphp/pest-plugin-livewire": "^1.0",
"pestphp/pest-plugin-parallel": "^0.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"spatie/laravel-ray": "^1.26"
},
"autoload": {
"psr-4": {
"MartinRo\\FilamentPageBlocks\\": "src/",
"MartinRo\\FilamentPageBlocks\\Database\\Factories\\": "database/factories"
}
},
"autoload-dev": {
"psr-4": {
"MartinRo\\FilamentPageBlocks\\Tests\\": "tests"
}
},
"scripts": {
"pint": "vendor/bin/pint",
"test:pest": "vendor/bin/pest --parallel",
"test:phpstan": "vendor/bin/phpstan analyse",
"test": [
"@test:pest",
"@test:phpstan"
]
},
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"providers": [
"MartinRo\\FilamentPageBlocks\\FilamentPageBlocksServiceProvider"
],
"aliases": {
"FilamentPageBlocks": "MartinRo\\FilamentPageBlocks\\Facades\\FilamentPageBlocks"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Empty file added phpstan-baseline.neon
Empty file.
16 changes: 16 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src
- config
- database
- routes
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

39 changes: 39 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
11 changes: 11 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"preset": "laravel",
"rules": {
"blank_line_before_statement": true,
"concat_space": {
"spacing": "one"
},
"method_argument_space": true,
"single_trait_insert_per_statement": true
}
}
14 changes: 14 additions & 0 deletions resources/views/components/page-blocks.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@props(['blocks' => []])

@foreach ($blocks as $blockData)
@php
$pageBlock = \MartinRo\FilamentPageBlocks\Facades\FilamentPageBlocks::getPageBlockFromName($blockData['type'])
@endphp

@isset($pageBlock)
<x-dynamic-component
:component="$pageBlock::getComponent()"
:attributes="new \Illuminate\View\ComponentAttributeBag($pageBlock::mutateData($blockData['data']))"
/>
@endisset
@endforeach
85 changes: 85 additions & 0 deletions src/Commands/MakePageBlockCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace MartinRo\FilamentPageBlocks\Commands;

use Filament\Support\Commands\Concerns\CanManipulateFiles;
use Filament\Support\Commands\Concerns\CanValidateInput;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class MakePageBlockCommand extends Command
{
use CanManipulateFiles;
use CanValidateInput;

protected $signature = 'make:page-block {name?} {--F|force}';

protected $description = 'Create a new filament page block';

public function handle(): int
{
$pageBlock = (string) Str::of($this->argument('name') ?? $this->askRequired('Name (e.g. `HeroBlock`)', 'name'))
->trim('/')
->trim('\\')
->trim(' ')
->replace('/', '\\');

$pageBlockClass = (string) Str::of($pageBlock)->afterLast('\\');

$pageBlockNamespace = Str::of($pageBlock)->contains('\\') ?
(string) Str::of($pageBlock)->beforeLast('\\') :
'';

$label = Str::of($pageBlock)
->beforeLast('Block')
->explode('\\')
->map(fn ($segment) => Str::title($segment))
->implode(': ');

$shortName = Str::of($pageBlock)
->beforeLast('Block')
->explode('\\')
->map(fn ($segment) => Str::kebab($segment))
->implode('.');

$view = Str::of($pageBlock)
->beforeLast('Block')
->prepend('components\\page-blocks\\')
->explode('\\')
->map(fn ($segment) => Str::kebab($segment))
->implode('.');

$path = app_path(
(string) Str::of($pageBlock)
->prepend('Filament\\PageBlocks\\')
->replace('\\', '/')
->append('.php'),
);

$viewPath = resource_path(
(string) Str::of($view)
->replace('.', '/')
->prepend('views/')
->append('.blade.php'),
);

$files = [$path, $viewPath];

if (! $this->option('force') && $this->checkForCollision($files)) {
return static::INVALID;
}

$this->copyStubToApp('PageBlock', $path, [
'class' => $pageBlockClass,
'namespace' => 'App\\Filament\\PageBlocks'.($pageBlockNamespace !== '' ? "\\{$pageBlockNamespace}" : ''),
'label' => $label,
'shortName' => $shortName,
]);

$this->copyStubToApp('PageBlockView', $viewPath);

$this->info("Successfully created {$pageBlock}!");

return static::SUCCESS;
}
}
40 changes: 40 additions & 0 deletions src/Facades/FilamentPageBlocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace MartinRo\FilamentPageBlocks\Facades;

use Illuminate\Support\Facades\Facade;
use MartinRo\FilamentPageBlocks\Models\Contracts\Page as PageContract;

/**
* @method static void register(string $class, string $baseClass)
* @method static void registerLayout(string $layout)
* @method static void registerPageBlock(string $pageBlock)
* @method static void registerSchemaSlot(string $name, array | \Closure $schema)
* @method static void pushMeta(array $meta)
* @method static void registerScripts(array $scripts)
* @method static void registerStyles(array $styles)
* @method static void favicon(?string $favicon)
* @method static ?string getLayoutFromName(string $layoutName)
* @method static ?string getPageBlockFromName(string $name)
* @method static array getLayouts()
* @method static array getPageBlocks()
* @method static array getPageBlocksRaw()
* @method static array | \Closure getSchemaSlot(string $name)
* @method static array getMeta()
* @method static array getScripts()
* @method static array getStyles()
* @method static ?string getFavicon()
* @method static class-string<PageContract> getPageModel()
* @method static string getRoutingPrefix()
* @method static array getPageUrls()
* @method static ?string getPageUrlFromId(int $id, bool $prefixSlash = false)
*
* @see \MartinRo\FilamentPageBlocks\FilamentPageBlocksManager
*/
class FilamentPageBlocks extends Facade
{
protected static function getFacadeAccessor()
{
return 'filament-page-blocks';
}
}
Loading

0 comments on commit 522dba8

Please sign in to comment.