--- trunk/lib/Frey/Web.pm 2008/07/17 19:11:01 160 +++ trunk/lib/Frey/Web.pm 2008/10/30 22:35:11 206 @@ -4,6 +4,7 @@ use Continuity::Widget::DomNode; use Data::Dump qw/dump/; use Carp qw/confess/; +use File::Slurp; has 'head' => ( is => 'rw', @@ -11,23 +12,46 @@ 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 { # warn "## dom2html ",dump( @_ ); 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,19 @@ our $reload_counter = 0; + +=head2 page + + $self->page( + title => 'page title', + head => '', + body => 'Page Body', + ); + +=cut + +use Frey::Bookmarklet; + sub page { my $self = shift; my $a = {@_}; @@ -72,7 +109,10 @@ . ( $a->{head} || '' ) . '' . ( $a->{body} || '' ) - . qq|
Frey $Frey::VERSION reload
| + . qq|
+ Frey $Frey::VERSION + reload + Bookmarklets| . Frey::Bookmarklet->markup . qq|| . '' ;