--- trunk/lib/Frey/Designer.pm 2008/10/28 18:33:53 195 +++ trunk/lib/Frey/Designer.pm 2008/11/05 22:11:17 319 @@ -12,6 +12,7 @@ extends 'Frey'; with 'Frey::Web'; +with 'Frey::Path'; has 'uri' => ( is => 'rw', @@ -25,18 +26,24 @@ default => 1, ); +has 'resolve_links' => ( + is => 'rw', + isa => 'Bool', + default => 1, +); + #use String::TT qw/strip tt/; #use pQuery; use HTML::Query; use File::Slurp; -use LWP::Simple (); -use File::Path; +use LWP::Simple qw/get/; use Data::Dump qw/dump/; +use HTML::ResolveLink; sub path { my $self = shift; - my $path = 'templates/www.carnet.hr/' . $self->uri->path; + my $path = join('/', ( 'templates', $self->uri->host, $self->uri->path ) ); $path .= '.html' if $path !~ m/\.\w+$/; return $path; } @@ -45,41 +52,37 @@ my ( $self ) = @_; my $path = $self->path; + my $body; if ( ! -e $path && $self->mirror ) { - my $base_path = $path; - $base_path =~ s{/[^/]+$}{}; - mkpath $base_path if ! -e $base_path; + $self->mkbasepath( $path ); my $url = $self->uri; warn ">> mirror $url -> $path\n"; - LWP::Simple::mirror( $url, $path ) or die "can't mirror $url: $!"; + $body = get( $url ) or die "can't mirror $url: $!"; + + if ( $self->resolve_links ) { + my $resolver = HTML::ResolveLink->new( base => $url ); + $body = $resolver->resolve( $body ); + } + + write_file( $path, $body ); warn "WW mirror $url -> $path ", -s $path, " bytes\n"; + + } else { + $body = read_file( $path ); } - my $body = read_file( $path ); warn "# $path ", -s $path, " == ", length($body), "bytes"; return $body; } -sub html { - my ( $self, $req ) = @_; - - my $body; - - if ( $self->uri->path =~ m{/__bookmarklet} ) { - my $js = read_file( 'static/xpath.js' ); - $js =~ s{//.*}{}gm; # remove comments so that compaction below doesn't screw code - $js =~ s/\s\s+/ /gs; - $req->print(qq{ - Drag this bookmarklet to bookmark toolbar or menu to install XPATH inspector - }); - return; - } +sub markup { + my ( $self ) = @_; - $body .= $self->get_page; + my $body = $self->get_page; # strip full hostname my $url = $self->uri; @@ -108,11 +111,10 @@ 'body', ); # warn dump( $dom->as_HTML ); - $body = $dom->as_HTML->[0]; +# $body = $dom->as_HTML->[0]; warn "<< ", $self->uri, " ", -s $self->path, - " ", $req->params ? dump( $req->params ) : '', "\n"; =for later @@ -136,7 +138,7 @@ warn $body; - $req->print( $self->page( title => $self->uri, body => $body ) ); + return $self->page( title => $self->uri, body => $body ); } 1;