X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FLayoutSet.pm;h=68d23d1d1e256a21c669cb41b2f32722743f01f9;hb=f2fef590a7283ea919bdaa51bac9d433e8785a09;hp=639af3b537ce4e3edda90a44ab39739ee61664de;hpb=89939ff9e89dbee9a8e4e7b8a5614f1fff0a74ae;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/LayoutSet.pm b/lib/Reaction/UI/LayoutSet.pm index 639af3b..68d23d1 100644 --- a/lib/Reaction/UI/LayoutSet.pm +++ b/lib/Reaction/UI/LayoutSet.pm @@ -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); };