/[Frey]/trunk/lib/Frey/Web.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

Diff of /trunk/lib/Frey/Web.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 444 by dpavlin, Wed Nov 19 02:52:42 2008 UTC revision 457 by dpavlin, Wed Nov 19 16:53:13 2008 UTC
# Line 1  Line 1 
1  package Frey::Web;  package Frey::Web;
2  use Moose::Role;  use Moose::Role;
3    
 #with 'Frey::Escape';  
   
4  use Frey::Types;  use Frey::Types;
5    
6  use Continuity::Widget::DomNode;  use Continuity::Widget::DomNode;
# Line 24  has 'status' => ( Line 22  has 'status' => (
22          isa => 'ArrayRef[HashRef[Str]]',          isa => 'ArrayRef[HashRef[Str]]',
23          lazy => 1,          lazy => 1,
24          default => sub { [          default => sub { [
25                  { 'Bookmarklets' => Frey::Bookmarklet->new->markup },                  { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup },
26                  { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->markup },                  { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup },
27          ] },          ] },
28  );  );
29    
# Line 45  has 'title' => ( Line 43  has 'title' => (
43          },          },
44  );  );
45    
46    has 'content_type' => (
47            is => 'rw',
48            isa => 'Str',
49            default => 'text/html',
50    );
51    
52  =head2 inline_smaller_than  =head2 inline_smaller_than
53    
54  Inline JavaScript and CSS smaller than this size into page reducing  Inline JavaScript and CSS smaller than this size into page reducing
# Line 81  sub _head_html { Line 85  sub _head_html {
85                          $out .= $self->_inline_path( $path ) ?                          $out .= $self->_inline_path( $path ) ?
86                                  qq|<!-- $path --><style type="text/css">\n| . read_file( $path ) . qq|\n</style>| :                                  qq|<!-- $path --><style type="text/css">\n| . read_file( $path ) . qq|\n</style>| :
87                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;
88                  } elsif ( $path =~ m{<.+>} ) {                  } elsif ( $path =~ m{<.+>}s ) {
89                          $out .= $path;                          $out .= $path;
90                  } else {                  } else {
91                          confess "don't know how to render $path";                          confess "don't know how to render $path";
# Line 97  sub _head_html { Line 101  sub _head_html {
101    
102    my $size = $o->add_head( 'path/to/external.css' );    my $size = $o->add_head( 'path/to/external.css' );
103    
104      $o->add_head( '<!-- html content -->' );
105    
106  =cut  =cut
107    
108  sub add_head {  sub add_head {
# Line 104  sub add_head { Line 110  sub add_head {
110          return if ! defined $path || $path eq '';          return if ! defined $path || $path eq '';
111          $path =~ s!^/!!;          $path =~ s!^/!!;
112    
113          if ( $path =~ m{<.*>} ) {          if ( $path =~ m{<.*>}s ) {
114                  push @{ $self->head }, $path;                  push @{ $self->head }, $path;
115          } elsif ( -e $path ) {          } elsif ( -e $path ) {
116                  if ( $path =~ m/\.(?:js|css)$/ ) {                  if ( $path =~ m/\.(?:js|css)$/ ) {
# Line 162  sub page { Line 168  sub page {
168          my $url = $self->request_url;          my $url = $self->request_url;
169          $url =~ s{\?reload=\d+}{};          $url =~ s{\?reload=\d+}{};
170    
171            my $body = $a->{body} || $self->as_markup;
172            return $body if $self->content_type !~ m{html};
173            $body ||= '<!-- no body -->';
174    
175          my $html = join("\n",          my $html = join("\n",
176                  qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,                  qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,
177                  $self->_head_html,                  $self->_head_html,
178                  '<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>',                  '<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>',
179                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',
180                  ( $a->{head} || '' ),                  ( $a->{head} || '' ),
                 '</head><body>',  
                 ( $a->{body} || $self->markup || '<!-- no body -->' ),  
181                  qq|                  qq|
182                    </head><body>
183                    $body
184                  <div class="frey-status-line">                  <div class="frey-status-line">
185                          <a href="/">Frey</a> $Frey::VERSION                          <a href="/">Frey</a> $Frey::VERSION
186                          <a href="?reload=$reload_counter"><code>$url</code></a>                          <a href="?reload=$reload_counter"><code>$url</code></a>

Legend:
Removed from v.444  
changed lines
  Added in v.457

  ViewVC Help
Powered by ViewVC 1.1.26