/[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 607 by dpavlin, Thu Nov 27 21:02:50 2008 UTC revision 608 by dpavlin, Fri Nov 28 23:28:12 2008 UTC
# Line 14  has path => ( Line 14  has path => (
14          default => 'static/icons/fugue/',          default => 'static/icons/fugue/',
15  );  );
16    
17    has show_names => (
18            is => 'rw',
19            isa => 'Bool',
20            required => 1,
21            default => 1,
22    );
23    
24  sub as_markup {  sub as_markup {
25          my ($self) = @_;          my ($self) = @_;
26    
27            $self->title( 'icons - ' . $self->path );
28    
29          my $extension = '\.(?:png)$';          my $extension = '\.(?:png)$';
30    
31          opendir(my $dir, $self->path) || die "can't opendir ", $self->path, ": $!";          opendir(my $dir, $self->path) || die "can't opendir ", $self->path, ": $!";
# Line 25  sub as_markup { Line 34  sub as_markup {
34    
35          my ( $combined_path, $styles ) = $self->combine_images( map { $self->path . '/' . $_ } @icons );          my ( $combined_path, $styles ) = $self->combine_images( map { $self->path . '/' . $_ } @icons );
36    
37          my $html;          my $width = 0;
38            foreach ( @icons ) {
39                    my $l = length($_);
40                    $width = $l if $l > $width;
41            }
42    
43            $width = 2 if ! $self->show_names;
44    
45            $self->add_css(qq|
46                    h1 { font-size: 20px }
47                    /* group */
48                    div.g {
49                            float: left;
50                            clear: both;
51                    }
52                    /* individual icon */
53                    div.i {
54                            color: #888;
55                            width: ${width}ex;
56                            float: left;
57                    }
58            |);
59    
60            my $html = '<div class="g">';
61          my $base;          my $base;
62    
63          foreach my $icon ( @icons ) {          foreach my $icon ( @icons ) {
64                  my $name = $icon;                  my $name = $icon;
65                  $name =~ s{$extension}{};                  $name =~ s{$extension}{};
66    
67                  $base ||= $name; # seed with first                  if ( ! $base ) {
68                            $base = $name;
69                            $html .= qq|<h1>$name</h1>|;
70                    }
71    
72                  my $desc = '';                  my $desc = '';
73    
74                  my $bl = length $base;                  my $bl = length $base;
75    
76                  if ( substr($name, 0, $bl) eq $base ) {                  if ( $name =~ m{_} && substr($name, 0, $bl) eq $base ) {
77                          ($name,$desc) = (                          ($name,$desc) = (
78                                  substr($name,0,$bl),                                  substr($name,0,$bl),
79                                  substr($name,$bl)                                  substr($name,$bl)
# Line 45  sub as_markup { Line 81  sub as_markup {
81                  } else {                  } else {
82                          $base = $name;                          $base = $name;
83                          warn "# new base $base" if $self->debug;                          warn "# new base $base" if $self->debug;
84                          $html .= qq|<hr>\n|;                          $html .= qq|
85                                    </div>
86                                    <div class="g">
87                                    <h1>$name</h1>
88                            |;
89                  }                  }
90    
91  #               $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 94  sub as_markup {
94                  my $path = $self->path . '/' . $icon;                  my $path = $self->path . '/' . $icon;
95    
96                  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 );
97                  $html .= qq|<span title="$icon">$pic <b>$name</b>$desc</span>\n|;                  $html .= ''
98                            . qq|<div title="$icon" class="i">$pic|
99                            . ( $self->show_names ? qq|<b>$name</b>$desc| : '' )
100                            . qq|</div>\n|
101                            ;
102          }          }
103    
104    
105            $html .= '</div>';
106  #       $html .= qq|<img src="$combined_path">|;  #       $html .= qq|<img src="$combined_path">|;
107          return $html;          return $html;
108  }  }

Legend:
Removed from v.607  
changed lines
  Added in v.608

  ViewVC Help
Powered by ViewVC 1.1.26