--- trunk/lib/Frey/Designer.pm 2008/08/10 16:01:07 164 +++ trunk/lib/Frey/Designer.pm 2008/08/16 23:37:42 175 @@ -1,34 +1,25 @@ package Frey::Designer; use Moose; -use Moose::Util::TypeConstraints; - -use URI (); - -subtype 'Uri' - => as 'Object' - => where { $_->isa('URI') }; - -coerce 'Uri' - => from 'Object' - => via { $_->isa('URI') - ? $_ - : Params::Coerce::coerce( 'URI', $_ ) } - => from 'Str' - => via { URI->new( $_ ) }; +use Frey::Types; +#use MooseX::Types::URI qw(Uri FileUri DataUri); has 'uri' => ( is => 'rw', - isa => 'Uri', - coerce => 1, + isa => 'Uri', coerce => 1, required => 1, ); +has 'mirror' => ( + is => 'rw', + isa => 'Boolean', +); + #use String::TT qw/strip tt/; use pQuery; use File::Slurp; -use LWP::Simple; +use LWP::Simple (); use File::Path; use Data::Dump qw/dump/; @@ -37,16 +28,20 @@ } sub mirror_design { - my ( $url, $path ) = @_; + my ( $self, $c, $path ) = @_; return if -e $path; + return unless $self->mirror; + + my $url = $self->uri . '/' . $c->req->path . '?' . $c->req->uri->query; + my $base_path = $path; $base_path =~ s{/[^/]+$}{}; mkpath $base_path if ! -e $base_path; warn ">> mirror $url -> $path\n"; - mirror( $url, $path ) or die "can't mirror $url: $!"; + LWP::Simple::mirror( $url, $path ) or die "can't mirror $url: $!"; } sub handler { @@ -58,11 +53,23 @@ my $path = template_path( $c->req->path ); + if ( $path =~ m{/__bookmarklet} ) { + $c->res->content_type( "text/html" ); + 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; + $c->res->body(qq{ + drag this look to bookmark xpath? to install XPATH inspector +

link test + }); + return; + } + $path .= '.html' if $path !~ m/\.\w+$/; my $url = $self->uri; - mirror_design( $url . $c->req->path, $path ); + $self->mirror_design( $c, $path ); $body .= read_file( $path ); @@ -83,12 +90,22 @@ my $dom = pQuery( $body ); # warn dump( $dom->find("body") ); $dom->find(".navigation")->each( sub { - warn dump( $_->innerHTML ); + my $html = $_->innerHTML; + warn $html; +# $_->innerHTML(qq{ +#

$html
+# }); } ); +# $body = $dom->toHtml; + } - warn "<< ", $c->req->path, " ", -s $path, " ", $c->res->content_type, "\n"; + warn "<< ", $c->req->path, + " ", -s $path, + " ", $c->res->content_type, + " ", $c->req->params ? dump( $c->req->params ) : '', + "\n"; =for later