--- trunk/lib/Frey/Web.pm 2008/12/02 18:29:01 685 +++ trunk/lib/Frey/Web.pm 2008/12/09 20:31:42 781 @@ -184,6 +184,17 @@ | ); } +sub add_js { + my ($self,$css) = @_; + my ( $package, $path, $line ) = caller; + $self->add_head( qq| + + | ); +} + our $reload_counter = 0; @@ -446,6 +457,7 @@ sub icon_path { my ($self,$class,$variant) = @_; my $icon = $class; + $icon ||= $self->title; $icon =~ s{::}{/}g; $icon .= "/$variant" if $variant; my $path = 'static/icons/' . $icon . '.png'; @@ -648,4 +660,39 @@ return @backtrace; } +=head2 checkbox + +Generate checkbox html markup from some attribute + + my $html = $self->checkbox('attribute_name', $value); + +=cut + +sub checkbox { + my ($self,$name,$value) = @_; + my $checked = ''; + 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 { 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;