Skip to content

Commit 8627ff6

Browse files
committed
Merge branch 'release/v0.6.0'
2 parents 4810fd0 + b91131e commit 8627ff6

23 files changed

+4538
-4350
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
/.idea
44
/.vscode
55
/.vagrant
6+
/ray.php
67
.phpunit.result.cache
78

89
/sample-dist
9-
/.proton-cache
10+
/.proton-cache

app/Proton/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function __construct(Command $cmd)
2424
$this->fsManager = new FilesystemManager($this->config);
2525
$this->fsManager->pathChecker();
2626

27-
$data = new Data($this->config);
28-
$this->pageManager = new PageManager($this->config, $data);
27+
$this->data = new Data($this->config);
28+
$this->pageManager = new PageManager($this->config, $this->data);
2929
$this->assetManager = new AssetManager($this->config);
3030
}
3131

app/Proton/Data.php

+25-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ class Data
1212
const DEFAULTDATA = "data";
1313

1414
public array $data = [];
15+
public array $env = [];
1516
public string $dir;
1617

1718
public function __construct(Config $config)
1819
{
1920
$this->dir = $config->settings->paths->data;
20-
$this->initDataFiles();
21+
$this->initData();
2122
}
2223

2324
public function dump(): void
@@ -28,7 +29,21 @@ public function dump(): void
2829
public function refresh(): void
2930
{
3031
$this->data = [];
32+
$this->env = [];
33+
$this->initData();
34+
}
35+
36+
private function initData(): void
37+
{
3138
$this->initDataFiles();
39+
$this->initEnvData();
40+
}
41+
42+
private function initEnvData(): void
43+
{
44+
$this->env = [
45+
'environment' => getenv('PROTON_ENV') ?: 'development',
46+
];
3247
}
3348

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

4055
foreach ($iterator as $file) {
41-
$this->mergeDataFile($file);
56+
// Skip dot files
57+
if (strpos($file->getFilename(), '.') !== 0) {
58+
$this->mergeDataFile($file);
59+
}
4260
}
4361
}
4462

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

82100
public function generatePageData(array $pageData): array
83101
{
84-
return array_merge($this->data, $pageData);
102+
return [
103+
"data" => $this->data,
104+
"proton" => $this->env,
105+
"page" => $pageData,
106+
];
85107
}
86108
}

app/Proton/FilesystemManager.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ public function getAllFiles(string $path): array
3232
// The length of the pages folder name + /
3333
$dirLength = strlen($path)+1;
3434
foreach ($iterator as $info) {
35-
// Remove the pages fodler name from the file name
36-
$files[] = substr_replace($info->getPathname(), '', 0, $dirLength);
35+
// Skip dot files
36+
if (strpos($info->getFilename(), '.') !== 0) {
37+
// Remove the pages fodler name from the file name
38+
$files[] = substr_replace($info->getPathname(), '', 0, $dirLength);
39+
}
3740
}
3841
return $files;
3942
}

app/Proton/Page.php

+27-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Page
1111
const ENDBLOCK = "endblock";
1212
const LAYOUTKEY = "layout";
1313
const BATCHKEY = "batch";
14+
const OUTPUTKEY = "output";
1415

1516
protected Config $config;
1617

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

4243
public function isBatch(): bool
4344
{
44-
return array_key_exists(self::BATCHKEY, $this->data);
45+
return array_key_exists(self::BATCHKEY, $this->data["page"]);
46+
}
47+
48+
public function getPageData($key)
49+
{
50+
if (array_key_exists($key, $this->data["page"])) {
51+
return $this->data["page"][$key];
52+
}
53+
return null;
54+
}
55+
56+
public function getProtonData($key)
57+
{
58+
if (array_key_exists($key, $this->data["proton"])) {
59+
return $this->data["proton"][$key];
60+
}
61+
return null;
62+
}
63+
64+
public function getData($key)
65+
{
66+
if (array_key_exists($key, $this->data["data"])) {
67+
return $this->data["data"][$key];
68+
}
69+
return null;
4570
}
4671

4772
public function dumpData(): void
@@ -69,7 +94,7 @@ private function processPage(Data $data): void
6994
private function applyLayout(): void
7095
{
7196
// Local page Data vs Layout Rules vs Default
72-
$layout = $this->data[self::LAYOUTKEY] ??
97+
$layout = $this->getPageData(self::LAYOUTKEY) ??
7398
$this->findLayoutRule() ??
7499
$this->config->settings->layouts->default;
75100

app/Proton/PageBatchWriter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public function __construct(Page $page, \Twig\Environment $twig, Config $config)
1818

1919
public function processBatch(): void
2020
{
21-
$batchkey = $this->page->data[Page::BATCHKEY];
22-
$batchData = $this->page->data[$batchkey];
21+
$batchkey = $this->page->getPageData(Page::BATCHKEY);
22+
$batchData = $this->page->getData($batchkey);
2323
foreach ($batchData as $key => $props) {
2424
// merge batch data into the global data batch key
2525
$data = $this->page->data;

app/Proton/PageManager.php

+34-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __construct(Config $config, Data $data)
3131
public function compilePages(): void
3232
{
3333
$fsManager = new FilesystemManager($this->config);
34+
// $fsManager->clearCache();
3435
$pages = $fsManager->getAllFiles($this->paths->pages);
3536
foreach ($pages as $pageName) {
3637
$page = new Page($pageName, $this->config, $this->data);
@@ -45,17 +46,49 @@ public function compilePages(): void
4546
}
4647
}
4748

49+
// public function ksort($array)
50+
// {
51+
// ksort($array);
52+
// return $array;
53+
// }
54+
4855
private function createPageLoader(string $pageName, string $content): \Twig\Environment
4956
{
5057
// Create the Twig Chain Loader
5158
$loader = new \Twig\Loader\ArrayLoader(["@pages/$pageName" => $content]);
5259
$loader = new \Twig\Loader\ChainLoader([$loader, $this->templateLoader]);
60+
// $cache = new \Twig\Cache\FilesystemCache(self::CACHEDIR, \Twig\Cache\FilesystemCache::FORCE_BYTECODE_INVALIDATION);
61+
$debug = $this->config->settings->debug;
5362
$twig = new \Twig\Environment($loader, [
5463
'cache' => self::CACHEDIR,
55-
'debug' => $this->config->settings->debug
64+
'debug' => $debug
5665
]);
66+
if ($debug) {
67+
$twig->addExtension(new \Twig\Extension\DebugExtension());
68+
}
5769
// Markdown Support
5870
$twig->addExtension(new MarkdownExtension(new MichelfMarkdownEngine()));
71+
72+
// ksort the twig variables
73+
$filter = new \Twig\TwigFilter('ksort', function ($array) {
74+
ksort($array);
75+
return $array;
76+
});
77+
$twig->addFilter($filter);
78+
79+
// krsort the twig variables
80+
$filter = new \Twig\TwigFilter('krsort', function ($array) {
81+
krsort($array);
82+
return $array;
83+
});
84+
$twig->addFilter($filter);
85+
86+
// count the twig variables
87+
$filter = new \Twig\TwigFilter('count', function ($array) {
88+
return count($array);
89+
});
90+
$twig->addFilter($filter);
91+
5992
return $twig;
6093
}
6194

app/Proton/PageWriter.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//---------------------------------------------------------------------------------
88
class PageWriter
99
{
10-
const OUTPUTKEY = "output";
11-
1210
protected \Twig\Environment $twig;
1311
protected Config $config;
1412
protected Page $page;
@@ -44,6 +42,11 @@ protected function formatOutput(): void
4442
$this->output = $parser->compress($this->output);
4543
} elseif ($this->config->settings->pretty) {
4644
$indenter = new \Gajus\Dindent\Indenter();
45+
// Set headers to inline style for nicer pretty output
46+
$inline = ["h1", "h2", "h3", "h4", "h5", "h6"];
47+
foreach ($inline as $tag) {
48+
$indenter->setElementType($tag, \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE);
49+
}
4750
$this->output = $indenter->indent($this->output);
4851
}
4952
}
@@ -57,8 +60,9 @@ protected function render(array $data): string
5760
protected function buildPagePath(): string
5861
{
5962
// If output name defined in page data, return that
60-
if (array_key_exists(self::OUTPUTKEY, $this->page->data)) {
61-
return $this->page->data[self::OUTPUTKEY];
63+
$name = $this->page->getPageData(Page::OUTPUTKEY);
64+
if ($name) {
65+
return $name;
6266
}
6367

6468
$filePath = [];

app/Proton/Watch.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Watch
1717
const EVENT_TYPE_FILE_DELETED = 'fileDeleted';
1818
const EVENT_TYPE_DIRECTORY_CREATED = 'directoryCreated';
1919
const EVENT_TYPE_DIRECTORY_DELETED = 'directoryDeleted';
20+
protected int $interval = 500 * 1000;
2021

2122
protected array $paths = [];
2223

@@ -108,6 +109,13 @@ public function onAnyChange(callable $callable): self
108109
return $this;
109110
}
110111

112+
public function setIntervalTime(int $interval): self
113+
{
114+
$this->interval = $interval;
115+
116+
return $this;
117+
}
118+
111119
public function shouldContinue(Closure $shouldContinue): self
112120
{
113121
$this->shouldContinue = $shouldContinue;
@@ -132,7 +140,7 @@ public function start(): void
132140
break;
133141
}
134142

135-
usleep(500 * 1000);
143+
usleep($this->interval);
136144
}
137145
}
138146

builds/proton

325 KB
Binary file not shown.

composer.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.3|^8.0",
19+
"php": "^8.0",
2020
"aptoma/twig-markdown": "^3.4",
2121
"gajus/dindent": "^2.0",
2222
"laravel-zero/phar-updater": "^1.0.6",
2323
"michelf/php-markdown": "^1.9",
2424
"pug/twig": "^1.2",
2525
"samdark/sitemap": "^2.4",
26-
"spatie/file-system-watcher": "^1.0",
26+
"spatie/file-system-watcher": "^1.1",
27+
"spatie/ray": "^1.32",
2728
"twig/twig": "^3.3",
2829
"webuni/front-matter": "^1.3",
2930
"wyrihaximus/html-compress": "^4.1"
3031
},
3132
"require-dev": {
32-
"laravel-zero/framework": "^8.8",
33+
"laravel-zero/framework": "^9.1",
3334
"mockery/mockery": "^1.4.3",
3435
"pestphp/pest": "^1.3"
3536
},
@@ -46,7 +47,10 @@
4647
"config": {
4748
"preferred-install": "dist",
4849
"sort-packages": true,
49-
"optimize-autoloader": true
50+
"optimize-autoloader": true,
51+
"allow-plugins": {
52+
"pestphp/pest-plugin": true
53+
}
5054
},
5155
"minimum-stability": "dev",
5256
"prefer-stable": true,

0 commit comments

Comments
 (0)