--- trunk/lib/Frey/SVK.pm 2008/11/27 15:40:12 552 +++ trunk/lib/Frey/SVK.pm 2008/12/02 22:16:44 695 @@ -3,6 +3,28 @@ extends 'Frey'; with 'Frey::Web'; +with 'Frey::Path'; + +use Moose::Util::TypeConstraints; + +enum 'SVK_Action' => ( 'commit', 'revert', 'postpone' ); + +has action => ( + is => 'rw', + isa => 'SVK_Action', +); + +has path => ( + documentation => 'path to work with', + is => 'rw', + isa => 'Str|ArrayRef', +); + +has commit_message => ( + documentation => 'commit message', + is => 'rw', + isa => 'Str', +); sub svk { my ( $self, $exec, $coderef ) = @_; @@ -18,7 +40,7 @@ my ($self) = @_; my @modified; my $svk = $self->svk('status -q', sub { - push @modified, $1 if /^(M|A)\s+(.+)/; + push @modified, $1 if /^\w+\s+(.+)/; }); return @modified; } @@ -31,6 +53,7 @@ my ( $label, $value ) = split(/:\s+/, $_, 2); $info->{$label} = $value if $label; }); + warn "# svk info ",$self->dump( $info ); return $info; } @@ -41,20 +64,122 @@ } } -sub as_markup { - my ($self) = @_; +sub checkbox { + my ($self,$name,$value) = @_; + my $checked = ''; + my $all_checkboxes = $self->$name; + $all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty + $checked = ' checked' if grep { $_ eq $value } @$all_checkboxes; + warn "# checkbox $name $value $checked\t", $self->dump( $self->$name ); + qq||; +} +sub commit_as_markup { + my ($self) = @_; my $status = `svk status -q`; + $status =~ s{^(\w+[\+\s]+)(\S+)$}{$1 . $self->checkbox('path',$2) . qq|$2|}egm; + if ( $status ) { + $self->add_css(qq| + pre.l a { text-decoration: none; } + form.commit { + background: #eee; + padding: 1em 1em; + position: fixed; + top: 1em; + right: 1em; + z-index: 10; + } + | ); + + + $status = qq| +
+
$status
+ +
+
+ |; + $self->add_status( status => $status ); + warn "commit_as_markup ",length($status)," bytes"; + } + return $status; +} + +sub diff_as_markup { + my ($self) = @_; + my $diff = `svk diff`; + $self->add_status( diff => $diff ); + + $diff = $self->html_escape( $diff ); + $self->add_css( qq| + pre span.add { background: #dfd } + pre span.del { background: #fdd } + pre form.inline { display: inline } + | ); + $diff =~ s{^(\+.+?)$}{$1}gm; + $diff =~ s{^(\-.+?)$}{$1}gm; + sub form { + my ( $path, $action ) = @_; + qq|
|; + }; + $diff =~ s{^(===\s+)(\S+)$}{$1 . form($2,'revert') . qq| $2 | . form($2,'postpone') }gem; + + $diff = qq|
$diff
|; + warn "diff_as_markup ",length($diff)," bytes"; + return $diff; +} + +sub action_as_markup { + my ($self) = @_; + + my $cmd; + + if ( $self->action eq 'postpone' ) { + my $old = $self->path; + my $new = $old; + $new =~ s{/([^/]+)$}{/.postponed.$1}; + + die "Allready have ", $self->path_size($new) if -e $new; + $cmd = "mv $old $new && svk revert $old"; + } elsif ( $self->action ) { + $cmd = 'svk ' . $self->action; + if ( $self->action eq 'commit' ) { + my $msg = $self->commit_message || return $self->error( "need commit message\n" ); + $msg =~ s{"}{\\"}gs; + $cmd .= qq{ -m "$msg"}; + } else { + confess "need path" unless $self->path; + } + $cmd .= ' ' . join(' ',$self->path); + } + if ( $cmd ) { + $cmd .= ' 2>&1'; + warn "# cmd $cmd"; + + my $out = `$cmd`; + warn "# output of $cmd is: $out"; + + return qq| + Command $cmd produced output: +
+			$out
+			
+ |; + } + +} + +sub as_markup { + my ($self) = @_; + + my $html = $self->action_as_markup; + + $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title - Frey::Web->meta->apply( $self ); # provide html_escape + $html .= $self->commit_as_markup . $self->diff_as_markup; - my $html - = qq|
$status

|
-		. $self->html_escape( $diff )
-		. qq|
| - ; - warn "diff ",length($html)," bytes"; + warn "as_markup ",length($html)," bytes"; return $html; }