/[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 100 by dpavlin, Fri Jul 11 19:19:42 2008 UTC revision 157 by dpavlin, Thu Jul 17 18:00:28 2008 UTC
# Line 3  use Moose::Role; Line 3  use Moose::Role;
3    
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/;
7    
8    has 'head' => (
9            is => 'rw',
10            isa => 'ArrayRef[Str]',
11            default => sub { [] },
12    );
13    
14  sub dom2html {  sub dom2html {
15          warn "## dom2html ",dump( @_ );  #       warn "## dom2html ",dump( @_ );
16          return Continuity::Widget::DomNode->create( @_ )->to_string;          return Continuity::Widget::DomNode->create( @_ )->to_string;
17  }  }
18    
19  our @javascript = ( qw'  sub _head_html {
20  ../lib/Joose.js          my $self = shift;
21  ');          my $out = '';
22            foreach my $path ( @{ $self->head } ) {
23                    $path =~ s!^/!!;
24                    if ( $path =~ m/\.js$/ ) {
25                            $out .= qq|<script type="text/javascript" src="/$path"></script>|;
26                    } elsif ( $path =~ m/\.css$/ ) {
27                            $out .= qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;
28                    } else {
29                            confess "don't know how to render $path";
30                    }
31            }
32            return $out;
33    }
34    
35    =head2 add_head
36    
37      $o->add_head( 'path/to/external.js' );
38    
39      my $size = $o->add_head( 'path/to/external.css' );
40    
41    =cut
42    
43    sub add_head {
44            my ( $self, $path ) = @_;
45            return if ! defined $path || $path eq '';
46            $path =~ s!^/!!;
47    
48            if ( -e $path ) {
49                    if ( $path =~ m/\.(?:js|css)$/ ) {
50                            push @{ $self->head }, $path;
51                    } else {
52                            confess "can't add_head( $path ) it's not js or css";
53                    }
54            } else {
55                    confess "can't find $path: $!";
56            }
57    
58            return -s $path;
59    }
60    
61    our $reload_counter = 0;
62    
63  sub head_javascript {  sub page {
64          my $self = shift;          my $self = shift;
65            my $a = {@_};
66    
67            $reload_counter++;
68    
69          my $js = Continuity::Widget::DomNode->create(          my $html = qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|
70                  map {          . $self->_head_html
71                          ( script => { type => 'text/javascript', src => $_ } )          . '<title>' . ( $a->{title} || ref($self) ) . '</title>'
72                  } @javascript          . ( $a->{head} || '' )
73          )->to_string;          . '</head><body>'
74            . ( $a->{body} || '<!-- no body -->' )
75            . qq|<div class="frey-status-line"> <a href="/">Frey</a> $Frey::VERSION <a href="?reload=$reload_counter">reload</a> </div>|
76            . '</body></html>'
77            ;
78    
79          warn "# >>> js\n$js\n" if $self->debug;          warn "## >>> page ",length($html), " bytes\n" if $self->debug;
80    
81          return $js;          return $html;
82  }  }
83    
84  1;  1;

Legend:
Removed from v.100  
changed lines
  Added in v.157

  ViewVC Help
Powered by ViewVC 1.1.26