/[Frey]/branches/zimbardo/lib/Frey/Web.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 /branches/zimbardo/lib/Frey/Web.pm

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

revision 986 by dpavlin, Sat Jan 10 18:53:15 2009 UTC revision 1124 by dpavlin, Tue Jun 30 13:58:38 2009 UTC
# Line 1  Line 1 
1  package Frey::Web;  package Frey::Web;
2  use Moose::Role;  use Moose::Role;
3    
4  with 'Frey::Session';  with 'Frey::Session', 'Frey::Class::Icon';
5    
6  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
7  use Carp qw/confess cluck carp/;  use Carp qw/confess cluck carp/;
8  use File::Slurp;  use File::Slurp;
9  use Text::Tabs; # expand, unexpand  use Text::Tabs; # expand, unexpand
10    use Digest::MD5 qw/md5/;
11    
12  use lib 'lib';  use lib 'lib';
13    
# Line 196  sub add_head { Line 197  sub add_head {
197  sub _add_css_js {  sub _add_css_js {
198          my ( $self, $what, $content ) = @_;          my ( $self, $what, $content ) = @_;
199    
200            my $md5 = md5( $content );
201            return if $self->{_add_css_js_seen}->{$what}->{$md5}++;
202    
203          my $tag  = $what eq 'css' ? 'style'    : 'script';          my $tag  = $what eq 'css' ? 'style'    : 'script';
204          my $type = $what eq 'css' ? 'text/css' : 'text/javascript';          my $type = $what eq 'css' ? 'text/css' : 'text/javascript';
205          my $head;          my $head;
# Line 203  sub _add_css_js { Line 207  sub _add_css_js {
207          my ( $package, $path, $line ) = caller(1);          my ( $package, $path, $line ) = caller(1);
208    
209          $content = "/$content" if $content !~ m{[\n\r]} && -e $content;          $content = "/$content" if $content !~ m{[\n\r]} && -e $content;
210          if ( $content =~ $re_html ) {          if ( $content =~ $re_html && $what ne 'js' ) {
211                  $head = qq|                  $head = qq|
212                          $content                          $content
213                          <!-- $type via $package at $path line $line -->                          <!-- $type via $package at $path line $line -->
# Line 258  our $reload_counter = 0; Line 262  our $reload_counter = 0;
262  our @status;  our @status;
263  sub status { @status };  sub status { @status };
264    
 our $icon_html;  
   
265  sub html_page {  sub html_page {
266          my $self = shift;          my $self = shift;
267          my $a = {@_};          my $a = {@_};
# Line 299  sub html_page { Line 301  sub html_page {
301    
302          my $right =          my $right =
303                  qq|                  qq|
304                          <span class="right">                          <span class="frey-status-right">
305                          <a title="reload $url"  href="/reload$url">reload</a>                          <a title="reload $url"  href="/reload$url">reload</a>
306                          <a title="$description" href="/exit$url" target="exit">$exit</a>                          <a title="$description" href="/exit$url" target="exit">$exit</a>
307                          </span>                          </span>
# Line 310  sub html_page { Line 312  sub html_page {
312          my $revision = $svk->info->{Revision} || '';          my $revision = $svk->info->{Revision} || '';
313          $revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)};          $revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)};
314    
315          $self->add_icon unless $icon_html;          $self->add_icon;
316    
317          my $title = undef          my $title = undef
318                  || $a->{title}                  || $a->{title}
# Line 331  sub html_page { Line 333  sub html_page {
333                  $self->_head_html,                  $self->_head_html,
334                  qq|<title>$title</title>|,                  qq|<title>$title</title>|,
335                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',
336                  ( $icon_html || '<!-- no icon -->' ),                  ( $self->icon_html ),
337                  ( $a->{head} || '' ),                  ( $a->{head} || '' ),
338                  qq|                  qq|
339                  </head><body>                  </head><body>
# Line 482  Called at beginning of each request Line 484  Called at beginning of each request
484    
485  sub clean_status {  sub clean_status {
486          my ($self) = shift;          my ($self) = shift;
487            warn "## clean_status";
488          @head = ( 'static/frey.css' );          @head = ( 'static/frey.css' );
489          @status = (          @status = (
490                  { 'ClassBrowser' => Frey::Class::Browser->new( usage_sort => 1, usage_on_top => 0 )->as_markup },                  { 'ClassBrowser' => Frey::Class::Browser->new( usage_sort => 1, usage_on_top => 0 )->as_markup },
491                  { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup },                  { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup },
492                  { 'INC' => Frey::INC->new->as_markup },                  { 'INC' => Frey::INC->new->as_markup },
493          );          );
         $icon_html = '';  
494  }  }
495    
496  =head2 status_parts  =head2 status_parts
# Line 512  sub DEMOLISH { Line 514  sub DEMOLISH {
514    
515  =cut  =cut
516    
 =head2 add_icon  
   
   Frey::Foo->add_icon;            # /static/icons/Frey/Foo.png  
   Frey::Foo->add_icon('warning'); # /static/icons/Frey/Foo/warning.png  
   
 =cut  
   
 sub icon_path {  
         my ($self,$class,$variant) = @_;  
   
         sub icon_exists {  
                 my $class = shift;  
                 $class =~ s{::}{/}g;  
                 $class .= "/$variant" if $variant;  
                 my $icon_path = 'static/icons/' . $class . '.png';  
                 return $icon_path if -e $icon_path;  
                 return;  
         }  
   
         my $path = icon_exists( $class );  
         if ( ! $path ) {  
                 my $super_class = $class;  
                 while ( $super_class =~ s{::[^:]+$}{} && ! $path ) {  
                         $path = icon_exists( $super_class ) unless $super_class eq 'Frey'; # don't default on Frey icon  
                 }  
         }  
   
         if ( ! $path ) {  
                 $self->TODO( "add icon for $class" . ( $variant ? " variant $variant" : '' ) );  
                 return undef;  
         }  
   
         warn "# $class from $self icon_path $path" if $self->debug;  
         return $path;  
 }  
   
 sub add_icon {  
         my ($self,$variant) = @_;  
   
         my $class = $self->class if $self->can('class');  
         #$class ||= $self->title;  
         $class ||= ref($self);  
         my $icon_path = $self->icon_path( $class, $variant ) || return;  
   
         $icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|;  
         warn "# using icon $icon_path";  
   
 =for later  
   
         # FIXME http://en.wikipedia.org/wiki/Favicon suggest just rel="icon" but that doesn't seem to work!  
         my $ico_path = $icon_path;  
         $ico_path =~ s{png$}{ico};  
         if ( ! -e $ico_path ) {  
                 system "convert $icon_path $ico_path";  
                 warn "# convert $icon_path $ico_path : $@";  
         }  
         $icon_html .= qq|<link rel="shortcut icon" type="image/x-icon" href="/$ico_path">| if -e $ico_path;  
   
 =cut  
   
 }  
   
517  my $warn_colors = {  my $warn_colors = {
518          '#'  => '#444',          '#'  => '#444',
519          '##' => '#888',          '##' => '#888',

Legend:
Removed from v.986  
changed lines
  Added in v.1124

  ViewVC Help
Powered by ViewVC 1.1.26