4 |
extends 'Frey'; |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
with 'Frey::Web'; |
6 |
|
|
7 |
|
use Moose::Util::TypeConstraints; |
8 |
|
|
9 |
|
enum 'SVK_Action' => ( 'commit', 'revert' ); |
10 |
|
|
11 |
|
has action => ( |
12 |
|
is => 'rw', |
13 |
|
isa => 'SVK_Action', |
14 |
|
); |
15 |
|
|
16 |
|
has path => ( |
17 |
|
documentation => 'path to work with', |
18 |
|
is => 'rw', |
19 |
|
isa => 'Str', |
20 |
|
); |
21 |
|
|
22 |
|
has commit_message => ( |
23 |
|
documentation => 'commit message', |
24 |
|
is => 'rw', |
25 |
|
isa => 'Str', |
26 |
|
); |
27 |
|
|
28 |
sub svk { |
sub svk { |
29 |
my ( $self, $exec, $coderef ) = @_; |
my ( $self, $exec, $coderef ) = @_; |
30 |
open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@"; |
open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@"; |
39 |
my ($self) = @_; |
my ($self) = @_; |
40 |
my @modified; |
my @modified; |
41 |
my $svk = $self->svk('status -q', sub { |
my $svk = $self->svk('status -q', sub { |
42 |
push @modified, $1 if /^M\s+(.+)/; |
push @modified, $1 if /^\w+\s+(.+)/; |
43 |
}); |
}); |
44 |
return @modified; |
return @modified; |
45 |
} |
} |
52 |
my ( $label, $value ) = split(/:\s+/, $_, 2); |
my ( $label, $value ) = split(/:\s+/, $_, 2); |
53 |
$info->{$label} = $value if $label; |
$info->{$label} = $value if $label; |
54 |
}); |
}); |
55 |
|
warn "# svk info ",$self->dump( $info ); |
56 |
return $info; |
return $info; |
57 |
} |
} |
58 |
|
|
63 |
} |
} |
64 |
} |
} |
65 |
|
|
66 |
sub 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; # FIXME |
70 |
|
$status =~ s{^(\w+\s+)(\S+)$}{$1<a href="#$2">$2</a>}gm; |
71 |
|
if ( $status ) { |
72 |
|
$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| |
85 |
|
<div class="commit" method="post"> |
86 |
|
<form> |
87 |
|
<textarea name="commit_message" cols=40 rows=4></textarea> |
88 |
|
<br><input type="submit" name="action" value="commit"> |
89 |
|
</form> |
90 |
|
</div> |
91 |
|
<pre class="l">$status</pre> |
92 |
|
|; |
93 |
|
$self->add_status( $status ); |
94 |
|
|
95 |
|
} |
96 |
|
warn "status_as_markup ",length($status)," bytes"; |
97 |
|
return $status; |
98 |
|
} |
99 |
|
|
100 |
|
sub diff_as_markup { |
101 |
|
my ($self) = @_; |
102 |
|
|
103 |
my $diff = `svk diff`; |
my $diff = `svk diff`; |
104 |
|
|
105 |
my $html |
$diff = $self->html_escape( $diff ); |
106 |
= qq|<pre>$status</pre><hr><pre>| |
$self->add_css( qq| |
107 |
# . $self->html_escape( $diff ) |
pre span.add { background: #dfd } |
108 |
. $diff |
pre span.del { background: #fdd } |
109 |
. qq|</pre>| |
pre form.revert { display: inline } |
110 |
; |
| ); |
111 |
warn "diff ",length($html)," bytes"; |
$diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm; |
112 |
|
$diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm; |
113 |
|
$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" target="editor" href="/editor+$2+1">$2</a>}gm; |
114 |
|
|
115 |
|
$diff = qq|<pre>$diff</pre>|; |
116 |
|
warn "diff_as_markup ",length($diff)," bytes"; |
117 |
|
return $diff; |
118 |
|
} |
119 |
|
|
120 |
|
sub as_markup { |
121 |
|
my ($self) = @_; |
122 |
|
|
123 |
|
my $html = ''; |
124 |
|
|
125 |
|
if ( $self->action ) { |
126 |
|
my $cmd = 'svk ' . $self->action . ' ' . $self->path; |
127 |
|
if ( $self->action eq 'commit' ) { |
128 |
|
confess "need commit message" unless $self->commit_message; |
129 |
|
my $msg = $self->commit_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' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title |
147 |
|
|
148 |
|
if ( ! $self->can('html_escape') ) { |
149 |
|
Frey::Web->meta->apply( $self ); |
150 |
|
$self->TODO( "Frey::Web role missing" ); |
151 |
|
} |
152 |
|
|
153 |
|
$html .= $self->status_as_markup || 'No changes in files tracked by SVK'; |
154 |
|
$html .= $self->diff_as_markup; |
155 |
|
|
156 |
|
warn "as_markup ",length($html)," bytes"; |
157 |
|
|
158 |
return $html; |
return $html; |
159 |
} |
} |