--- trunk/lib/Frey/Web.pm 2008/12/04 20:20:45 720 +++ trunk/lib/Frey/Web.pm 2008/12/11 21:36:04 816 @@ -3,21 +3,22 @@ with 'Frey::Session'; -use Frey::Types; - #use Continuity::Widget::DomNode; use Data::Dump qw/dump/; use Carp qw/confess cluck carp/; use File::Slurp; +use Text::Tabs; # expand, unexpand + +use lib 'lib'; + +use Frey::Types; use Frey::Bookmarklet; -use Frey::ClassBrowser; +use Frey::Class::Browser; use Frey::INC; use Frey::SVK; -use Text::Tabs; # expand, unexpand - our @head; sub head { @head } @@ -93,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+).+?/\1|[^>]+/?)>}s; # relaxed html check for one semi-valid tag sub popup_dropdown { my ( $self, $type, $name, $content, $full ) = @_; @@ -184,6 +185,26 @@ | ); } +sub add_js { + my ($self,$js) = @_; + my ( $package, $path, $line ) = caller; + + if ( $js =~ m{http.*\.js} ) { + $self->add_head( qq| + + |); + } else { + $self->add_head( qq| + + | ); + }; +} + our $reload_counter = 0; @@ -408,7 +429,7 @@ my ($self) = shift; @head = ( 'static/frey.css' ); @status = ( - { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, + { 'ClassBrowser' => Frey::Class::Browser->new( usage_sort => 1, usage_on_top => 0 )->as_markup }, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, { 'INC' => Frey::INC->new->as_markup }, ); @@ -445,15 +466,28 @@ sub icon_path { my ($self,$class,$variant) = @_; - my $icon = $class; - $icon =~ s{::}{/}g; - $icon .= "/$variant" if $variant; - my $path = 'static/icons/' . $icon . '.png'; +# $class ||= $self->title; + + sub icon_exists { + my $class = shift; + $class =~ s{::}{/}g; + $class .= "/$variant" if $variant; + my $icon_path = 'static/icons/' . $class . '.png'; + return $icon_path if -e $icon_path; + return; + } + + my $path = icon_exists( $class ); + + while ( $class =~ s{::[^:]+$}{} && ! $path ) { + $path = icon_exists( $class ) unless $class eq 'Frey'; # don't default on Frey icon + } + if ( -e $path ) { warn "# $class from $self icon_path $path" if $self->debug; return $path; } else { - $self->TODO( "add $path icon for $class" ); + $self->TODO( "add $path icon for $class $variant" ); return undef; } } @@ -659,11 +693,28 @@ sub checkbox { my ($self,$name,$value) = @_; my $checked = ''; - my $all_checkboxes = $self->$name; + my $all_checkboxes = eval { $self->$name }; + warn "ERROR tried to get checkbox value for '$name' which is unknown: $@" if $@; $all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty - $checked = ' checked' if grep { $_ eq $value } @$all_checkboxes; + $checked = ' checked' if grep { defined $_ && $_ eq $value } @$all_checkboxes; warn "# checkbox $name $value $checked\t", $self->dump( $self->$name ); qq||; } +=head2 strip + +Strip whitespace around content + + my $stripped = strip(' no more whitespace around this '); + +=cut + +sub strip { + my $t = shift; + $t =~ s{^\s+}{}gs; + $t =~ s{>\s+<}{><}gs; + $t =~ s{\s+$}{}gs; + return $t; +} + 1;