/[Frey]/trunk/lib/Frey/SVK.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/SVK.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 614 by dpavlin, Sat Nov 29 00:20:23 2008 UTC revision 615 by dpavlin, Sat Nov 29 01:01:14 2008 UTC
# Line 4  use Moose; Line 4  use Moose;
4  extends 'Frey';  extends 'Frey';
5  with 'Frey::Web';  with 'Frey::Web';
6    
7  has commit_path => (  use Moose::Util::TypeConstraints;
8          documentation => 'path to commit',  
9    enum 'SVK_Action' => ( 'commit', 'revert' );
10    
11    has action => (
12          is => 'rw',          is => 'rw',
13          isa => 'ArrayRef|Str',          isa => 'SVK_Action',
14  );  );
15    
16  has revert_path => (  has path => (
17          documentation => 'path to commit',          documentation => 'path to work with',
18          is => 'rw',          is => 'rw',
19          isa => 'ArrayRef|Str',          isa => 'Str',
20  );  );
21    
22  has message => (  has message => (
# Line 63  sub as_data { Line 66  sub as_data {
66  sub status_as_markup {  sub status_as_markup {
67          my ($self) = @_;          my ($self) = @_;
68          my $status = `svk status -q`;          my $status = `svk status -q`;
69          $status =~ s{^(\w+\s+)(\S+)$}{$1<input name="commit_path" value="$2" type="checkbox"><a href="#$2">$2</a>}gm;  #       $status =~ s{^(\w+\s+)(\S+)$}{$1<input name="commit_path" value="$2" type="checkbox"><a href="#$2">$2</a>}gm; # FIXME
70            $status =~ s{^(\w+\s+)(\S+)$}{$1<a href="#$2">$2</a>}gm;
71          if ( $status ) {          if ( $status ) {
72                  $self->add_css( qq| pre.l a { text-decoration: none; } | );                  $self->add_css(qq|
73                            pre.l a { text-decoration: none; }
74                            div.commit {
75                                    background: #ffd;
76                                    padding: 1em 1em;
77                                    position: fixed;
78                                    top: 1em;
79                                    right: 1em;
80                                    z-index: 10;
81                            }
82                    | );
83    
84                  $status = qq|                  $status = qq|
85                          <form>                          <div class="commit">
86                          <div style="background: #ffd; float: right; padding: 1em;">                                  <form>
87                                  <textarea name="message" width=20 height=4></textarea>                                  <textarea name="message" cols=40 rows=4></textarea>
88                                  <br><input type="submit" value="Commit">                                  <br><input type="submit" name="action" value="commit">
89                                    </form>
90                          </div>                          </div>
91                          <pre class="l">$status</pre>                          <pre class="l">$status</pre>
                         </form>  
92                  |;                  |;
93                  $self->add_status( $status );                  $self->add_status( $status );
94    
95          }          }
96          warn "status_as_markup ",length($status)," bytes";          warn "status_as_markup ",length($status)," bytes";
97          return $status;          return $status;
# Line 94  sub diff_as_markup { Line 110  sub diff_as_markup {
110          | );          | );
111          $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;          $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;
112          $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;          $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;
113          $diff =~ s{^(===\s+)(\S+)$}{$1<form class="revert"><input type="hidden" name="revert_path" value="$2"><input type="submit" value="Revert"></form> <a name="$2">$2</a>}gm;          $diff =~ s{^(===\s+)(\S+)$}{$1<form class="revert"><input type="hidden" name="path" value="$2"><input type="submit" name="action" value="revert"></form> <a name="$2">$2</a>}gm;
114    
115          $diff = qq|<pre>$diff</pre>|;          $diff = qq|<pre>$diff</pre>|;
116          warn "diff_as_markup ",length($diff)," bytes";          warn "diff_as_markup ",length($diff)," bytes";
# Line 106  sub as_markup { Line 122  sub as_markup {
122    
123          my $html = '';          my $html = '';
124    
125          if ( $self->revert_path ) {          if ( $self->action ) {
126                  my $cmd = 'svk revert ' . join(' ', $self->revert_path );                  my $cmd = 'svk ' . $self->action . ' ' . $self->path;
127                  my $revert = `$cmd`;                  if ( $self->action eq 'commit' ) {
128                  warn "$cmd $revert";                          confess "need message" unless $self->message;
129                  $html .= qq|<code style="background: #ff8;">$revert</code>|;                          my $msg = $self->message;
130                            $msg =~ s{"}{\\"}gs;
131                            $cmd .= qq{ -m "$msg"};
132                    } else {
133                            confess "need path" unless $self->path;
134                    }
135                    $cmd .= ' 2>&1';
136                    my $out = `$cmd`;
137                    warn "$cmd $out";
138                    $html .= qq|
139                            <code style="background: #ff8;">
140                            $cmd\n
141                            <b>$out</b>
142                            </code>
143                    |;
144          }          }
145    
146          $self->title('svk'); # XXX without this we get wrong icon and title          $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title
147    
148          if ( ! $self->can('html_escape') ) {          if ( ! $self->can('html_escape') ) {
149                  Frey::Web->meta->apply( $self );                  Frey::Web->meta->apply( $self );

Legend:
Removed from v.614  
changed lines
  Added in v.615

  ViewVC Help
Powered by ViewVC 1.1.26