/[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 156 by dpavlin, Thu Jul 17 17:55:39 2008 UTC revision 161 by dpavlin, Thu Jul 17 19:33:51 2008 UTC
# Line 4  use Moose::Role; Line 4  use Moose::Role;
4  use Continuity::Widget::DomNode;  use Continuity::Widget::DomNode;
5  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
6  use Carp qw/confess/;  use Carp qw/confess/;
7    use File::Slurp;
8    
9  has 'head' => (  has 'head' => (
10          is => 'rw',          is => 'rw',
11          isa => 'ArrayRef[Str]',          isa => 'ArrayRef[Str]',
12          default => sub { [] },          default => sub { [ 'static/frey.css' ] },
13    );
14    
15    has 'inline_smaller_than' => (
16            is => 'rw',
17            isa => 'Int',
18            default => 10240,
19  );  );
20    
21  sub dom2html {  sub dom2html {
# Line 16  sub dom2html { Line 23  sub dom2html {
23          return Continuity::Widget::DomNode->create( @_ )->to_string;          return Continuity::Widget::DomNode->create( @_ )->to_string;
24  }  }
25    
26    sub _inline_path {
27            my ( $self, $path ) = @_;
28            -s $path < $self->inline_smaller_than;
29    }
30    
31  sub _head_html {  sub _head_html {
32          my $self = shift;          my $self = shift;
33          my $out = '';          my $out = '';
34          foreach my $path ( @{ $self->head } ) {          foreach my $path ( @{ $self->head } ) {
35                  $path =~ s!^/!!;                  $path =~ s!^/!!;
36                  if ( $path =~ m/\.js$/ ) {                  if ( $path =~ m/\.js$/ ) {
37                          $out .= qq|<script type="text/javascript" src="/$path"></script>|;                          $out .= $self->_inline_path( $path ) ?
38                                    qq|<script type="text/javascript">| . read_file($path) . qq|</script>| :
39                                    qq|<script type="text/javascript" src="/$path"></script>|;
40                  } elsif ( $path =~ m/\.css$/ ) {                  } elsif ( $path =~ m/\.css$/ ) {
41                          $out .= qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;                          $out .= $self->_inline_path( $path ) ?
42                                    qq|<style type="text/css">| . read_file( $path ) . qq|</style>| :
43                                    qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;
44                  } else {                  } else {
45                          confess "don't know how to render $path";                          confess "don't know how to render $path";
46                  }                  }
# Line 72  sub page { Line 88  sub page {
88          . ( $a->{head} || '' )          . ( $a->{head} || '' )
89          . '</head><body>'          . '</head><body>'
90          . ( $a->{body} || '<!-- no body -->' )          . ( $a->{body} || '<!-- no body -->' )
91  #       . qq|<div class="frey-status-line"> <a href="/">Frey</a> $Frey::VERSION <a href="?reload=$reload_counter">reload</a> </div>|          . qq|<div class="frey-status-line"> <a href="/">Frey</a> $Frey::VERSION <a href="?reload=$reload_counter">reload</a> </div>|
92          . '</body></html>'          . '</body></html>'
93          ;          ;
94    

Legend:
Removed from v.156  
changed lines
  Added in v.161

  ViewVC Help
Powered by ViewVC 1.1.26