--- trunk/lib/Frey/SVK.pm 2008/11/28 19:23:38 603 +++ trunk/lib/Frey/SVK.pm 2008/11/29 16:17:18 620 @@ -4,13 +4,22 @@ extends 'Frey'; with 'Frey::Web'; -has commit_path => ( - documentation => 'path to commit', +use Moose::Util::TypeConstraints; + +enum 'SVK_Action' => ( 'commit', 'revert' ); + +has action => ( is => 'rw', - isa => 'ArrayRef|Str', + isa => 'SVK_Action', ); -has message => ( +has path => ( + documentation => 'path to work with', + is => 'rw', + isa => 'Str', +); + +has commit_message => ( documentation => 'commit message', is => 'rw', isa => 'Str', @@ -57,19 +66,32 @@ sub status_as_markup { my ($self) = @_; my $status = `svk status -q`; - $status =~ s{^(\w+\s+)(\S+)$}{$1$2}gm; +# $status =~ s{^(\w+\s+)(\S+)$}{$1$2}gm; # FIXME + $status =~ s{^(\w+\s+)(\S+)$}{$1$2}gm; if ( $status ) { - $self->add_css( qq| pre.l a { text-decoration: none; } | ); + $self->add_css(qq| + pre.l a { text-decoration: none; } + div.commit { + background: #ffd; + padding: 1em 1em; + position: fixed; + top: 1em; + right: 1em; + z-index: 10; + } + | ); + $status = qq| -
-
- -
+
+ + +
+
$status
- |; $self->add_status( $status ); + } warn "status_as_markup ",length($status)," bytes"; return $status; @@ -84,10 +106,11 @@ $self->add_css( qq| pre span.add { background: #dfd } pre span.del { background: #fdd } + pre form.revert { display: inline } | ); $diff =~ s{^(\+.+?)$}{$1}gm; $diff =~ s{^(\-.+?)$}{$1}gm; - $diff =~ s{^(===\s+)(\S+)$}{$1$2}gm; + $diff =~ s{^(===\s+)(\S+)$}{$1
$2}gm; $diff = qq|
$diff
|; warn "diff_as_markup ",length($diff)," bytes"; @@ -97,15 +120,39 @@ sub as_markup { my ($self) = @_; + my $html = ''; + + if ( $self->action ) { + my $cmd = 'svk ' . $self->action . ' ' . $self->path; + if ( $self->action eq 'commit' ) { + confess "need commit message" unless $self->commit_message; + my $msg = $self->commit_message; + $msg =~ s{"}{\\"}gs; + $cmd .= qq{ -m "$msg"}; + } else { + confess "need path" unless $self->path; + } + $cmd .= ' 2>&1'; + my $out = `$cmd`; + warn "$cmd $out"; + $html .= qq| + + $cmd\n + $out + + |; + } + + $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title + if ( ! $self->can('html_escape') ) { Frey::Web->meta->apply( $self ); $self->TODO( "Frey::Web role missing" ); } - my $html - = ( $self->status_as_markup || $self->error('no status_or_markup output') ) - . ( $self->diff_as_markup || $self->error('no diff_as_markup output') ) - ; + $html .= $self->status_as_markup || 'No changes in files tracked by SVK'; + $html .= $self->diff_as_markup; + warn "as_markup ",length($html)," bytes"; return $html;