/[Frey]/trunk/lib/Frey/HTML/Designer.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/HTML/Designer.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1133 - (show annotations)
Tue Jun 30 15:10:55 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 2598 byte(s)
make classes immutable and remove moose droppings to make Perl::Critic::Moose happy
1 package Frey::HTML::Designer;
2 use Moose;
3
4 =head1 NAME
5
6 Frey::HTML::Designer - modify html (sometime in future)
7
8 =cut
9
10 use Frey::Types;
11 #use MooseX::Types::URI qw(Uri FileUri DataUri);
12
13 extends 'Frey';
14 with 'Frey::Web', 'Frey::Path';
15
16 has 'uri' => (
17 is => 'rw',
18 isa => 'Uri', coerce => 1,
19 required => 1,
20 );
21
22 has 'mirror' => (
23 is => 'rw',
24 isa => 'Bool',
25 default => 1,
26 );
27
28 has 'resolve_links' => (
29 is => 'rw',
30 isa => 'Bool',
31 default => 1,
32 );
33
34 #use String::TT qw/strip tt/;
35
36 #use pQuery;
37 use HTML::Query;
38 use File::Slurp;
39 use LWP::Simple qw/get/;
40 use Data::Dump qw/dump/;
41 use HTML::ResolveLink;
42
43 sub path {
44 my $self = shift;
45 my $path = join('/', ( 'templates', $self->uri->host, $self->uri->path ) );
46 $path .= '.html' if $path !~ m/\.\w+$/;
47 return $path;
48 }
49
50 sub get_page {
51 my ( $self ) = @_;
52
53 my $path = $self->path;
54 my $body;
55
56 if ( ! -e $path && $self->mirror ) {
57
58 $self->mkbasepath( $path );
59
60 my $url = $self->uri;
61 warn ">> mirror $url -> $path\n";
62
63 $body = get( $url ) or die "can't mirror $url: $!";
64
65 if ( $self->resolve_links ) {
66 my $resolver = HTML::ResolveLink->new( base => $url );
67 $body = $resolver->resolve( $body );
68 }
69
70 write_file( $path, $body );
71 warn "WW mirror $url -> $path ", -s $path, " bytes\n";
72
73 } else {
74 $body = read_file( $path );
75 }
76
77 warn "# $path ", -s $path, " == ", length($body), "bytes";
78 return $body;
79 }
80
81 sub as_markup {
82 my ( $self ) = @_;
83
84 my $body = $self->get_page;
85
86 # strip full hostname
87 my $url = $self->uri;
88 $body =~ s{\Q$url\E}{/}gs;
89 # remove cookie variable from url
90 $body =~ s{CARNetweb=[0-9a-f]+}{}gs;
91
92 =for pQuery
93
94 my $dom = pQuery( $body );
95 # warn dump( $dom->find("body") );
96 $dom->find(".navigation")->each( sub {
97 my $html = $_->innerHTML;
98 warn $html;
99 # $_->innerHTML(qq{
100 # <div style="border: 3px dashed black;">$html</div>
101 # });
102 } );
103
104 # $body = $dom->toHtml;
105
106 =cut
107
108 my $dom = HTML::Query->new(
109 text => $body,
110 'body',
111 );
112 # warn dump( $dom->as_HTML );
113 # $body = $dom->as_HTML->[0];
114
115 warn "<< ", $self->uri,
116 " ", -s $self->path,
117 "\n";
118
119 =for later
120
121 $body .= strip tt q{
122 <form method="post">
123 <input type="text" name="id" />
124 <input type="submit" />
125 </form>
126
127 <form method="post" enctype="multipart/form-data">
128 <input type="file" name="upload_file" />
129 <input type="submit" />
130 </form>
131
132 <pre>[% raw | html %]</pre>
133 <pre>[% req_dump | html %]</pre>
134 };
135
136 =cut
137
138 warn $body;
139
140 return $self->html_page( title => $self->uri, body => $body );
141 }
142
143 __PACKAGE__->meta->make_immutable;
144 no Moose;
145
146 1;

  ViewVC Help
Powered by ViewVC 1.1.26