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

  ViewVC Help
Powered by ViewVC 1.1.26