From 8d22132ef515a0b6efc1ee0bc1d5736f9925cd9c Mon Sep 17 00:00:00 2001
From: Dave Mc Nicoll <info@mcnd.ca>
Date: Thu, 12 Oct 2023 12:52:34 -0400
Subject: [PATCH] - WIP on picea asset

---
 meta/definitions/template.php | 11 ++++++-----
 src/Application.php           |  6 ++++++
 src/Lean.php                  | 13 +++++++++++++
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/meta/definitions/template.php b/meta/definitions/template.php
index ea13690..ba0961f 100644
--- a/meta/definitions/template.php
+++ b/meta/definitions/template.php
@@ -15,7 +15,7 @@ return [
     },
 
     Context::class => function($c) {
-        return new BaseContext( $c->get(Lean\Lean::class)->getPiceaContext() );
+        return new BaseContext($c->get(Lean\Lean::class)->getPiceaContext());
     },
 
     Compiler::class => function($c) {
@@ -33,14 +33,15 @@ return [
             public function registerAll(Compiler $compiler) : void
             {
                 parent::registerAll($compiler);
-                ( new Ui() )->registerFormExtension($compiler);
 
-                if ( class_exists('Picea\\Asset\\Asset') ) {
+                if (class_exists(Ui::class)) {
+                    ( new Ui() )->registerFormExtension($compiler);
+                }
+
+                if (class_exists(Asset::class)) {
                     ( new Asset() )->registerExtension($compiler);
-
                 }
             }
-
         });
     },
 
diff --git a/src/Application.php b/src/Application.php
index 2fdf4f6..1b0cec1 100644
--- a/src/Application.php
+++ b/src/Application.php
@@ -12,6 +12,8 @@ class Application
 
     public array $piceaExtensions;
 
+    public array $piceaAssets;
+
     public array $views;
 
     public array $routes;
@@ -47,6 +49,10 @@ class Application
                 $this->piceaExtensions = $picea['extensions'];
             }
 
+            if ($picea['asset'] ?? false ) {
+                $this->piceaAssets = $picea['asset'];
+            }
+
             if ($picea['view'] ?? false) {
                 $this->views = $picea['view'];
             }
diff --git a/src/Lean.php b/src/Lean.php
index 7e3dc77..e0cdfef 100644
--- a/src/Lean.php
+++ b/src/Lean.php
@@ -73,6 +73,19 @@ class Lean
         return $list;
     }
 
+    public function getPiceaAssets() : array
+    {
+        $list = [];
+
+        foreach(array_reverse($this->applications) as $apps) {
+            if ( $apps->piceaAssets ?? null ) {
+                $list = array_merge_recursive($list, $apps->piceaAssets);
+            }
+        }
+# dump($list);
+        return $list;
+    }
+
     public function getRoutable() : array
     {
         return array_merge(...array_map(fn($app) => $app->routes ?? [], $this->applications));