PluginProbe
WindPress – Tailwind CSS integration for WordPress / trunk
WindPress – Tailwind CSS integration for WordPress vtrunk
3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 All 142 releases
windpress / src / Integration / Timber / Compile.php

Compile.php in WindPress – Tailwind CSS integration for WordPress trunk, at src/Integration/Timber/Compile.php

51 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the WindPress package.
5 *
6 * (c) Joshua Gugun Siagian <suabahasa@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 declare (strict_types=1);
12 namespace WindPress\WindPress\Integration\Timber;
13
14 use WindPressDeps\Symfony\Component\Finder\Finder;
15 use Timber\LocationManager;
16 use Timber\Timber;
17 /**
18 * @author Joshua Gugun Siagian <suabahasa@gmail.com>
19 */
20 class Compile
21 {
22 /**
23 * @param array $metadata
24 */
25 public function __invoke($metadata): array
26 {
27 if (!class_exists(Timber::class)) {
28 return [];
29 }
30 return $this->get_contents($metadata);
31 }
32 public function get_contents($metadata): array
33 {
34 $contents = [];
35 $paths = LocationManager::get_locations();
36 $paths = array_unique(array_filter(array_merge(...array_values($paths)), fn($path) => $path !== '/'));
37 $finder = new Finder();
38 $finder->in($paths);
39 $finder->files()->name('*.twig');
40 do_action('a!windpress/integration/timber/compile:get_contents.finder', $finder);
41 foreach ($finder as $file) {
42 $template_file = $file->getPathname();
43 if (!is_readable($template_file)) {
44 continue;
45 }
46 $contents[] = ['name' => $file->getRelativePathname(), 'content' => $file->getContents()];
47 }
48 return ['metadata' => ['next_batch' => \false, 'total_batches' => 1], 'contents' => $contents];
49 }
50 }
51