/[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 529 by dpavlin, Wed Nov 26 04:26:43 2008 UTC revision 538 by dpavlin, Wed Nov 26 17:36:02 2008 UTC
# Line 50  has 'dump_max_bytes' => ( Line 50  has 'dump_max_bytes' => (
50          documentation => 'Maximum dump size sent to browser before truncation',          documentation => 'Maximum dump size sent to browser before truncation',
51  );  );
52    
 =head2 inline_smaller_than  
   
 Inline JavaScript and CSS smaller than this size into page reducing  
 round-trips to server.  
   
 =cut  
   
53  has 'inline_smaller_than' => (  has 'inline_smaller_than' => (
54          is => 'rw',          is => 'rw',
55          isa => 'Int',          isa => 'Int',
56          default => 10240,          default => 10240,
57            documentation => 'Inline JavaScript and CSS to reduce round-trips',
58    );
59    
60    has 'chop_warning' => (
61            is => 'rw',
62            isa => 'Int',
63            default => 80,
64            documentation => 'Crop lines longer',
65  );  );
66    
67    my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
68    my $escape_re  = join '|' => keys %escape;
69    
70    sub html_escape {
71            my ( $self, $html ) = @_;
72            $html =~ s/($escape_re)/$escape{$1}/g;
73            return $html;
74    }
75    
76    sub html_dump {
77            my $self = shift;
78            $self->html_escape( dump( @_ ) );
79    }
80    
81  sub dom2html {  sub dom2html {
82  #       warn "## dom2html ",dump( @_ );  #       warn "## dom2html ",dump( @_ );
83          return Continuity::Widget::DomNode->create( @_ )->to_string;          return Continuity::Widget::DomNode->create( @_ )->to_string;
# Line 144  sub status { @status }; Line 159  sub status { @status };
159    
160  our $icon_html;  our $icon_html;
161    
162    sub popup {
163            my ( $self, $name, $content, $full ) = @_;
164    
165            if ( ref($content) ) {
166                    $content = '<code>' . dump($content) . '</code>';
167                    my $l = length($content);
168                    $content = qq|<span>$l bytes</span>| if ! $full && $l > $self->dump_max_bytes;
169            } else {
170                    $content = qq|<span>$content</span>|;
171            }
172    
173            warn "## popup [$name] = ", length( $content ), " bytes" if $self->debug;
174            return qq|<span class="frey-popup">$name $content</span>\n|;
175    }
176    
177  sub page {  sub page {
178          my $self = shift;          my $self = shift;
179          my $a = {@_};          my $a = {@_};
# Line 155  sub page { Line 185  sub page {
185          my $status_line = '';          my $status_line = '';
186    
187          unshift @status, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup };          unshift @status, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup };
188          unshift @status, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup };  #       unshift @status, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup };
189    
190          foreach my $part ( @status ) {          foreach my $part ( @status ) {
191                  foreach my $name ( keys %$part ) {                  foreach my $name ( keys %$part ) {
192                          my $content = $part->{$name};                          $status_line .= $self->popup( $name, $part->{$name} );
                         if ( ref($content) ) {  
                                 $content = '<code>' . dump($content) . '</code>';  
                                 my $l = length($content);  
                                 $content = qq|<span>$l bytes</span>| if $l > $self->dump_max_bytes;  
                         } else {  
                                 $content = qq|<span>$content</span>|;  
                         }  
                         warn "### part [$name] = ", length( $content ), " bytes" if $self->debug;  
                         $status_line .= qq|<span class="frey-popup">$name $content</span>\n|;  
193                  }                  }
194          }          }
195    
# Line 185  sub page { Line 206  sub page {
206                  $body = '<!-- no body -->';                  $body = '<!-- no body -->';
207          }          }
208    
209          my $warn_colors = {          $status_line .= $self->warnings_html;
210                  '#'  => '#444',  
211                  '##' => '#888',          my $inc_html;
212          };          {
213                    my $inc;
214          $status_line                  map {
215                  .= qq|<span class="frey-popup">warn<span>|                          s{.pm$}{};
216                  . $self->editor_links(                          my $class = $_;
217                          join("", map {                          s[/][}->{]g;
218                                  warn "# $_";                          $class =~ s[/][::]g;
219                                  my $style = '';                          eval '$inc->{' . $_ . '} = $class';
220                                  $style = $warn_colors->{$1}                  } sort keys %INC;
221                                          ? ' style="color:' . $warn_colors->{$1} . '"'                  $inc_html = dump( $inc );
222                                          : ''                  $inc_html =~ s{\s+=>\s+\d+}{}gs;
223                                          if m{^(#+)};                  $inc_html =~ s{(['"]?)(\w+)\1\s+=>\s+(['"]?)([\w:]*\2)\3}{<a target="$4" href="/$4" title="$4">$2</a>}gs;
224                                  qq|<tt$style>$_</tt><br/>|; # XXX <tt> should be <code> but CSS hates me                  $inc_html =~ s{\s+=>\s+}{ }gs;
225                          } $self->warnings )                  $inc_html =~ s{,}{}gs;
226                  )          }
227                  . qq|</span></span>|  
228                  if $self->warnings;          $status_line .= $self->popup( INC => "<small>$inc_html</small>" );
229    
230          my      ($exit,$description) = ('exit','stop server');          my      ($exit,$description) = ('exit','stop server');
231                  ($exit,$description) = ('restart','restart server')                  ($exit,$description) = ('restart','restart server')
# Line 370  sub add_icon { Line 391  sub add_icon {
391    
392  }  }
393    
394    my $warn_colors = {
395            '#'  => '#444',
396            '##' => '#888',
397    };
398    
399    my $multiline_markers = {
400            '(' => ')',
401            '{' => '}',
402            '[' => ']',
403            '"' => '"',
404    };
405    
406    my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']';
407    warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re";
408    
409    sub log_path {
410            $Frey::Bootstrap::log_path || warn "no log_path?";
411    }
412    
413    sub warnings_html {
414            my ($self,$level) = shift;
415            $level ||= $self->debug,
416            my $path = $self->log_path;
417    
418            my $warnings;
419            my $line = 0;
420            my $multiline_end;
421    
422            open(my $log, '<', $path) || die "can't open $path: $!";
423            while(<$log>) {
424                    chomp;
425                    $line++;
426    
427                    my $style = '';
428    
429                    if ( $multiline_end ) {
430                            if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) {
431    #                               warn "## $line end of $multiline_end in '$_'\n";
432                                    undef $multiline_end;
433                            } else {
434    #                               warn "## $line skipped\n";
435                            }
436                    } elsif ( m{^(#*)\s+} ) {
437                            my $l = $1 ? length($1) : 0;
438                            if ( $l > $level ) {
439                                    undef $multiline_end;
440                                    $multiline_end = $multiline_markers->{$1} if m{($multiline_re)$};
441    #                               warn "## $line start $1 .. $multiline_end level $l > $level for '$_'\n" if $multiline_end;
442                                    next;
443                            }
444    
445                            $style = $warn_colors->{$1}
446                                    ? ' style="color:' . $warn_colors->{$1} . '"'
447                                    : '';
448    
449                            my $msg = $self->html_escape( $_ );
450                            my $spacer = ' ';
451                            if ( length($msg) > $self->chop_warning ) {
452                                    $msg = substr( $msg, 0, $self->chop_warning );
453                                    $spacer = '&hellip;'
454                            }
455                            $msg =~ s{^\s}{&nbsp;}g;
456                            $warnings .= qq|<tt$style>$msg</tt>$spacer<small><a target="editor" href="/editor+$path+$line">+$line</a></small><br/>|;
457                            # FIXME <tt> should be <code> but CSS hates me
458                    }
459            }
460            close($log) || die "can't close $path: $!";
461    
462            return
463                      qq|<span class="frey-popup"><a target="editor" href="/editor+$path+$line" title="open $path level $level">warn</a><span>|
464                    . $self->editor_links( $warnings )
465                    . qq|</span></span>|
466                    ;
467    }
468    
469  1;  1;

Legend:
Removed from v.529  
changed lines
  Added in v.538

  ViewVC Help
Powered by ViewVC 1.1.26