X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FLayoutSet.pm;h=77a0dac663c38ad922b0a733d9ac4dd6a9cac0bf;hb=13427367a812499857225b741a6aec2a15194aba;hp=792bb701036de91e695d631a1c1b1d1f248177c8;hpb=cb92a3a388a813d1309757155a4b7750eb9f5504;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/LayoutSet.pm b/lib/Reaction/UI/LayoutSet.pm index 792bb70..77a0dac 100644 --- a/lib/Reaction/UI/LayoutSet.pm +++ b/lib/Reaction/UI/LayoutSet.pm @@ -9,36 +9,23 @@ class LayoutSet which { 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 'source_file' => (is => 'ro', required => 1); has 'widget_class' => ( is => 'rw', lazy_fail => 1, predicate => 'has_widget_class' ); - has 'super' => (is => 'rw', predicate => 'has_super'); + has 'widget_type' => (is => 'rw', lazy_build => 1); - implements _build_file_extension => as { 'html' }; + has 'super' => (is => 'rw', predicate => 'has_super'); implements 'BUILD' => as { my ($self, $args) = @_; my @path = @{$args->{search_path}||[]}; - confess "No search_path provided" unless @path; - confess "No view object provided" unless $args->{view}; - my $found; - my $ext = $self->file_extension; - SEARCH: foreach my $path (@path) { - my $cand = $path->file($self->name . ".${ext}"); - #print STDERR $cand,"\n"; - if ($cand->stat) { - $self->_load_file($cand, $args); - $found = 1; - last SEARCH; - } - } - confess "Unable to load file for LayoutSet ".$self->name unless $found; + confess "No skin object provided" unless $args->{skin}; + $self->_load_file($self->source_file, $args); unless ($self->has_widget_class) { - $self->widget_class($args->{view}->widget_class_for($self)); + $self->widget_class($args->{skin}->widget_class_for($self)); } }; @@ -80,23 +67,33 @@ class LayoutSet which { my ($data, $text) = ($1, $2); if ($data =~ /^for layout (\S+)/) { my $fname = $1; - #remove extra whitespace without killing indentation - #remove all empty leading lines. and trailing whitespace - ($layouts->{$fname}) = - ($text =~ /^(?:\s*\n)*((?:.*?\n)*(?:.*?\S+.*?\n))\s*$/m); + $text =~ s/^(?:\s*\r?\n)+//; #remove leading empty lines + $text =~ s/[\s\r\n]+$//; #remove trailing whitespace + $layouts->{$fname} = $text; } elsif ($data =~ /^extends (\S+)/) { my $super_name = $1; - $self->super($build_args->{view}->create_layout_set($super_name)) + my $skin; + if ($super_name eq 'NEXT') { + confess "No next skin and layout extends NEXT" + unless $build_args->{next_skin}; + $skin = $build_args->{next_skin}; + $super_name = $self->name; + } else { + $skin = $build_args->{skin}; + } + $self->super($skin->create_layout_set($super_name)); + } elsif ($data =~ /^widget (\S+)/) { + my $widget_type = $1; + $self->widget_type($1); } elsif ($data =~ /^cut/) { # no-op } else { confess "Unparseable directive ${data}"; } } - $self->source_file($file); }; - implements 'widget_type' => as { + implements '_build_widget_type' => as { my ($self) = @_; my $widget = join('', map { ucfirst($_) } split('_', $self->name)); $widget = join('::', map { ucfirst($_) } split('/', $widget));