1
0
cms11/app/Classes/Traits/ManagesMarkdown.php

69 lines
1.5 KiB
PHP
Raw Normal View History

2024-04-17 11:41:10 +02:00
<?php
namespace App\Classes\Traits;
use App\Classes\MarkdownManager;
trait ManagesMarkdown
{
private array $markdownManagers = [];
/**
* Return an instance of markdown manager for specified filename
*/
public function markdown(?string $filename = 'index'): MarkdownManager
{
return $this->registerMarkdownManager($filename);
}
2024-04-17 11:41:10 +02:00
/**
* Register a markdown manager for specified filename
*/
private function registerMarkdownManager(string $filename): MarkdownManager
{
$filename = $this->getFilenameInBundle($filename, '.md');
if (!array_key_exists($filename, $this->markdownManagers)) {
$this->markdownManagers[$filename] = new MarkdownManager($filename, $this);
2024-04-17 11:41:10 +02:00
}
return $this->markdownManagers[$filename];
}
/**
* Load all markdown files at once
*/
private function loadMarkdown()
{
foreach ($this->markdownManagers as $manager) {
$manager->load();
}
}
2024-04-17 11:41:10 +02:00
/**
* Save all markdown files that needs to be
*/
private function saveMarkdown()
{
$oneSaved = false;
2024-04-26 23:05:49 +02:00
2024-04-17 11:41:10 +02:00
foreach ($this->markdownManagers as $manager) {
if ($manager->save()) {
$oneSaved = true;
2024-04-26 23:05:49 +02:00
}
2024-04-17 11:41:10 +02:00
}
2024-04-26 23:05:49 +02:00
return $oneSaved;
2024-04-17 11:41:10 +02:00
}
/**
* Lint all markdowns in the bundle
2024-04-17 11:41:10 +02:00
*/
private function lintMarkdown()
2024-04-17 11:41:10 +02:00
{
foreach ($this->markdownManagers as $manager) {
$manager->lint();
}
2024-04-17 11:41:10 +02:00
}
}