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; |
86 |
return "<code>$dump</code>"; |
return "<code>$dump</code>"; |
87 |
} |
} |
88 |
|
|
89 |
sub dom2html { |
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
90 |
# warn "## dom2html ",dump( @_ ); |
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
91 |
return Continuity::Widget::DomNode->create( @_ )->to_string; |
|
92 |
|
our $re_html = qr{<(?:!--.+?--|(\w+).+?/\1)>}s; # relaxed html check for one semi-valid tag |
93 |
|
|
94 |
|
sub popup_dropdown { |
95 |
|
my ( $self, $type, $name, $content, $full ) = @_; |
96 |
|
|
97 |
|
$content = $self->html_dump($content) if ref $content; |
98 |
|
|
99 |
|
$content = qq|<span>$content</span>| unless $content =~ m{^\s*<(span|a|code).+?/\1>\s*}; |
100 |
|
|
101 |
|
warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug; |
102 |
|
|
103 |
|
if ( $name =~ m{::} && $name !~ $re_html ) { |
104 |
|
return qq|<a class="frey-$type" target="$name" href="/$name">$name $content</a>\n|; |
105 |
|
} else { |
106 |
|
return qq|<span class="frey-$type">$name $content</span>\n|; |
107 |
|
} |
108 |
} |
} |
109 |
|
|
110 |
sub _inline_path { |
sub _inline_path { |
150 |
return if ! defined $path || $path eq ''; |
return if ! defined $path || $path eq ''; |
151 |
$path =~ s!^/!!; |
$path =~ s!^/!!; |
152 |
|
|
153 |
if ( $path =~ m{<.*>}s ) { |
if ( $path =~ $re_html ) { |
154 |
push @{ $self->head }, $path; |
push @{ $self->head }, $path; |
155 |
} elsif ( -e $path ) { |
} elsif ( -e $path ) { |
156 |
if ( $path =~ m/\.(?:js|css)$/ ) { |
if ( $path =~ m/\.(?:js|css)$/ ) { |
183 |
|
|
184 |
our $icon_html; |
our $icon_html; |
185 |
|
|
|
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
|
|
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
|
|
|
|
|
sub popup_dropdown { |
|
|
my ( $self, $type, $name, $content, $full ) = @_; |
|
|
|
|
|
if ( ref($content) ) { |
|
|
$content = $self->html_dump($content); |
|
|
# my $l = length($content); |
|
|
# $content = qq|<span>$l bytes</span>| if ! $full && $l > $self->dump_max_bytes; |
|
|
} else { |
|
|
$content = qq|<span>$content</span>|; |
|
|
} |
|
|
|
|
|
warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug; |
|
|
|
|
|
if ( $name =~ m{::} && ! $name =~ m{<(\w+).+?/\1>} ) { |
|
|
return qq|<a class="frey-$type" target="$name" href="/$name">$name $content</a>\n|; |
|
|
} else { |
|
|
return qq|<span class="frey-$type">$name $content</span>\n|; |
|
|
} |
|
|
} |
|
|
|
|
186 |
sub page { |
sub page { |
187 |
my $self = shift; |
my $self = shift; |
188 |
my $a = {@_}; |
my $a = {@_}; |
352 |
warn "# $class from $self icon_path $path"; |
warn "# $class from $self icon_path $path"; |
353 |
return $path; |
return $path; |
354 |
} else { |
} else { |
355 |
warn "TODO: add $path icon for $class"; |
$self->TODO( "add $path icon for $class" ); |
356 |
return undef; |
return undef; |
357 |
} |
} |
358 |
} |
} |