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

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

revision 27 by dpavlin, Sun Jun 29 20:11:27 2008 UTC revision 42 by dpavlin, Mon Jun 30 20:02:16 2008 UTC
# Line 7  use Time::HiRes qw/time/; Line 7  use Time::HiRes qw/time/;
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8  use Carp qw/confess carp/;  use Carp qw/confess carp/;
9    
10    #use Template::Declare;
11    use base qw/Template::Declare/;
12    use Template::Declare::Tags; # defaults to 'HTML'
13    
14  =head1 NAME  =head1 NAME
15    
16  Frey::HTML - generate html pages  Frey::HTML - generate html pages
# Line 19  Frey::HTML - generate html pages Line 23  Frey::HTML - generate html pages
23    
24  our @view_classes = qw(  our @view_classes = qw(
25          Frey::View          Frey::View
         Frey::REST  
26          Strix::View          Strix::View
27  );  );
28    
# Line 30  foreach ( @view_classes ) { Line 33  foreach ( @view_classes ) {
33          $path =~ s!::!/!g;          $path =~ s!::!/!g;
34          $path .= '.pm';          $path .= '.pm';
35          require $path or warn "Can't require $_ from $path: $!";          require $path or warn "Can't require $_ from $path: $!";
36            # this will import templates as fully qualified paths
37            import_templates $_ under "/$_/";
38  }  }
39    
40  warn "available templates = ",dump( Template::Declare->templates );  warn "available templates = ",dump( Template::Declare->templates );
# Line 37  warn "available templates = ",dump( Temp Line 42  warn "available templates = ",dump( Temp
42  our @javascript;  our @javascript;
43  our $debug = 0;  our $debug = 0;
44    
45  use Template::Declare;  Template::Declare->init( roots => \@view_classes );
46  use Template::Declare::Tags; # defaults to 'HTML'  sub page_template {
47  Template::Declare->init( roots => \@view_classes, around_template => sub {          my ( $body ) = @_;
48          my ($orig, $path, $args, $code) = @_;          my $title = (caller(0))[3];
49    
50          my $t = time;          my $t = time;
51          html {          html {
52                  head {                  head {
53                          title { $path }                          title { $title }
54                          link {                          link {
55                                  { rel is 'stylesheet' }                                  { rel is 'stylesheet' }
56                                  { href is '/static/app.css' }                                  { href is '/static/app.css' }
# Line 56  Template::Declare->init( roots => \@view Line 62  Template::Declare->init( roots => \@view
62                                          { type is 'text/javascript' }                                          { type is 'text/javascript' }
63                                          { src is "/$js" }                                          { src is "/$js" }
64                                  }                                  }
65                          }                          };
                 }  
                 body {  
                         $orig->();  
66                  }                  }
67                    body { outs_raw $body }
68          };          };
69          warn "TEMPLATE $path ",dump($args),sprintf(" in %.4fs\n",time - $t) if $debug;  };
 });  
70    
71  =head2 page  =head2 page
72    
# Line 74  Wrap template into html page Line 77  Wrap template into html page
77  =cut  =cut
78    
79  sub page {  sub page {
80          my $self = shift;          my ( $self, $page, $req, $args ) = @_;
81          warn "## page ",dump($_[0],ref($_[1]),$_[2]),"\n";          warn "## buffer_stack ",dump( Template::Declare->buffer_stack );
82          my $page = eval { Template::Declare->show( @_ ) };          Template::Declare->buffer->clear; # XXX we need to manually do this!
83            my $out = eval { Template::Declare->show( $page, $req, $args ) };
84          if ( $@ ) {          if ( $@ ) {
85                  carp "ERROR: $@";                  carp "ERROR: $@";
86                  $page = Template::Declare->show( 'error', $_[1], "page" . dump($_[0], ref($_[1])) . "\n$@" );                  $out = Template::Declare->show( 'error', $req, "page $page " . dump($args) . ": $@" );
                 warn $page;  
87          }          }
88          return $page;          warn "## page $page ",dump($args)," ",length($out)," bytes\n";
89            return scalar page_template($out);
90  }  }
91    
92  =head2 add_javascript  =head2 add_javascript
# Line 100  sub add_javascript { Line 104  sub add_javascript {
104          warn "Added javascript $js\n";          warn "Added javascript $js\n";
105          push @javascript, $js;          push @javascript, $js;
106  }  }
107    
108    1;

Legend:
Removed from v.27  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26