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

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

revision 532 by dpavlin, Wed Nov 26 07:57:12 2008 UTC revision 540 by dpavlin, Wed Nov 26 18:02:38 2008 UTC
# Line 12  use File::Slurp; Line 12  use File::Slurp;
12    
13  use Frey::Bookmarklet;  use Frey::Bookmarklet;
14  use Frey::ClassBrowser;  use Frey::ClassBrowser;
15    use Frey::INC;
16    
17  use Frey::SVK;  use Frey::SVK;
18    
19  has 'head' => (  has 'head' => (
# Line 50  has 'dump_max_bytes' => ( Line 52  has 'dump_max_bytes' => (
52          documentation => 'Maximum dump size sent to browser before truncation',          documentation => 'Maximum dump size sent to browser before truncation',
53  );  );
54    
 =head2 inline_smaller_than  
   
 Inline JavaScript and CSS smaller than this size into page reducing  
 round-trips to server.  
   
 =cut  
   
55  has 'inline_smaller_than' => (  has 'inline_smaller_than' => (
56          is => 'rw',          is => 'rw',
57          isa => 'Int',          isa => 'Int',
58          default => 10240,          default => 10240,
59            documentation => 'Inline JavaScript and CSS to reduce round-trips',
60    );
61    
62    has 'chop_warning' => (
63            is => 'rw',
64            isa => 'Int',
65            default => 80,
66            documentation => 'Crop lines longer',
67  );  );
68    
69    my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
70    my $escape_re  = join '|' => keys %escape;
71    
72    sub html_escape {
73            my ( $self, $html ) = @_;
74            $html =~ s/($escape_re)/$escape{$1}/g;
75            return $html;
76    }
77    
78    sub html_dump {
79            my $self = shift;
80            $self->html_escape( dump( @_ ) );
81    }
82    
83  sub dom2html {  sub dom2html {
84  #       warn "## dom2html ",dump( @_ );  #       warn "## dom2html ",dump( @_ );
85          return Continuity::Widget::DomNode->create( @_ )->to_string;          return Continuity::Widget::DomNode->create( @_ )->to_string;
# Line 144  sub status { @status }; Line 161  sub status { @status };
161    
162  our $icon_html;  our $icon_html;
163    
164    sub popup {
165            my ( $self, $name, $content, $full ) = @_;
166    
167            if ( ref($content) ) {
168                    $content = '<code>' . dump($content) . '</code>';
169                    my $l = length($content);
170                    $content = qq|<span>$l bytes</span>| if ! $full && $l > $self->dump_max_bytes;
171            } else {
172                    $content = qq|<span>$content</span>|;
173            }
174    
175            warn "## popup [$name] = ", length( $content ), " bytes" if $self->debug;
176            return qq|<span class="frey-popup">$name $content</span>\n|;
177    }
178    
179  sub page {  sub page {
180          my $self = shift;          my $self = shift;
181          my $a = {@_};          my $a = {@_};
# Line 155  sub page { Line 187  sub page {
187          my $status_line = '';          my $status_line = '';
188    
189          unshift @status, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup };          unshift @status, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup };
190          unshift @status, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup };  #       unshift @status, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup };
191            unshift @status, { 'INC' => Frey::INC->new->as_markup };
192    
193          foreach my $part ( @status ) {          foreach my $part ( @status ) {
194                  foreach my $name ( keys %$part ) {                  foreach my $name ( keys %$part ) {
195                          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|;  
196                  }                  }
197          }          }
198    
# Line 357  my $warn_colors = { Line 381  my $warn_colors = {
381  };  };
382    
383  my $multiline_markers = {  my $multiline_markers = {
384          '(' => '\)',          '(' => ')',
385          '{' => '}',          '{' => '}',
386          '[' => '\]',          '[' => ']',
387          '"' => '"',          '"' => '"',
388  };  };
389    
# Line 372  sub log_path { Line 396  sub log_path {
396    
397  sub warnings_html {  sub warnings_html {
398          my ($self,$level) = shift;          my ($self,$level) = shift;
399          $level ||= $self->debug;          $level ||= $self->debug,
400          my $path = $self->log_path;          my $path = $self->log_path;
401    
402          my $warnings;          my $warnings;
# Line 384  sub warnings_html { Line 408  sub warnings_html {
408                  chomp;                  chomp;
409                  $line++;                  $line++;
410    
                 if ( $multiline_end ) {  
                         undef $multiline_end if m{^$multiline_end};  
                         next;  
                 }  
   
411                  my $style = '';                  my $style = '';
412    
413                  if ( m{^(#*)\s+} ) {                  if ( $multiline_end ) {
414                            if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) {
415    #                               warn "## $line end of $multiline_end in '$_'\n";
416                                    undef $multiline_end;
417                            } else {
418    #                               warn "## $line skipped\n";
419                            }
420                    } elsif ( m{^(#*)\s+} ) {
421                          my $l = $1 ? length($1) : 0;                          my $l = $1 ? length($1) : 0;
422                          $multiline_end = $multiline_markers->{$1} if m{($multiline_re)$};                          if ( $l > $level ) {
423                          next if $l > $level;                                  undef $multiline_end;
424                          warn "## multiline_end: $multiline_end $l > $level for '$_'" if $multiline_end;                                  $multiline_end = $multiline_markers->{$1} if m{($multiline_re)$};
425                          undef $multiline_end;  #                               warn "## $line start $1 .. $multiline_end level $l > $level for '$_'\n" if $multiline_end;
426                                    next;
427                            }
428    
429                          $style = $warn_colors->{$1}                          $style = $warn_colors->{$1}
430                                  ? ' style="color:' . $warn_colors->{$1} . '"'                                  ? ' style="color:' . $warn_colors->{$1} . '"'
431                                  : '';                                  : '';
432    
433                          $warnings .= qq|<tt$style>$_</tt> <small> <a target="editor" href="/editor+$path+$line">+$line</a> </small> <br/>|;                          my $msg = $self->html_escape( $_ );
434                            my $spacer = ' ';
435                            if ( length($msg) > $self->chop_warning ) {
436                                    $msg = substr( $msg, 0, $self->chop_warning );
437                                    $spacer = '&hellip;'
438                            }
439                            $msg =~ s{^\s}{&nbsp;}g;
440                            $warnings .= qq|<tt$style>$msg</tt>$spacer<small><a target="editor" href="/editor+$path+$line">+$line</a></small><br/>|;
441                          # FIXME <tt> should be <code> but CSS hates me                          # FIXME <tt> should be <code> but CSS hates me
442                  }                  }
443          }          }

Legend:
Removed from v.532  
changed lines
  Added in v.540

  ViewVC Help
Powered by ViewVC 1.1.26