--- trunk/lib/Frey/ClassBrowser.pm 2008/11/26 07:57:12 532 +++ trunk/lib/Frey/Class/Browser.pm 2008/12/10 17:51:32 794 @@ -1,9 +1,10 @@ -package Frey::ClassBrowser; +package Frey::Class::Browser; use Moose; extends 'Frey::ClassLoader'; with 'Frey::Web'; with 'Frey::Session'; +with 'Frey::Web::CombineImages'; use Frey::Run; use Data::Dump qw/dump/; @@ -15,20 +16,29 @@ documentation => 'Show usage on top of list', ); +our $usage; + sub as_markup { my $self = shift; my $row; + my @icons; - my $usage = $self->session_dump( $self->usage ); + $usage ||= $self->session_dump( $self->usage ); #warn "# usage ",dump( $usage ); + + if ( ! $self->can('icon_path') ) { + $self->TODO( "re-apply Frey::Web on $self" ); + Frey::Web->meta->apply( $self ); + } + foreach my $class ( $self->classes ) { - my $icon = ''; - if ( $self->can('icon_path') ) { - $icon = $self->icon_path( $class ); - $icon = qq|$class| if $icon; + my $icon = $self->icon_path( $class ); + if ($icon) { + push @icons, $icon; + $icon = qq||; } else { - #warn "## $self doesn't know how to return icon_path"; + $icon = ''; } my $html @@ -45,8 +55,10 @@ } my @run = map { + my $invoke = $_; s{^as_}{}; - qq|$_|; + s{_as_\w+}{}; + qq|$_|; } $self->class_runnable( $class ); push @run, qq|collection| if $class->can('collection_table'); @@ -65,18 +77,26 @@ $row->{$class} = $html; } + my $icons_html = $self->combine_images( @icons ); + sub icon { + my ($icons_html,$path) = @_; + $icons_html->{ $path } || die "can't find $path in ",dump($icons_html); + }; + + $self->title('Frey'); + return qq|| . join("\n", - map { $row->{$_} } + map { + my $html = $row->{$_}; + $html =~ s{}{icon($icons_html,$1)}gse; + $html; + } sort { if ( $usage->{$a} || $usage->{$b} ) { - if ( $self->usage_on_top ) { - $usage->{$b} <=> $usage->{$a}; - } else { - $usage->{$a} <=> $usage->{$b}; - } + $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b}; } else { - $a cmp $b; + $self->usage_on_top ? $a cmp $b : $b cmp $a; } } keys %$row