Skip to content

Commit

Permalink
Merge branch 'release/v0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
joeworkman committed Jun 17, 2022
2 parents 4810fd0 + b91131e commit 8627ff6
Show file tree
Hide file tree
Showing 23 changed files with 4,538 additions and 4,350 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/.idea
/.vscode
/.vagrant
/ray.php
.phpunit.result.cache

/sample-dist
/.proton-cache
/.proton-cache
4 changes: 2 additions & 2 deletions app/Proton/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function __construct(Command $cmd)
$this->fsManager = new FilesystemManager($this->config);
$this->fsManager->pathChecker();

$data = new Data($this->config);
$this->pageManager = new PageManager($this->config, $data);
$this->data = new Data($this->config);
$this->pageManager = new PageManager($this->config, $this->data);
$this->assetManager = new AssetManager($this->config);
}

Expand Down
28 changes: 25 additions & 3 deletions app/Proton/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ class Data
const DEFAULTDATA = "data";

public array $data = [];
public array $env = [];
public string $dir;

public function __construct(Config $config)
{
$this->dir = $config->settings->paths->data;
$this->initDataFiles();
$this->initData();
}

public function dump(): void
Expand All @@ -28,7 +29,21 @@ public function dump(): void
public function refresh(): void
{
$this->data = [];
$this->env = [];
$this->initData();
}

private function initData(): void
{
$this->initDataFiles();
$this->initEnvData();
}

private function initEnvData(): void
{
$this->env = [
'environment' => getenv('PROTON_ENV') ?: 'development',
];
}

private function initDataFiles(): void
Expand All @@ -38,7 +53,10 @@ private function initDataFiles(): void
$iterator = new \RecursiveIteratorIterator($directory);

foreach ($iterator as $file) {
$this->mergeDataFile($file);
// Skip dot files
if (strpos($file->getFilename(), '.') !== 0) {
$this->mergeDataFile($file);
}
}
}

Expand Down Expand Up @@ -81,6 +99,10 @@ public function getDataPath(\SplFileInfo $file): string

public function generatePageData(array $pageData): array
{
return array_merge($this->data, $pageData);
return [
"data" => $this->data,
"proton" => $this->env,
"page" => $pageData,
];
}
}
7 changes: 5 additions & 2 deletions app/Proton/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public function getAllFiles(string $path): array
// The length of the pages folder name + /
$dirLength = strlen($path)+1;
foreach ($iterator as $info) {
// Remove the pages fodler name from the file name
$files[] = substr_replace($info->getPathname(), '', 0, $dirLength);
// Skip dot files
if (strpos($info->getFilename(), '.') !== 0) {
// Remove the pages fodler name from the file name
$files[] = substr_replace($info->getPathname(), '', 0, $dirLength);
}
}
return $files;
}
Expand Down
29 changes: 27 additions & 2 deletions app/Proton/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Page
const ENDBLOCK = "endblock";
const LAYOUTKEY = "layout";
const BATCHKEY = "batch";
const OUTPUTKEY = "output";

protected Config $config;

Expand Down Expand Up @@ -41,7 +42,31 @@ public function __construct(string $name, Config $config, Data $data)

public function isBatch(): bool
{
return array_key_exists(self::BATCHKEY, $this->data);
return array_key_exists(self::BATCHKEY, $this->data["page"]);
}

public function getPageData($key)
{
if (array_key_exists($key, $this->data["page"])) {
return $this->data["page"][$key];
}
return null;
}

public function getProtonData($key)
{
if (array_key_exists($key, $this->data["proton"])) {
return $this->data["proton"][$key];
}
return null;
}

public function getData($key)
{
if (array_key_exists($key, $this->data["data"])) {
return $this->data["data"][$key];
}
return null;
}

public function dumpData(): void
Expand Down Expand Up @@ -69,7 +94,7 @@ private function processPage(Data $data): void
private function applyLayout(): void
{
// Local page Data vs Layout Rules vs Default
$layout = $this->data[self::LAYOUTKEY] ??
$layout = $this->getPageData(self::LAYOUTKEY) ??
$this->findLayoutRule() ??
$this->config->settings->layouts->default;

Expand Down
4 changes: 2 additions & 2 deletions app/Proton/PageBatchWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function __construct(Page $page, \Twig\Environment $twig, Config $config)

public function processBatch(): void
{
$batchkey = $this->page->data[Page::BATCHKEY];
$batchData = $this->page->data[$batchkey];
$batchkey = $this->page->getPageData(Page::BATCHKEY);
$batchData = $this->page->getData($batchkey);
foreach ($batchData as $key => $props) {
// merge batch data into the global data batch key
$data = $this->page->data;
Expand Down
35 changes: 34 additions & 1 deletion app/Proton/PageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(Config $config, Data $data)
public function compilePages(): void
{
$fsManager = new FilesystemManager($this->config);
// $fsManager->clearCache();
$pages = $fsManager->getAllFiles($this->paths->pages);
foreach ($pages as $pageName) {
$page = new Page($pageName, $this->config, $this->data);
Expand All @@ -45,17 +46,49 @@ public function compilePages(): void
}
}

// public function ksort($array)
// {
// ksort($array);
// return $array;
// }

private function createPageLoader(string $pageName, string $content): \Twig\Environment
{
// Create the Twig Chain Loader
$loader = new \Twig\Loader\ArrayLoader(["@pages/$pageName" => $content]);
$loader = new \Twig\Loader\ChainLoader([$loader, $this->templateLoader]);
// $cache = new \Twig\Cache\FilesystemCache(self::CACHEDIR, \Twig\Cache\FilesystemCache::FORCE_BYTECODE_INVALIDATION);
$debug = $this->config->settings->debug;
$twig = new \Twig\Environment($loader, [
'cache' => self::CACHEDIR,
'debug' => $this->config->settings->debug
'debug' => $debug
]);
if ($debug) {
$twig->addExtension(new \Twig\Extension\DebugExtension());
}
// Markdown Support
$twig->addExtension(new MarkdownExtension(new MichelfMarkdownEngine()));

// ksort the twig variables
$filter = new \Twig\TwigFilter('ksort', function ($array) {
ksort($array);
return $array;
});
$twig->addFilter($filter);

// krsort the twig variables
$filter = new \Twig\TwigFilter('krsort', function ($array) {
krsort($array);
return $array;
});
$twig->addFilter($filter);

// count the twig variables
$filter = new \Twig\TwigFilter('count', function ($array) {
return count($array);
});
$twig->addFilter($filter);

return $twig;
}

Expand Down
12 changes: 8 additions & 4 deletions app/Proton/PageWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
//---------------------------------------------------------------------------------
class PageWriter
{
const OUTPUTKEY = "output";

protected \Twig\Environment $twig;
protected Config $config;
protected Page $page;
Expand Down Expand Up @@ -44,6 +42,11 @@ protected function formatOutput(): void
$this->output = $parser->compress($this->output);
} elseif ($this->config->settings->pretty) {
$indenter = new \Gajus\Dindent\Indenter();
// Set headers to inline style for nicer pretty output
$inline = ["h1", "h2", "h3", "h4", "h5", "h6"];
foreach ($inline as $tag) {
$indenter->setElementType($tag, \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE);
}
$this->output = $indenter->indent($this->output);
}
}
Expand All @@ -57,8 +60,9 @@ protected function render(array $data): string
protected function buildPagePath(): string
{
// If output name defined in page data, return that
if (array_key_exists(self::OUTPUTKEY, $this->page->data)) {
return $this->page->data[self::OUTPUTKEY];
$name = $this->page->getPageData(Page::OUTPUTKEY);
if ($name) {
return $name;
}

$filePath = [];
Expand Down
10 changes: 9 additions & 1 deletion app/Proton/Watch.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Watch
const EVENT_TYPE_FILE_DELETED = 'fileDeleted';
const EVENT_TYPE_DIRECTORY_CREATED = 'directoryCreated';
const EVENT_TYPE_DIRECTORY_DELETED = 'directoryDeleted';
protected int $interval = 500 * 1000;

protected array $paths = [];

Expand Down Expand Up @@ -108,6 +109,13 @@ public function onAnyChange(callable $callable): self
return $this;
}

public function setIntervalTime(int $interval): self
{
$this->interval = $interval;

return $this;
}

public function shouldContinue(Closure $shouldContinue): self
{
$this->shouldContinue = $shouldContinue;
Expand All @@ -132,7 +140,7 @@ public function start(): void
break;
}

usleep(500 * 1000);
usleep($this->interval);
}
}

Expand Down
Binary file modified builds/proton
Binary file not shown.
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
}
],
"require": {
"php": "^7.3|^8.0",
"php": "^8.0",
"aptoma/twig-markdown": "^3.4",
"gajus/dindent": "^2.0",
"laravel-zero/phar-updater": "^1.0.6",
"michelf/php-markdown": "^1.9",
"pug/twig": "^1.2",
"samdark/sitemap": "^2.4",
"spatie/file-system-watcher": "^1.0",
"spatie/file-system-watcher": "^1.1",
"spatie/ray": "^1.32",
"twig/twig": "^3.3",
"webuni/front-matter": "^1.3",
"wyrihaximus/html-compress": "^4.1"
},
"require-dev": {
"laravel-zero/framework": "^8.8",
"laravel-zero/framework": "^9.1",
"mockery/mockery": "^1.4.3",
"pestphp/pest": "^1.3"
},
Expand All @@ -46,7 +47,10 @@
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
"optimize-autoloader": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
Loading

0 comments on commit 8627ff6

Please sign in to comment.