/[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 576 by dpavlin, Fri Nov 28 00:09:51 2008 UTC revision 614 by dpavlin, Sat Nov 29 00:20:23 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 => (
8            documentation => 'path to commit',
9            is => 'rw',
10            isa => 'ArrayRef|Str',
11    );
12    
13    has revert_path => (
14            documentation => 'path to commit',
15            is => 'rw',
16            isa => 'ArrayRef|Str',
17    );
18    
19    has message => (
20            documentation => 'commit message',
21            is => 'rw',
22            isa => 'Str',
23    );
24    
25  sub svk {  sub svk {
26          my ( $self, $exec, $coderef ) = @_;          my ( $self, $exec, $coderef ) = @_;
27          open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@";          open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@";
# Line 18  sub modified { Line 36  sub modified {
36          my ($self) = @_;          my ($self) = @_;
37          my @modified;          my @modified;
38          my $svk = $self->svk('status -q', sub {          my $svk = $self->svk('status -q', sub {
39                  push @modified, $1 if /^(M|A)\s+(.+)/;                  push @modified, $1 if /^\w+\s+(.+)/;
40          });          });
41          return @modified;          return @modified;
42  }  }
# Line 42  sub as_data { Line 60  sub as_data {
60          }          }
61  }  }
62    
63  sub as_markup {  sub status_as_markup {
64          my ($self) = @_;          my ($self) = @_;
65            my $status = `svk status -q`;
66          if ( ! $self->can('html_escape') ) {          $status =~ s{^(\w+\s+)(\S+)$}{$1<input name="commit_path" value="$2" type="checkbox"><a href="#$2">$2</a>}gm;
67                  Frey::Web->meta->apply( $self );          if ( $status ) {
68                  $self->TODO( "Frey::Web role missing" );                  $self->add_css( qq| pre.l a { text-decoration: none; } | );
69                    $status = qq|
70                            <form>
71                            <div style="background: #ffd; float: right; padding: 1em;">
72                                    <textarea name="message" width=20 height=4></textarea>
73                                    <br><input type="submit" value="Commit">
74                            </div>
75                            <pre class="l">$status</pre>
76                            </form>
77                    |;
78                    $self->add_status( $status );
79          }          }
80            warn "status_as_markup ",length($status)," bytes";
81            return $status;
82    }
83    
84          my $status = `svk status -q`;  sub diff_as_markup {
85          $status =~ s{^(\w+\s+)(\S+)$}{$1<a href="#$2">$2</a>}gm;          my ($self) = @_;
         $self->add_css( qq| pre.l a { text-decoration: none; } | );  
         $status = qq|<pre class="l">$status</pre>|;  
         $self->add_status( $status );  
86    
87          my $diff   = `svk diff`;          my $diff   = `svk diff`;
88    
# Line 62  sub as_markup { Line 90  sub as_markup {
90          $self->add_css( qq|          $self->add_css( qq|
91          pre span.add { background: #dfd }          pre span.add { background: #dfd }
92          pre span.del { background: #fdd }          pre span.del { background: #fdd }
93            pre form.revert { display: inline }
94          | );          | );
95          $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;          $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;
96          $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;          $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;
97          $diff =~ s{^(===\s+)(\S+)$}{$1<a name="$2">$2</a>}gm;          $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;
98    
99          $diff = qq|<pre>$diff</pre>|;          $diff = qq|<pre>$diff</pre>|;
100            warn "diff_as_markup ",length($diff)," bytes";
101            return $diff;
102    }
103    
104    sub as_markup {
105            my ($self) = @_;
106    
107            my $html = '';
108    
109            if ( $self->revert_path ) {
110                    my $cmd = 'svk revert ' . join(' ', $self->revert_path );
111                    my $revert = `$cmd`;
112                    warn "$cmd $revert";
113                    $html .= qq|<code style="background: #ff8;">$revert</code>|;
114            }
115    
116            $self->title('svk'); # XXX without this we get wrong icon and title
117    
118            if ( ! $self->can('html_escape') ) {
119                    Frey::Web->meta->apply( $self );
120                    $self->TODO( "Frey::Web role missing" );
121            }
122    
123            $html .= $self->status_as_markup || $self->error('no status_or_markup output');
124            $html .= $self->diff_as_markup   || $self->error('no diff_as_markup output');
125    
126          my $html = $status . $diff;          warn "as_markup ",length($html)," bytes";
         warn "html ",length($html)," bytes";  
127    
128          return $html;          return $html;
129  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26