root of componentUI renders
[catagits/Reaction.git] / lib / Reaction / UI / LayoutSet.pm
index 639af3b..68d23d1 100644 (file)
@@ -5,13 +5,15 @@ use File::Spec;
 
 class LayoutSet which {
 
-  has 'fragments' => (is => 'ro', default => sub { {} });
+  has 'layouts' => (is => 'ro', default => sub { {} });
 
   has 'name' => (is => 'ro', required => 1);
 
   has 'source_file' => (is => 'rw', lazy_fail => 1);
   has 'file_extension'=> (isa => 'Str', is => 'rw', lazy_build => 1);
 
+  has 'widget_class' => (is => 'rw', lazy_fail => 1);
+
   implements _build_file_extension => as { 'html' };
 
   implements 'BUILD' => as {
@@ -30,19 +32,34 @@ class LayoutSet which {
       }
     }
     confess "Unable to load file for LayoutSet ".$self->name unless $found;
+    confess "No view object provided" unless $args->{view};
+    $self->widget_class($args->{view}->widget_class_for($self));
+  };
+
+  implements 'widget_order_for' => as {
+    my ($self, $name) = @_;
+    if ($self->has_layout($name)) {
+      return ([ $self->widget_class, $self ]);
+    } else {
+      return ();
+    }
   };
 
+  implements 'layout_names' => as { [ keys %{shift->layouts} ] };
+
+  implements 'has_layout' => as { exists $_[0]->layouts->{$_[1]} };
+
   implements '_load_file' => as {
     my ($self, $file) = @_;
     my $data = $file->slurp;
-    my $fragments = $self->fragments;
-    # cheesy match for "=for layout fragmentname ... =something"
+    my $layouts = $self->layouts;
+    # cheesy match for "=for layout name ... =something"
     # final split group also handles last in file, (?==) is lookahead
-    # assertion for '=' so "=for layout fragment1 ... =for layout fragment2"
-    # doesn't have the match pos go past the latter = and lose fragment2
+    # assertion for '=' so "=for layout name1 ... =for layout name2"
+    # doesn't have the match pos go past the latter = and lose name2
     while ($data =~ m/=for layout (.*?)\n(.+?)(?:\n(?==)|$)/sg) {
       my ($fname, $text) = ($1, $2);
-      $fragments->{$fname} = $text;
+      $layouts->{$fname} = $text;
     }
     $self->source_file($file);
   };