/[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 818 - (show annotations)
Fri Dec 12 18:00:21 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 1951 byte(s)
added dir_extension helper for opendir
1 package Frey::IconBrowser;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6 with 'Frey::Web::CombineImages';
7 with 'Frey::File';
8
9 use Data::Dump qw/dump/;
10
11 has path => (
12 is => 'rw',
13 isa => 'Str',
14 required => 1,
15 default => 'static/icons/fugue/',
16 );
17
18 has show_names => (
19 is => 'rw',
20 isa => 'Bool',
21 required => 1,
22 default => 1,
23 );
24
25 sub as_markup {
26 my ($self) = @_;
27
28 $self->title( 'icons - ' . $self->path );
29
30 my $extension = '\.(?:png)$';
31 my @icons = $self->dir_extension( $self->path, $extension );
32
33 my ( $combined_path, $styles ) = $self->combine_images( map { $self->path . '/' . $_ } @icons );
34
35 my $width = 0;
36 foreach ( @icons ) {
37 my $l = length($_);
38 $width = $l if $l > $width;
39 }
40
41 $width = 2 if ! $self->show_names;
42
43 $self->add_css(qq|
44 h1 { font-size: 20px }
45 /* group */
46 div.g {
47 float: left;
48 clear: both;
49 }
50 /* individual icon */
51 div.i {
52 color: #888;
53 width: ${width}ex;
54 float: left;
55 }
56 |);
57
58 my $html = '<div class="g">';
59 my $base;
60
61 foreach my $icon ( @icons ) {
62 my $name = $icon;
63 $name =~ s{$extension}{};
64
65 if ( ! $base ) {
66 $base = $name;
67 $html .= qq|<h1>$name</h1>|;
68 }
69
70 my $desc = '';
71
72 my $bl = length $base;
73
74 if ( $name =~ m{_} && substr($name, 0, $bl) eq $base ) {
75 ($name,$desc) = (
76 substr($name,0,$bl),
77 substr($name,$bl)
78 );
79 } else {
80 $base = $name;
81 warn "# new base $base" if $self->debug;
82 $html .= qq|
83 </div>
84 <div class="g">
85 <h1>$name</h1>
86 |;
87 }
88
89 # $html .= qq|<img src="/| . $self->path . qq|/$icon" alt="$icon"> <b>$name</b>$desc<br/>\n|;
90 # $html .= qq|<b>$name</b>$desc<br/>\n|;
91
92 my $path = $self->path . '/' . $icon;
93
94 my $pic = $styles->{$path} || die "can't find pic for $path in ",dump( $styles );
95 $html .= ''
96 . qq|<div title="$icon" class="i">$pic|
97 . ( $self->show_names ? qq|<b>$name</b>$desc| : '' )
98 . qq|</div>\n|
99 ;
100 }
101
102
103 $html .= '</div>';
104 # $html .= qq|<img src="$combined_path">|;
105 return $html;
106 }
107
108 1;

  ViewVC Help
Powered by ViewVC 1.1.26