1 |
dpavlin |
553 |
package Frey::IconBrowser; |
2 |
|
|
use Moose; |
3 |
|
|
|
4 |
|
|
extends 'Frey'; |
5 |
|
|
with 'Frey::Web'; |
6 |
dpavlin |
555 |
with 'Frey::Web::CombineImages'; |
7 |
dpavlin |
553 |
|
8 |
dpavlin |
555 |
use Data::Dump qw/dump/; |
9 |
|
|
|
10 |
dpavlin |
553 |
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 |
dpavlin |
555 |
my ( $combined_path, $styles ) = $self->combine_images( map { $self->path . '/' . $_ } @icons ); |
27 |
dpavlin |
553 |
|
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 |
dpavlin |
555 |
my $desc = ''; |
37 |
dpavlin |
553 |
|
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 |
dpavlin |
555 |
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 |
dpavlin |
553 |
} |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
# $html .= qq|<img src="$combined_path">|; |
62 |
|
|
return $html; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
1; |