/[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 482 by dpavlin, Thu Nov 20 15:23:13 2008 UTC revision 527 by dpavlin, Wed Nov 26 02:35:59 2008 UTC
# Line 7  use Frey::Types; Line 7  use Frey::Types;
7    
8  use Continuity::Widget::DomNode;  use Continuity::Widget::DomNode;
9  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
10  use Carp qw/confess/;  use Carp qw/confess cluck/;
11  use File::Slurp;  use File::Slurp;
12    
13  use Frey::Bookmarklet;  use Frey::Bookmarklet;
14  use Frey::ClassBrowser;  use Frey::ClassBrowser;
15    use Frey::SVK;
16    
17  has 'head' => (  has 'head' => (
18          is => 'rw',          is => 'rw',
# Line 19  has 'head' => ( Line 20  has 'head' => (
20          default => sub { [ 'static/frey.css' ] },          default => sub { [ 'static/frey.css' ] },
21  );  );
22    
 has 'status' => (  
         is => 'rw',  
         isa => 'ArrayRef[HashRef[Str]]',  
         lazy => 1,  
         default => sub { [  
                 { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup },  
                 { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup },  
         ] },  
 );  
   
23  has 'request_url' => (  has 'request_url' => (
24          is => 'rw',          is => 'rw',
25          isa => 'Uri', coerce => 1,          isa => 'Uri', coerce => 1,
# Line 148  our $reload_counter = 0; Line 139  our $reload_counter = 0;
139    
140  =cut  =cut
141    
142    our @status;
143    sub status { @status };
144    
145    our $icon_html;
146    
147  sub page {  sub page {
148          my $self = shift;          my $self = shift;
149          my $a = {@_};          my $a = {@_};
150    
151            warn "## page ",dump($a);
152    
153          $reload_counter++;          $reload_counter++;
154    
155          my $status_line = '';          my $status_line = '';
156          foreach my $part ( @{ $self->status } ) {  
157                  if ( ref($part) ne 'HASH' ) {          unshift @status, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup };
158                          warn "part not hash ",dump( $part ) ;          unshift @status, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup };
159                          #$self->status( $part );  
160                          next;          foreach my $part ( @status ) {
                 }  
161                  foreach my $name ( keys %$part ) {                  foreach my $name ( keys %$part ) {
162                          my $content = $part->{$name};                          my $content = $part->{$name};
163                          if ( ref($content) ) {                          if ( ref($content) ) {
# Line 216  sub page { Line 213  sub page {
213          my $right =          my $right =
214                  qq|                  qq|
215                          <span class="right">                          <span class="right">
216                          <a title="reload"  href="/reload$url"><code>$url</code></a>                          <a title="reload $url"  href="/reload$url">reload</a>
217                          <a title="$description" href="/exit$url">$exit</a>                          <a title="$description" href="/exit$url">$exit</a>
218                          </span>                          </span>
219                  |;                  |;
220    
221            my $info = Frey::SVK->info;
222            my $revision = Frey::SVK->info->{Revision} || '';
223            $revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)};
224    
225            $self->add_icon unless $icon_html;
226    
227          my $html = join("\n",          my $html = join("\n",
228                  qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,                  qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,
229                  $self->_head_html,                  $self->_head_html,
230                  '<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>',                  '<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>',
231                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',
232                    ( $icon_html || '<!-- no icon -->' ),
233                  ( $a->{head} || '' ),                  ( $a->{head} || '' ),
234                  qq|                  qq|
235                  </head><body>                  </head><body>
236                  $body                  $body
237                  <div class="frey-status-line">                  <div class="frey-status-line">
238                          <a href="/">Frey</a> $Frey::VERSION                          <a href="/">Frey</a> $Frey::VERSION $revision
239                          $status_line                          $status_line
240                          $right                          $right
241                  </div>                  </div>
# Line 255  Create HTML editor link with optional li Line 259  Create HTML editor link with optional li
259  sub editor {  sub editor {
260          my ( $self, $class, $line, $title ) = @_;          my ( $self, $class, $line, $title ) = @_;
261          confess "need class" unless $class;          confess "need class" unless $class;
262          $line ||= 1;          if ( ! defined $title ) {
263                    $title  = "edit $class";
264                    $title .= " line $line" if $line;
265            }
266            $line  ||= 1;
267          qq|<a target="editor" href="/editor+$class+$line"| .          qq|<a target="editor" href="/editor+$class+$line"| .
268          ( $title ? qq| title="$title"| : '' ) .          ( $title ? qq| title="$title"| : '' ) .
269          qq|>$class</a>|;          qq|>$class</a>|;
# Line 296  sub error { Line 304  sub error {
304                  ;                  ;
305  }  }
306    
307    sub add_status {
308            my ( $self, $data ) = @_;
309            push @status, $data;
310    }
311    
312    sub clean_status {
313            @status = ();
314            $icon_html = '';
315    }
316    
317    sub status_parts {
318            warn "## status parts ", dump( map { keys %$_ } @status );
319    }
320    
321    sub DEMOLISH {
322            my ( $self ) = @_;
323            cluck "## DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status;
324    }
325    
326    =head2 add_icon
327    
328      Frey::Foo->add_icon;            # /static/icons/Frey/Foo.png
329      Frey::Foo->add_icon('warning'); # /static/icons/Frey/Foo/warning.png
330    
331    =cut
332    
333    sub add_icon {
334            my ($self,$name) = @_;
335            my $icon = ref($self);
336            $icon = $self->class if $self->can('class');
337            $icon =~ s{::}{/}g;
338            $icon .= "/$name" if $name;
339    
340            my $icon_path = "static/icons/$icon.png";
341    
342            if ( -e $icon_path ) {
343                    $icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|;
344                    warn "# using icon $icon_path";
345    
346    =for later
347    
348                    # FIXME http://en.wikipedia.org/wiki/Favicon suggest just rel="icon" but that doesn't seem to work!
349                    my $ico_path = $icon_path;
350                    $ico_path =~ s{png$}{ico};
351                    if ( ! -e $ico_path ) {
352                            system "convert $icon_path $ico_path";
353                            warn "# convert $icon_path $ico_path : $@";
354                    }
355                    $icon_html .= qq|<link rel="shortcut icon" type="image/x-icon" href="/$ico_path">| if -e $ico_path;
356    
357    =cut
358    
359            } else {
360                    warn "TODO add $icon_path icon";
361            }
362    }
363    
364  1;  1;

Legend:
Removed from v.482  
changed lines
  Added in v.527

  ViewVC Help
Powered by ViewVC 1.1.26