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 = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
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; |
200 |
$body = '<!-- no body -->'; |
$body = '<!-- no body -->'; |
201 |
} |
} |
202 |
|
|
203 |
my $warn_colors = { |
$status_line .= $self->warnings_html; |
|
'#' => '#444', |
|
|
'##' => '#888', |
|
|
}; |
|
|
|
|
|
$status_line |
|
|
.= qq|<span class="frey-popup">warn<span>| |
|
|
. $self->editor_links( |
|
|
join("", map { |
|
|
warn "# $_"; |
|
|
my $style = ''; |
|
|
$style = $warn_colors->{$1} |
|
|
? ' style="color:' . $warn_colors->{$1} . '"' |
|
|
: '' |
|
|
if m{^(#+)}; |
|
|
qq|<tt$style>$_</tt><br/>|; # XXX <tt> should be <code> but CSS hates me |
|
|
} $self->warnings ) |
|
|
) |
|
|
. qq|</span></span>| |
|
|
if $self->warnings; |
|
204 |
|
|
205 |
my ($exit,$description) = ('exit','stop server'); |
my ($exit,$description) = ('exit','stop server'); |
206 |
($exit,$description) = ('restart','restart server') |
($exit,$description) = ('restart','restart server') |
316 |
|
|
317 |
sub DEMOLISH { |
sub DEMOLISH { |
318 |
my ( $self ) = @_; |
my ( $self ) = @_; |
319 |
cluck "## DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status; |
warn "## $self DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status; |
320 |
} |
} |
321 |
|
|
322 |
=head2 add_icon |
=head2 add_icon |
326 |
|
|
327 |
=cut |
=cut |
328 |
|
|
329 |
sub add_icon { |
sub icon_path { |
330 |
my ($self,$name) = @_; |
my ($self,$class,$variant) = @_; |
331 |
my $icon = ref($self); |
my $icon = $class; |
|
$icon = $self->class if $self->can('class'); |
|
332 |
$icon =~ s{::}{/}g; |
$icon =~ s{::}{/}g; |
333 |
$icon .= "/$name" if $name; |
$icon .= "/$variant" if $variant; |
334 |
|
my $path = 'static/icons/' . $icon . '.png'; |
335 |
|
if ( -e $path ) { |
336 |
|
warn "# $class from $self icon_path $path"; |
337 |
|
return $path; |
338 |
|
} else { |
339 |
|
warn "TODO: add $path icon for $class"; |
340 |
|
return undef; |
341 |
|
} |
342 |
|
} |
343 |
|
|
344 |
|
sub add_icon { |
345 |
|
my ($self,$variant) = @_; |
346 |
|
|
347 |
my $icon_path = "static/icons/$icon.png"; |
my $class = ref($self); |
348 |
|
$class = $self->class if $self->can('class'); |
349 |
|
my $icon_path = $self->icon_path( $class, $variant ) || return; |
350 |
|
|
351 |
if ( -e $icon_path ) { |
$icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|; |
352 |
$icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|; |
warn "# using icon $icon_path"; |
|
warn "# using icon $icon_path"; |
|
353 |
|
|
354 |
=for later |
=for later |
355 |
|
|
356 |
# FIXME http://en.wikipedia.org/wiki/Favicon suggest just rel="icon" but that doesn't seem to work! |
# FIXME http://en.wikipedia.org/wiki/Favicon suggest just rel="icon" but that doesn't seem to work! |
357 |
my $ico_path = $icon_path; |
my $ico_path = $icon_path; |
358 |
$ico_path =~ s{png$}{ico}; |
$ico_path =~ s{png$}{ico}; |
359 |
if ( ! -e $ico_path ) { |
if ( ! -e $ico_path ) { |
360 |
system "convert $icon_path $ico_path"; |
system "convert $icon_path $ico_path"; |
361 |
warn "# convert $icon_path $ico_path : $@"; |
warn "# convert $icon_path $ico_path : $@"; |
362 |
} |
} |
363 |
$icon_html .= qq|<link rel="shortcut icon" type="image/x-icon" href="/$ico_path">| if -e $ico_path; |
$icon_html .= qq|<link rel="shortcut icon" type="image/x-icon" href="/$ico_path">| if -e $ico_path; |
364 |
|
|
365 |
=cut |
=cut |
366 |
|
|
367 |
} else { |
} |
368 |
warn "TODO add $icon_path icon"; |
|
369 |
|
my $warn_colors = { |
370 |
|
'#' => '#444', |
371 |
|
'##' => '#888', |
372 |
|
}; |
373 |
|
|
374 |
|
my $multiline_markers = { |
375 |
|
'(' => ')', |
376 |
|
'{' => '}', |
377 |
|
'[' => ']', |
378 |
|
'"' => '"', |
379 |
|
}; |
380 |
|
|
381 |
|
my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']'; |
382 |
|
warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re"; |
383 |
|
|
384 |
|
sub log_path { |
385 |
|
$Frey::Bootstrap::log_path || warn "no log_path?"; |
386 |
|
} |
387 |
|
|
388 |
|
sub warnings_html { |
389 |
|
my ($self,$level) = shift; |
390 |
|
$level ||= $self->debug, |
391 |
|
my $path = $self->log_path; |
392 |
|
|
393 |
|
my $warnings; |
394 |
|
my $line = 0; |
395 |
|
my $multiline_end; |
396 |
|
|
397 |
|
open(my $log, '<', $path) || die "can't open $path: $!"; |
398 |
|
while(<$log>) { |
399 |
|
chomp; |
400 |
|
$line++; |
401 |
|
|
402 |
|
my $style = ''; |
403 |
|
|
404 |
|
if ( $multiline_end ) { |
405 |
|
if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) { |
406 |
|
warn "## $line end of $multiline_end in '$_'\n"; |
407 |
|
undef $multiline_end; |
408 |
|
} else { |
409 |
|
warn "## $line skipped\n"; |
410 |
|
} |
411 |
|
} elsif ( m{^(#*)\s+} ) { |
412 |
|
my $l = $1 ? length($1) : 0; |
413 |
|
if ( $l > $level ) { |
414 |
|
undef $multiline_end; |
415 |
|
$multiline_end = $multiline_markers->{$1} if m{($multiline_re)$}; |
416 |
|
warn "## $line start $1 .. $multiline_end level $l > $level for '$_'\n" if $multiline_end; |
417 |
|
next; |
418 |
|
} |
419 |
|
|
420 |
|
$style = $warn_colors->{$1} |
421 |
|
? ' style="color:' . $warn_colors->{$1} . '"' |
422 |
|
: ''; |
423 |
|
|
424 |
|
my $msg = $self->html_escape( $_ ); |
425 |
|
my $spacer = ' '; |
426 |
|
if ( length($msg) > $self->chop_warning ) { |
427 |
|
$msg = substr( $msg, 0, $self->chop_warning ); |
428 |
|
$spacer = '…' |
429 |
|
} |
430 |
|
$msg =~ s{^\s}{ }g; |
431 |
|
$warnings .= qq|<tt$style>$msg</tt>$spacer<small><a target="editor" href="/editor+$path+$line">+$line</a></small><br/>|; |
432 |
|
# FIXME <tt> should be <code> but CSS hates me |
433 |
|
} |
434 |
} |
} |
435 |
|
close($log) || die "can't close $path: $!"; |
436 |
|
|
437 |
|
return |
438 |
|
qq|<span class="frey-popup"><a target="editor" href="/editor+$path+$line" title="open $path level $level">warn</a><span>| |
439 |
|
. $self->editor_links( $warnings ) |
440 |
|
. qq|</span></span>| |
441 |
|
; |
442 |
} |
} |
443 |
|
|
444 |
1; |
1; |