--- trunk/lib/Frey/Web.pm 2008/12/14 22:15:51 838 +++ trunk/lib/Frey/Web.pm 2008/12/19 14:10:03 881 @@ -94,7 +94,7 @@ sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } -our $re_html = qr{<(?:!--.+?--|(\w+).+?/\1|[^>]+/?)>}s; # relaxed html check for one semi-valid tag +our $re_html = qr{<(?:!--|(\w+)|[^>]+)/?>}s; # relaxed html check for one semi-valid tag sub popup_dropdown { my ( $self, $type, $name, $content, $full ) = @_; @@ -116,9 +116,11 @@ } } -sub _inline_path { +sub _inline { my ( $self, $path ) = @_; - -s $path < $self->inline_smaller_than; + return unless defined $path; + warn "# _inline $path"; + -e $path && -s $path < $self->inline_smaller_than && -s $path; } sub _head_html { @@ -127,12 +129,14 @@ foreach my $path ( @head ) { $path =~ s!^/!!; if ( $path =~ m/\.js$/ ) { - $out .= $self->_inline_path( $path ) ? - qq|| : + my $size; + $out .= $size = _inline( $path ) ? + qq|| : qq||; } elsif ( $path =~ m/\.css$/ ) { - $out .= $self->_inline_path( $path ) ? - qq|| : + my $size; + $out .= $size = _inline( $path ) ? + qq|| : qq||; } elsif ( $path =~ m{<.+>}s ) { $out .= $path; @@ -174,38 +178,53 @@ } -sub _add_something { - my ( $self, $regex, $tag, $type, $content ) = @_; +sub _add_css_js { + my ( $self, $what, $content ) = @_; - my ( $package, $path, $line ) = caller(1); + my $tag = $what eq 'css' ? 'style' : 'script'; + my $type = $what eq 'css' ? 'text/css' : 'text/javascript'; + my $head; - warn "# $regex $tag $type $content caller $package $path $line"; + my ( $package, $path, $line ) = caller(1); - if ( $content =~ $regex ) { + if ( $content =~ m{\.(js|css)} ) { $content = "/$content" if -e $content; - $self->add_head( strip ( qq| - <$tag type="$type" src="$content"> - /* via $package at $path line $line */ - - | ) ); + if ( $content =~ $re_html ) { + $head = qq| + $content + + |; + } elsif ( $what eq 'js' ) { + $head = qq| + <$tag type="$type" src="$content"> + /* $what via $package at $path line $line */ + + |; + } else { + $head = qq| + + + |; + } } else { - $self->add_head(qq| + $head = qq| <$tag type="$type"> /* via $package at $path line $line */ $content - |); + |; }; + $self->add_head( $head ); } sub add_css { my ($self,$css) = @_; - $self->_add_something( qr{\.css$}, qw{style text/css}, $css ); + $self->_add_css_js( 'css', $css ); } sub add_js { my ($self,$js) = @_; - $self->_add_something( qr{\.js$}, qw{script text/javascript}, $js ); + $self->_add_css_js( 'js', $js ); } our $reload_counter = 0;