1 |
package Frey::Web; |
package Frey::Web; |
2 |
use Moose::Role; |
use Moose::Role; |
3 |
|
|
4 |
|
with 'Frey::Session'; |
5 |
|
|
6 |
use Frey::Types; |
use Frey::Types; |
7 |
|
|
8 |
use Continuity::Widget::DomNode; |
#use Continuity::Widget::DomNode; |
9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
use Carp qw/confess cluck/; |
use Carp qw/confess cluck/; |
11 |
use File::Slurp; |
use File::Slurp; |
16 |
|
|
17 |
use Frey::SVK; |
use Frey::SVK; |
18 |
|
|
19 |
has 'head' => ( |
our @head = ( 'static/frey.css' ); |
|
is => 'rw', |
|
|
isa => 'ArrayRef[Str]', |
|
|
default => sub { [ 'static/frey.css' ] }, |
|
|
); |
|
20 |
|
|
21 |
has 'request_url' => ( |
has 'request_url' => ( |
22 |
is => 'rw', |
is => 'rw', |
103 |
} |
} |
104 |
} |
} |
105 |
|
|
|
sub dom2html { |
|
|
# warn "## dom2html ",dump( @_ ); |
|
|
return Continuity::Widget::DomNode->create( @_ )->to_string; |
|
|
} |
|
|
|
|
106 |
sub _inline_path { |
sub _inline_path { |
107 |
my ( $self, $path ) = @_; |
my ( $self, $path ) = @_; |
108 |
-s $path < $self->inline_smaller_than; |
-s $path < $self->inline_smaller_than; |
111 |
sub _head_html { |
sub _head_html { |
112 |
my $self = shift; |
my $self = shift; |
113 |
my $out = ''; |
my $out = ''; |
114 |
foreach my $path ( @{ $self->head } ) { |
foreach my $path ( @head ) { |
115 |
$path =~ s!^/!!; |
$path =~ s!^/!!; |
116 |
if ( $path =~ m/\.js$/ ) { |
if ( $path =~ m/\.js$/ ) { |
117 |
$out .= $self->_inline_path( $path ) ? |
$out .= $self->_inline_path( $path ) ? |
147 |
$path =~ s!^/!!; |
$path =~ s!^/!!; |
148 |
|
|
149 |
if ( $path =~ $re_html ) { |
if ( $path =~ $re_html ) { |
150 |
push @{ $self->head }, $path; |
push @head, $path; |
151 |
} elsif ( -e $path ) { |
} elsif ( -e $path ) { |
152 |
if ( $path =~ m/\.(?:js|css)$/ ) { |
if ( $path =~ m/\.(?:js|css)$/ ) { |
153 |
push @{ $self->head }, $path; |
push @head, $path; |
154 |
} else { |
} else { |
155 |
confess "can't add_head( $path ) it's not js or css"; |
confess "can't add_head( $path ) it's not js or css"; |
156 |
} |
} |
161 |
|
|
162 |
} |
} |
163 |
|
|
164 |
|
sub add_css { |
165 |
|
my ($self,$css) = @_; |
166 |
|
my ( $package, $path, $line ) = caller; |
167 |
|
$self->add_head( qq| |
168 |
|
<style type="text/css"> |
169 |
|
/* via package $package at $path line $line */ |
170 |
|
$css |
171 |
|
</style> |
172 |
|
| ); |
173 |
|
} |
174 |
|
|
175 |
our $reload_counter = 0; |
our $reload_counter = 0; |
176 |
|
|
177 |
|
|
237 |
</span> |
</span> |
238 |
|; |
|; |
239 |
|
|
240 |
my $info = Frey::SVK->info; |
my $svk = Frey::SVK->new; |
241 |
my $revision = Frey::SVK->info->{Revision} || ''; |
my $info = $svk->info; |
242 |
|
my $revision = $svk->info->{Revision} || ''; |
243 |
$revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)}; |
$revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)}; |
244 |
|
|
245 |
$self->add_icon unless $icon_html; |
$self->add_icon unless $icon_html; |
324 |
; |
; |
325 |
} |
} |
326 |
|
|
327 |
|
=head1 Status line |
328 |
|
|
329 |
|
=head2 add_status |
330 |
|
|
331 |
|
$self->add_status( name => { some => 'data' } ); |
332 |
|
|
333 |
|
$self->add_status( "append to last status popup" ); |
334 |
|
|
335 |
|
=cut |
336 |
|
|
337 |
sub add_status { |
sub add_status { |
338 |
my ( $self, $data ) = @_; |
my ( $self, $data ) = @_; |
339 |
push @status, $data; |
if ( ref($data) ) { |
340 |
|
push @status, $data; |
341 |
|
} else { |
342 |
|
$status[ $#status ]->{added} = $data; |
343 |
|
} |
344 |
} |
} |
345 |
|
|
346 |
|
=head2 clean_status |
347 |
|
|
348 |
|
Called at beginning of each request |
349 |
|
|
350 |
|
$self->clean_status; |
351 |
|
|
352 |
|
=cut |
353 |
|
|
354 |
sub clean_status { |
sub clean_status { |
355 |
|
my ($self) = shift; |
356 |
|
@head = (); |
357 |
@status = (); |
@status = (); |
358 |
$icon_html = ''; |
$icon_html = ''; |
359 |
} |
} |
360 |
|
|
361 |
|
=head2 status_parts |
362 |
|
|
363 |
|
Dump all status line parts |
364 |
|
|
365 |
|
$self->status_parts |
366 |
|
|
367 |
|
=cut |
368 |
|
|
369 |
sub status_parts { |
sub status_parts { |
370 |
warn "## status parts ", dump( map { keys %$_ } @status ); |
warn "## status parts ", dump( map { keys %$_ } @status ); |
371 |
} |
} |
372 |
|
|
373 |
|
=for debug |
374 |
|
|
375 |
sub DEMOLISH { |
sub DEMOLISH { |
376 |
my ( $self ) = @_; |
my ( $self ) = @_; |
377 |
warn "## $self DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status; |
warn "## $self DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status; |
378 |
} |
} |
379 |
|
|
380 |
|
=cut |
381 |
|
|
382 |
=head2 add_icon |
=head2 add_icon |
383 |
|
|
384 |
Frey::Foo->add_icon; # /static/icons/Frey/Foo.png |
Frey::Foo->add_icon; # /static/icons/Frey/Foo.png |
393 |
$icon .= "/$variant" if $variant; |
$icon .= "/$variant" if $variant; |
394 |
my $path = 'static/icons/' . $icon . '.png'; |
my $path = 'static/icons/' . $icon . '.png'; |
395 |
if ( -e $path ) { |
if ( -e $path ) { |
396 |
warn "# $class from $self icon_path $path"; |
warn "# $class from $self icon_path $path" if $self->debug; |
397 |
return $path; |
return $path; |
398 |
} else { |
} else { |
399 |
warn "TODO: add $path icon for $class"; |
$self->TODO( "add $path icon for $class" ); |
400 |
return undef; |
return undef; |
401 |
} |
} |
402 |
} |
} |
523 |
) = caller($_) or last; |
) = caller($_) or last; |
524 |
|
|
525 |
push @backtrace, |
push @backtrace, |
526 |
qq|via $package from $path <a target="editor" href="/editor+$path+$line">$path</a>|; |
qq|via package $package at $path line $line|; |
527 |
} |
} |
528 |
warn "# backtrace: ", dump( @backtrace ) if @backtrace; |
warn "# backtrace: ", dump( @backtrace ) if @backtrace; |
529 |
return @backtrace; |
return @backtrace; |