3 |
|
|
4 |
with 'Frey::Session'; |
with 'Frey::Session'; |
5 |
|
|
|
#use Continuity::Widget::DomNode; |
|
6 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
7 |
use Carp qw/confess cluck carp/; |
use Carp qw/confess cluck carp/; |
8 |
use File::Slurp; |
use File::Slurp; |
9 |
use Text::Tabs; # expand, unexpand |
use Text::Tabs; # expand, unexpand |
10 |
|
use Digest::MD5 qw/md5/; |
11 |
|
|
12 |
use lib 'lib'; |
use lib 'lib'; |
13 |
|
|
71 |
default => 250, |
default => 250, |
72 |
); |
); |
73 |
|
|
74 |
|
has 'wrap_in_page' => ( |
75 |
|
documentation => 'wrap full html page with status bar around content', |
76 |
|
is => 'rw', |
77 |
|
isa => 'Bool', |
78 |
|
default => 1, |
79 |
|
); |
80 |
|
|
81 |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
82 |
my $escape_re = join '|' => keys %escape; |
my $escape_re = join '|' => keys %escape; |
83 |
|
|
84 |
sub html_escape { |
sub html_escape { |
85 |
my ( $self, $html ) = @_; |
my ( $self, $html ) = @_; |
86 |
|
return '' unless defined $html; |
87 |
$html =~ s/($escape_re)/$escape{$1}/g; |
$html =~ s/($escape_re)/$escape{$1}/g; |
88 |
return $html; |
return $html; |
89 |
} |
} |
197 |
sub _add_css_js { |
sub _add_css_js { |
198 |
my ( $self, $what, $content ) = @_; |
my ( $self, $what, $content ) = @_; |
199 |
|
|
200 |
|
my $md5 = md5( $content ); |
201 |
|
return if $self->{_add_css_js_seen}->{$what}->{$md5}++; |
202 |
|
|
203 |
my $tag = $what eq 'css' ? 'style' : 'script'; |
my $tag = $what eq 'css' ? 'style' : 'script'; |
204 |
my $type = $what eq 'css' ? 'text/css' : 'text/javascript'; |
my $type = $what eq 'css' ? 'text/css' : 'text/javascript'; |
205 |
my $head; |
my $head; |
207 |
my ( $package, $path, $line ) = caller(1); |
my ( $package, $path, $line ) = caller(1); |
208 |
|
|
209 |
$content = "/$content" if $content !~ m{[\n\r]} && -e $content; |
$content = "/$content" if $content !~ m{[\n\r]} && -e $content; |
210 |
if ( $content =~ $re_html ) { |
if ( $content =~ $re_html && $what ne 'js' ) { |
211 |
$head = qq| |
$head = qq| |
212 |
$content |
$content |
213 |
<!-- $type via $package at $path line $line --> |
<!-- $type via $package at $path line $line --> |
249 |
our $reload_counter = 0; |
our $reload_counter = 0; |
250 |
|
|
251 |
|
|
252 |
=head2 page |
=head2 html_page |
253 |
|
|
254 |
$self->page( |
$self->html_page( |
255 |
title => 'page title', |
title => 'page title', |
256 |
head => '<!-- optional head markup -->', |
head => '<!-- optional head markup -->', |
257 |
body => '<b>Page Body</b>', |
body => '<b>Page Body</b>', |
264 |
|
|
265 |
our $icon_html; |
our $icon_html; |
266 |
|
|
267 |
sub page { |
sub html_page { |
268 |
my $self = shift; |
my $self = shift; |
269 |
my $a = {@_}; |
my $a = {@_}; |
270 |
|
|
287 |
warn "# no body, invoke $self->$run on ", ref($self); |
warn "# no body, invoke $self->$run on ", ref($self); |
288 |
$body = $self->$run; |
$body = $self->$run; |
289 |
} |
} |
290 |
if ( $self->content_type !~ m{html} ) { |
if ( $self->content_type !~ m{html} || ! $self->wrap_in_page ) { |
291 |
warn "# return only $self body ", $self->content_type; |
warn "# return only $self body ", $self->content_type; |
292 |
return $body |
return $body |
293 |
} elsif ( ! defined $body ) { |
} elsif ( ! defined $body ) { |
303 |
|
|
304 |
my $right = |
my $right = |
305 |
qq| |
qq| |
306 |
<span class="right"> |
<span class="frey-status-right"> |
307 |
<a title="reload $url" href="/reload$url">reload</a> |
<a title="reload $url" href="/reload$url">reload</a> |
308 |
<a title="$description" href="/exit$url" target="exit">$exit</a> |
<a title="$description" href="/exit$url" target="exit">$exit</a> |
309 |
</span> |
</span> |
324 |
|
|
325 |
# $title =~ s{(\w)\w+::}{$1:}g; # XXX compress names of classes |
# $title =~ s{(\w)\w+::}{$1:}g; # XXX compress names of classes |
326 |
|
|
327 |
|
$self->add_css(qq| |
328 |
|
body { |
329 |
|
padding-bottom: 3em; /* don't overlap status line */ |
330 |
|
} |
331 |
|
|); |
332 |
|
|
333 |
my $html = join("\n", |
my $html = join("\n", |
334 |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
335 |
$self->_head_html, |
$self->_head_html, |