-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2ca9d7
commit 81b1f79
Showing
9 changed files
with
238 additions
and
54 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
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 |
---|---|---|
@@ -1,56 +1,64 @@ | ||
{ | ||
"name": "hi-folks/fusion", | ||
"description": "Empowering Markdown and Frontmatter for Structured, Database-free Content Management", | ||
"keywords": [ | ||
"hi-folks", | ||
"fusion", | ||
"markdown", | ||
"eloquent", | ||
"laravel" | ||
], | ||
"homepage": "https://github.com/hi-folks/fusion", | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Roberto B", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.2|^8.3", | ||
"illuminate/support": "^11.0" | ||
}, | ||
"require-dev": { | ||
"orchestra/testbench": "^9.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"HiFolks\\Fusion\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"HiFolks\\Fusion\\Tests\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit", | ||
"test-coverage": "vendor/bin/phpunit --coverage-html coverage" | ||
|
||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"HiFolks\\Fusion\\FusionServiceProvider" | ||
], | ||
"aliases": { | ||
"Fusion": "HiFolks\\Fusion\\FusionFacade" | ||
} | ||
} | ||
"name": "hi-folks/fusion", | ||
"description": "Laravel package that enhances Eloquent models to facilitate the management of structured, database-free content through Markdown files with Frontmatter.", | ||
"keywords": [ | ||
"hi-folks", | ||
"fusion", | ||
"markdown", | ||
"eloquent", | ||
"laravel" | ||
], | ||
"homepage": "https://github.com/hi-folks/fusion", | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Roberto B", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.2|^8.3", | ||
"illuminate/support": "^11.0", | ||
"calebporzio/sushi": "^2.5", | ||
"league/commonmark": "^2.4", | ||
"spatie/yaml-front-matter": "^2.0" | ||
}, | ||
"require-dev": { | ||
"laravel/pint": "^1.13", | ||
"orchestra/testbench": "^9.0", | ||
"pestphp/pest": "^2.34" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"HiFolks\\Fusion\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"HiFolks\\Fusion\\Tests\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"style-fix": "vendor/bin/pint", | ||
"test": "vendor/bin/pest", | ||
"test-coverage": "vendor/bin/pest coverage" | ||
}, | ||
"config": { | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"pestphp/pest-plugin": true | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"HiFolks\\Fusion\\FusionServiceProvider" | ||
], | ||
"aliases": { | ||
"Fusion": "HiFolks\\Fusion\\FusionFacade" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
*/ | ||
return [ | ||
|
||
]; | ||
]; |
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./app</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
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,90 @@ | ||
<?php | ||
|
||
namespace HiFolks\Fusion\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Filesystem\Filesystem; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\File; | ||
use Illuminate\Support\Str; | ||
use League\CommonMark\Environment\Environment; | ||
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; | ||
use League\CommonMark\MarkdownConverter; | ||
use Spatie\YamlFrontMatter\YamlFrontMatter; | ||
|
||
abstract class FusionBaseModel extends Model | ||
{ | ||
public function getResourceFolder(): string | ||
{ | ||
|
||
$folderName = str_replace( | ||
'App\\Models\\', | ||
'', | ||
get_called_class() | ||
); | ||
$folderName = Str::snake($folderName); | ||
|
||
return 'content'.DIRECTORY_SEPARATOR.$folderName; | ||
} | ||
|
||
public function getRouteKeyName() | ||
{ | ||
return 'slug'; | ||
} | ||
|
||
public function frontmatterFields(): array | ||
{ | ||
return [ | ||
'title', | ||
]; | ||
} | ||
|
||
public function getRows() | ||
{ | ||
return $this->getFrontmatterRows( | ||
$this->frontmatterFields() | ||
); | ||
} | ||
|
||
public function getFrontmatterRows($columns = []) | ||
{ | ||
|
||
$environment = (new Environment()) | ||
->addExtension(new CommonMarkCoreExtension()); | ||
$converter = new MarkdownConverter($environment); | ||
|
||
$filesystem = new FileSystem(); | ||
$markdowns = []; | ||
|
||
foreach (File::allFiles(resource_path($this->getResourceFolder())) as $file) { | ||
$slug = $file->getFilenameWithoutExtension(); | ||
|
||
$filename = $file->getRelativePathName(); | ||
$fileContent = $filesystem->get($file->getRealPath()); | ||
|
||
$object = YamlFrontMatter::parse($fileContent); | ||
|
||
$row = [ | ||
'title' => $object->matter('title'), | ||
'label' => $object->matter('label'), | ||
'excerpt' => $object->matter('excerpt'), | ||
'date' => Carbon::createFromTimestamp($object->matter('date'))->format('Y-m-d'), | ||
'slug' => $slug, | ||
'body' => $converter->convert($object->body()), | ||
'real_path' => $file->getRealPath(), | ||
'relative_path_name' => $file->getRelativePathname(), | ||
'published' => $object->matter('published'), | ||
'highlight' => $object->matter('highlight'), | ||
|
||
]; | ||
|
||
foreach ($columns as $column) { | ||
$row[$column] = $object->matter($column); | ||
} | ||
|
||
$markdowns[] = $row; | ||
} | ||
|
||
return $markdowns; | ||
} | ||
} |
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,5 @@ | ||
<?php | ||
|
||
test('example', function () { | ||
expect(true)->toBeTrue(); | ||
}); |
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,45 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The closure you provide to your test functions is always bound to a specific PHPUnit test | ||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may | ||
| need to change it using the "uses()" function to bind a different classes or traits. | ||
| | ||
*/ | ||
|
||
// uses(Tests\TestCase::class)->in('Feature'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Expectations | ||
|-------------------------------------------------------------------------- | ||
| | ||
| When you're writing tests, you often need to check that values meet certain conditions. The | ||
| "expect()" function gives you access to a set of "expectations" methods that you can use | ||
| to assert different things. Of course, you may extend the Expectation API at any time. | ||
| | ||
*/ | ||
|
||
expect()->extend('toBeOne', function () { | ||
return $this->toBe(1); | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Functions | ||
|-------------------------------------------------------------------------- | ||
| | ||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your | ||
| project that you don't want to repeat in every file. Here you can also expose helpers as | ||
| global functions to help you to reduce the number of lines of code in your test files. | ||
| | ||
*/ | ||
|
||
function something() | ||
{ | ||
// .. | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use PHPUnit\Framework\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
// | ||
} |
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,5 @@ | ||
<?php | ||
|
||
test('example', function () { | ||
expect(true)->toBeTrue(); | ||
}); |