--- trunk/lib/Frey/Web.pm 2008/07/17 17:55:39 156 +++ trunk/lib/Frey/Web.pm 2008/11/17 20:14:12 385 @@ -4,11 +4,25 @@ use Continuity::Widget::DomNode; use Data::Dump qw/dump/; use Carp qw/confess/; +use File::Slurp; has 'head' => ( is => 'rw', isa => 'ArrayRef[Str]', - default => sub { [] }, + default => sub { [ 'static/frey.css' ] }, +); + +=head2 inline_smaller_than + +Inline JavaScript and CSS smaller than this size into page reducing +round-trips to server. + +=cut + +has 'inline_smaller_than' => ( + is => 'rw', + isa => 'Int', + default => 10240, ); sub dom2html { @@ -16,18 +30,28 @@ return Continuity::Widget::DomNode->create( @_ )->to_string; } +sub _inline_path { + my ( $self, $path ) = @_; + -s $path < $self->inline_smaller_than; +} + sub _head_html { my $self = shift; my $out = ''; foreach my $path ( @{ $self->head } ) { $path =~ s!^/!!; if ( $path =~ m/\.js$/ ) { - $out .= qq||; + $out .= $self->_inline_path( $path ) ? + qq|| : + qq||; } elsif ( $path =~ m/\.css$/ ) { - $out .= qq||; + $out .= $self->_inline_path( $path ) ? + qq|| : + qq||; } else { confess "don't know how to render $path"; } + $out .= "\n"; } return $out; } @@ -60,6 +84,20 @@ our $reload_counter = 0; + +=head2 page + + $self->page( + title => 'page title', + head => '', + body => 'Page Body', + ); + +=cut + +use Frey::Bookmarklet; +use Frey::ClassBrowser; + sub page { my $self = shift; my $a = {@_}; @@ -69,16 +107,30 @@ my $html = qq|| . $self->_head_html . '' . ( $a->{title} || ref($self) ) . '' + . '' . ( $a->{head} || '' ) . '' . ( $a->{body} || '' ) -# . qq|
Frey $Frey::VERSION reload
| - . '' - ; + . qq|
+ Frey $Frey::VERSION + | . dump( $ENV{'REQUEST_URI'} ) . qq| + Bookmarklets| . Frey::Bookmarklet->markup . qq| + ClassBrowser| . Frey::ClassBrowser->markup . qq| + ENV| . dump( %ENV ) . qq| +
+ + |; warn "## >>> page ",length($html), " bytes\n" if $self->debug; return $html; } +sub error { + my ( $self, $error ) = @_; + warn $error; + $error =~ s{at\s+(\S+)\s+line\s+(\d+)}{ $1 line $2}gsm; + return qq|
$error
|; +} + 1;