/[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 591 by dpavlin, Fri Nov 28 16:39:37 2008 UTC revision 698 by dpavlin, Tue Dec 2 22:23:56 2008 UTC
# Line 3  use Moose; Line 3  use Moose;
3    
4  extends 'Frey';  extends 'Frey';
5  with 'Frey::Web';  with 'Frey::Web';
6    with 'Frey::Path';
7    
8  has commit_path => (  use Moose::Util::TypeConstraints;
9          documentation => 'path to commit',  
10    enum 'SVK_Action' => ( 'commit', 'revert', 'postpone' );
11    
12    has action => (
13          is => 'rw',          is => 'rw',
14          isa => 'Str',          isa => 'SVK_Action',
15    );
16    
17    has path => (
18            documentation => 'path to work with',
19            is => 'rw',
20            isa => 'Str|ArrayRef',
21  );  );
22    
23  has message => (  has commit_message => (
24          documentation => 'commit message',          documentation => 'commit message',
25          is => 'rw',          is => 'rw',
26          isa => 'Str',          isa => 'Str',
# Line 54  sub as_data { Line 64  sub as_data {
64          }          }
65  }  }
66    
67  sub status_as_markup {  sub checkbox {
68            my ($self,$name,$value) = @_;
69            my $checked = '';
70            my $all_checkboxes = $self->$name;
71            $all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty
72            $checked = ' checked' if grep { $_ eq $value } @$all_checkboxes;
73            warn "# checkbox $name $value $checked\t", $self->dump( $self->$name );
74            qq|<input name="$name" value="$value" type="checkbox"$checked>|;
75    }
76    
77    sub commit_as_markup {
78          my ($self) = @_;          my ($self) = @_;
79          my $status = `svk status -q`;          my $status = `svk status -q`;
80          $status =~ s{^(\w+\s+)(\S+)$}{$1<a href="#$2">$2</a>}gm;          $status =~ s{^(\w+[\+\s]+)(\S+)$}{$1 . $self->checkbox('path',$2) . qq|<a href="#$2">$2</a>|}egm;
81          $self->add_css( qq| pre.l a { text-decoration: none; } | );          if ( $status ) {
82          $status = qq|<pre class="l">$status</pre>|;                  $self->add_css(qq|
83          $self->add_status( $status );                          pre.l a { text-decoration: none; }
84          warn "status_as_markup ",length($status)," bytes";                          form.commit {
85                                    background: #eee;
86                                    padding: 1em 1em;
87                                    position: fixed;
88                                    top: 1em;
89                                    right: 1em;
90                                    z-index: 10;
91                            }
92                    | );
93    
94    
95                    $status = qq|
96                            <form class="commit" method="post">
97                            <pre class="l">$status</pre>
98                            <textarea name="commit_message" cols=40 rows=4></textarea>
99                            <br><input type="submit" name="action" value="commit">
100                            </form>
101                    |;
102                    $self->add_status( status => $status );
103                    warn "commit_as_markup ",length($status)," bytes";
104            }
105          return $status;          return $status;
106  }  }
107    
# Line 69  sub diff_as_markup { Line 109  sub diff_as_markup {
109          my ($self) = @_;          my ($self) = @_;
110    
111          my $diff   = `svk diff`;          my $diff   = `svk diff`;
112            $self->add_status( diff => $diff );
113    
114          $diff = $self->html_escape( $diff );          $diff = $self->html_escape( $diff );
115          $self->add_css( qq|          $self->add_css( qq|
116          pre span.add { background: #dfd }          pre span.add { background: #dfd }
117          pre span.del { background: #fdd }          pre span.del { background: #fdd }
118            pre form.inline { display: inline }
119          | );          | );
120          $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;          $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;
121          $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;          $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;
122          $diff =~ s{^(===\s+)(\S+)$}{$1<a name="$2">$2</a>}gm;          sub form {
123                    my ( $path, $action ) = @_;
124                    qq|<form class="inline"><input type="hidden" name="path" value="$path"><input type="submit" name="action" value="$action"></form>|;
125            };
126            $diff =~ s{^(===\s+)(\S+)$}{$1 . form($2,'revert') . qq| <a name="$2" target="editor" href="/editor+$2+1">$2</a> | . form($2,'postpone') }gem;
127    
128          $diff = qq|<pre>$diff</pre>|;          $diff = qq|<pre>$diff</pre>|;
129          warn "diff_as_markup ",length($diff)," bytes";          warn "diff_as_markup ",length($diff)," bytes";
130          return $diff;          return $diff;
131  }  }
132    
133  sub as_markup {  sub action_as_markup {
134          my ($self) = @_;          my ($self) = @_;
135    
136          if ( ! $self->can('html_escape') ) {          my $cmd;
137                  Frey::Web->meta->apply( $self );  
138                  $self->TODO( "Frey::Web role missing" );          if ( $self->action eq 'postpone' ) {
139                    my $old = $self->path;
140                    my $new = $old;
141                    $new =~ s{/([^/]+)$}{/.postponed.$1};
142            
143                    die "Allready have ", $self->path_size($new) if -e $new;
144                    $cmd = "mv $old $new && svk revert $old";
145            } elsif ( $self->action ) {
146                    $cmd = 'svk ' . $self->action;
147                    if ( $self->action eq 'commit' ) {
148                            my $msg = $self->commit_message || return $self->error( "need commit message\n" );
149                            $msg =~ s{"}{\\"}gs;
150                            $cmd .= qq{ -m "$msg"};
151                    } else {
152                            confess "need path" unless $self->path;
153                    }
154                    $cmd .= ' ' . join(' ',$self->path);
155            }
156            if ( $cmd ) {
157                    $cmd .= ' 2>&1';
158                    warn "# cmd $cmd";
159    
160                    my $out = `$cmd`;
161                    warn "# output of $cmd is: $out";
162    
163                    return qq|
164                            Command <tt>$cmd</tt> produced output:
165                            <pre style="background: #ff8;">
166                            $out
167                            </pre>
168                    |;
169          }          }
170    
171          my $html = $self->status_as_markup . $self->diff_as_markup;  }
172    
173    sub as_markup {
174            my ($self) = @_;
175    
176            my $html = $self->action_as_markup;
177    
178            $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title
179    
180            $html .= $self->commit_as_markup . $self->diff_as_markup ||
181                    qq|No changes in tracked files|;
182    
183          warn "as_markup ",length($html)," bytes";          warn "as_markup ",length($html)," bytes";
184    
185          return $html;          return $html;

Legend:
Removed from v.591  
changed lines
  Added in v.698

  ViewVC Help
Powered by ViewVC 1.1.26