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

Commit

Permalink
🐛 a modified partial now updates all lnc-files as it should
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Feb 5, 2020
1 parent 30c9701 commit daf7a54
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
11 changes: 11 additions & 0 deletions classes/LncFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,23 @@ public function read(array $data)
$data['needsUpdate'] = false;
if ($target && F::exists($target) === false) {
$data['needsUpdate'] = true;
} elseif ($source && F::exists($target) && F::modified($source) > F::modified($target)) {
$data['needsUpdate'] = true;
} elseif ($source && F::modified($source) !== $data['modified']) {
$data['needsUpdate'] = true;
}

return $data;
}

public function writePartial()
{
if ($this->partial()) {
$this->data['needsUpdate'] = false;
F::write($this->target(), ''); // touch
}
}

/**
* @param string|null $php
* @return string|null
Expand All @@ -125,6 +135,7 @@ public function php(string $php = null): ?string
// write
if ($this->target() && A::get($this->data, 'lnc')) {
F::write($this->target(), $php);
$this->data['needsUpdate'] = false;
}
}

Expand Down
25 changes: 21 additions & 4 deletions classes/LncFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@

final class LncFiles
{
/*
/**
* @var array
*/
private $files;

/**
* @var string
*/
private $modified;

/**
* LncFiles constructor.
* @param array $options
Expand Down Expand Up @@ -115,6 +120,9 @@ public function filterDirByExtension(string $dir, string $extension)
*/
public function modified(array $files = []): string
{
if ($this->modified) {
return $this->modified;
}
if (count($files) === 0) {
$files = array_merge(
$this->filterDirByExtension(
Expand All @@ -133,7 +141,8 @@ public function modified(array $files = []): string
$modified[] = F::modified($file);
}

return strval(crc32(implode($modified)));
$this->modified = strval(crc32(implode($modified)));
return $this->modified;
}

/**
Expand Down Expand Up @@ -222,7 +231,7 @@ public function load()
return $files;
}

return $files = $this->scan();
return $this->scan();
}

/**
Expand All @@ -249,8 +258,16 @@ public function registerAllTemplates(): array
{
$this->files = $this->load();

$anyPartialNeedsUpdate = false;
foreach ($this->files as $lncFile) {
if ($lncFile->partial() && $lncFile->needsUpdate()) {
$anyPartialNeedsUpdate = true;
$lncFile->writePartial();
}
}

foreach ($this->files as $lncFile) {
if ($lncFile->needsUpdate() && !$lncFile->partial()) {
if (!$lncFile->partial() && ($anyPartialNeedsUpdate || $lncFile->needsUpdate())) {
$lncFile->php($this->compile($lncFile));
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-handlebars",
"type": "kirby-plugin",
"version": "3.0.10",
"version": "3.1.0",
"license": "MIT",
"description": "Kirby 3 Component for semantic templates with Handlebars and Mustache",
"authors": [
Expand Down

0 comments on commit daf7a54

Please sign in to comment.