--- trunk/lib/Frey/Web.pm 2008/11/26 19:43:03 543 +++ trunk/lib/Frey/Web.pm 2008/11/27 22:09:59 568 @@ -1,9 +1,11 @@ package Frey::Web; use Moose::Role; +with 'Frey::Session'; + use Frey::Types; -use Continuity::Widget::DomNode; +#use Continuity::Widget::DomNode; use Data::Dump qw/dump/; use Carp qw/confess cluck/; use File::Slurp; @@ -84,9 +86,25 @@ return "$dump"; } -sub dom2html { -# warn "## dom2html ",dump( @_ ); - return Continuity::Widget::DomNode->create( @_ )->to_string; +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 + +sub popup_dropdown { + my ( $self, $type, $name, $content, $full ) = @_; + + $content = $self->html_dump($content) if ref $content; + + $content = qq|$content| unless $content =~ m{^\s*<(span|a|code).+?/\1>\s*}; + + warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug; + + if ( $name =~ m{::} && $name !~ $re_html ) { + return qq|$name $content\n|; + } else { + return qq|$name $content\n|; + } } sub _inline_path { @@ -132,7 +150,7 @@ return if ! defined $path || $path eq ''; $path =~ s!^/!!; - if ( $path =~ m{<.*>}s ) { + if ( $path =~ $re_html ) { push @{ $self->head }, $path; } elsif ( -e $path ) { if ( $path =~ m/\.(?:js|css)$/ ) { @@ -165,29 +183,6 @@ our $icon_html; -sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } -sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } - -sub popup_dropdown { - my ( $self, $type, $name, $content, $full ) = @_; - - if ( ref($content) ) { - $content = $self->html_dump($content); -# my $l = length($content); -# $content = qq|$l bytes| if ! $full && $l > $self->dump_max_bytes; - } else { - $content = qq|$content|; - } - - warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug; - - if ( $name =~ m{::} && ! $name =~ m{<(\w+).+?/\1>} ) { - return qq|$name $content\n|; - } else { - return qq|$name $content\n|; - } -} - sub page { my $self = shift; my $a = {@_}; @@ -335,11 +330,15 @@ warn "## status parts ", dump( map { keys %$_ } @status ); } +=for debug + sub DEMOLISH { my ( $self ) = @_; warn "## $self DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status; } +=cut + =head2 add_icon Frey::Foo->add_icon; # /static/icons/Frey/Foo.png @@ -357,7 +356,7 @@ warn "# $class from $self icon_path $path"; return $path; } else { - warn "TODO: add $path icon for $class"; + $self->TODO( "add $path icon for $class" ); return undef; } }