--- trunk/lib/Frey/Web.pm 2008/07/17 18:00:28 157
+++ trunk/lib/Frey/Web.pm 2008/07/17 22:26:21 163
@@ -4,11 +4,18 @@
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' ] },
+);
+
+has 'inline_smaller_than' => (
+ is => 'rw',
+ isa => 'Int',
+ default => 10240,
);
sub dom2html {
@@ -16,18 +23,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;
}