/[Frey]/trunk/lib/Frey/IconBrowser.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/IconBrowser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 555 - (show annotations)
Thu Nov 27 17:39:00 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1332 byte(s)
extracted Frey::Web::CombineImages and use it also from ClassBrowser
1 package Frey::IconBrowser;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6 with 'Frey::Web::CombineImages';
7
8 use Data::Dump qw/dump/;
9
10 has path => (
11 is => 'rw',
12 isa => 'Str',
13 required => 1,
14 default => 'static/icons/fugue/',
15 );
16
17 sub as_markup {
18 my ($self) = @_;
19
20 my $extension = '\.(?:png)$';
21
22 opendir(my $dir, $self->path) || die "can't opendir ", $self->path, ": $!";
23 my @icons = sort grep { m/$extension/ } readdir($dir);
24 closedir $dir;
25
26 my ( $combined_path, $styles ) = $self->combine_images( map { $self->path . '/' . $_ } @icons );
27
28 my $html;
29 my $base;
30
31 foreach my $icon ( @icons ) {
32 my $name = $icon;
33 $name =~ s{$extension}{};
34
35 $base ||= $name; # seed with first
36 my $desc = '';
37
38 my $bl = length $base;
39
40 if ( substr($name, 0, $bl) eq $base ) {
41 ($name,$desc) = (
42 substr($name,0,$bl),
43 substr($name,$bl)
44 );
45 } else {
46 $base = $name;
47 warn "# new base $base";
48 $html .= qq|<hr>\n|;
49 }
50
51 # $html .= qq|<img src="/| . $self->path . qq|/$icon" alt="$icon"> <b>$name</b>$desc<br/>\n|;
52 # $html .= qq|<b>$name</b>$desc<br/>\n|;
53
54 my $path = $self->path . '/' . $icon;
55
56 my $pic = $styles->{$path} || die "can't find pic for $path in ",dump( $styles );
57 $html .= qq|<span title="$icon">$pic <b>$name</b>$desc</span>\n|;
58 }
59
60
61 # $html .= qq|<img src="$combined_path">|;
62 return $html;
63 }
64
65 1;

  ViewVC Help
Powered by ViewVC 1.1.26