/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 560 by dpavlin, Thu Nov 27 21:02:50 2008 UTC revision 818 by dpavlin, Fri Dec 12 18:00:21 2008 UTC
# Line 4  use Moose; Line 4  use Moose;
4  extends 'Frey';  extends 'Frey';
5  with 'Frey::Web';  with 'Frey::Web';
6  with 'Frey::Web::CombineImages';  with 'Frey::Web::CombineImages';
7    with 'Frey::File';
8    
9  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
10    
# Line 14  has path => ( Line 15  has path => (
15          default => 'static/icons/fugue/',          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 {  sub as_markup {
26          my ($self) = @_;          my ($self) = @_;
27    
28          my $extension = '\.(?:png)$';          $self->title( 'icons - ' . $self->path );
29    
30          opendir(my $dir, $self->path) || die "can't opendir ", $self->path, ": $!";          my $extension = '\.(?:png)$';
31          my @icons = sort grep { m/$extension/ } readdir($dir);          my @icons = $self->dir_extension( $self->path, $extension );
         closedir $dir;  
32    
33          my ( $combined_path, $styles ) = $self->combine_images( map { $self->path . '/' . $_ } @icons );          my ( $combined_path, $styles ) = $self->combine_images( map { $self->path . '/' . $_ } @icons );
34    
35          my $html;          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;          my $base;
60    
61          foreach my $icon ( @icons ) {          foreach my $icon ( @icons ) {
62                  my $name = $icon;                  my $name = $icon;
63                  $name =~ s{$extension}{};                  $name =~ s{$extension}{};
64    
65                  $base ||= $name; # seed with first                  if ( ! $base ) {
66                            $base = $name;
67                            $html .= qq|<h1>$name</h1>|;
68                    }
69    
70                  my $desc = '';                  my $desc = '';
71    
72                  my $bl = length $base;                  my $bl = length $base;
73    
74                  if ( substr($name, 0, $bl) eq $base ) {                  if ( $name =~ m{_} && substr($name, 0, $bl) eq $base ) {
75                          ($name,$desc) = (                          ($name,$desc) = (
76                                  substr($name,0,$bl),                                  substr($name,0,$bl),
77                                  substr($name,$bl)                                  substr($name,$bl)
# Line 45  sub as_markup { Line 79  sub as_markup {
79                  } else {                  } else {
80                          $base = $name;                          $base = $name;
81                          warn "# new base $base" if $self->debug;                          warn "# new base $base" if $self->debug;
82                          $html .= qq|<hr>\n|;                          $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|;  #               $html .= qq|<img src="/| . $self->path . qq|/$icon" alt="$icon"> <b>$name</b>$desc<br/>\n|;
# Line 54  sub as_markup { Line 92  sub as_markup {
92                  my $path = $self->path . '/' . $icon;                  my $path = $self->path . '/' . $icon;
93    
94                  my $pic = $styles->{$path} || die "can't find pic for $path in ",dump( $styles );                  my $pic = $styles->{$path} || die "can't find pic for $path in ",dump( $styles );
95                  $html .= qq|<span title="$icon">$pic <b>$name</b>$desc</span>\n|;                  $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">|;  #       $html .= qq|<img src="$combined_path">|;
105          return $html;          return $html;
106  }  }

Legend:
Removed from v.560  
changed lines
  Added in v.818

  ViewVC Help
Powered by ViewVC 1.1.26