--- trunk/lib/Frey/Web.pm 2008/11/20 11:56:41 473
+++ trunk/lib/Frey/Web.pm 2008/11/26 16:17:17 535
@@ -7,11 +7,12 @@
use Continuity::Widget::DomNode;
use Data::Dump qw/dump/;
-use Carp qw/confess/;
+use Carp qw/confess cluck/;
use File::Slurp;
use Frey::Bookmarklet;
use Frey::ClassBrowser;
+use Frey::SVK;
has 'head' => (
is => 'rw',
@@ -19,16 +20,6 @@
default => sub { [ 'static/frey.css' ] },
);
-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 },
- ] },
-);
-
has 'request_url' => (
is => 'rw',
isa => 'Uri', coerce => 1,
@@ -49,21 +40,44 @@
is => 'rw',
isa => 'Str',
default => 'text/html',
+ documentation => 'Content-type header',
);
-=head2 inline_smaller_than
-
-Inline JavaScript and CSS smaller than this size into page reducing
-round-trips to server.
-
-=cut
+has 'dump_max_bytes' => (
+ is => 'rw',
+ isa => 'Int',
+ default => 4096,
+ documentation => 'Maximum dump size sent to browser before truncation',
+);
has 'inline_smaller_than' => (
is => 'rw',
isa => 'Int',
default => 10240,
+ documentation => 'Inline JavaScript and CSS to reduce round-trips',
);
+has 'chop_warning' => (
+ is => 'rw',
+ isa => 'Int',
+ default => 80,
+ documentation => 'Crop lines longer',
+);
+
+my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
+my $escape_re = join '|' => keys %escape;
+
+sub html_escape {
+ my ( $self, $html ) = @_;
+ $html =~ s/($escape_re)/$escape{$1}/g;
+ return $html;
+}
+
+sub html_dump {
+ my $self = shift;
+ $self->html_escape( dump( @_ ) );
+}
+
sub dom2html {
# warn "## dom2html ",dump( @_ );
return Continuity::Widget::DomNode->create( @_ )->to_string;
@@ -140,25 +154,31 @@
=cut
+our @status;
+sub status { @status };
+
+our $icon_html;
+
sub page {
my $self = shift;
my $a = {@_};
+ warn "## page ",dump($a);
+
$reload_counter++;
my $status_line = '';
- foreach my $part ( @{ $self->status } ) {
- if ( ref($part) ne 'HASH' ) {
- warn "part not hash ",dump( $part ) ;
- #$self->status( $part );
- next;
- }
+
+ unshift @status, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup };
+ unshift @status, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup };
+
+ foreach my $part ( @status ) {
foreach my $name ( keys %$part ) {
my $content = $part->{$name};
if ( ref($content) ) {
$content = '' . dump($content) . '
';
my $l = length($content);
- $content = qq|$l bytes| if $l > 1024;
+ $content = qq|$l bytes| if $l > $self->dump_max_bytes;
} else {
$content = qq|$content|;
}
@@ -180,30 +200,38 @@
$body = '';
}
- $status_line
- .= qq|warn|
- . $self->editor_links( join("", $self->warnings ) )
- . qq|
|
- if $self->warnings;
+ $status_line .= $self->warnings_html;
+
+ my ($exit,$description) = ('exit','stop server');
+ ($exit,$description) = ('restart','restart server')
+ if $ENV{FREY_RESTART}; # tune labels on exit link
my $right =
qq|
- $url
+ reload
+ $exit
|;
+ my $info = Frey::SVK->info;
+ my $revision = Frey::SVK->info->{Revision} || '';
+ $revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)};
+
+ $self->add_icon unless $icon_html;
+
my $html = join("\n",
qq|
but CSS hates me
+ }
+ }
+ close($log) || die "can't close $path: $!";
+
+ return
+ qq|warn|
+ . $self->editor_links( $warnings )
+ . qq||
+ ;
+}
+
1;