/[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

Annotation of /trunk/lib/Frey/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (hide annotations)
Sun Jun 29 13:12:59 2008 UTC (14 years, 7 months ago) by dpavlin
Original Path: trunk/lib/HTML.pm
File size: 1315 byte(s)
require view classes on startup
1 dpavlin 10 package HTML;
2    
3     use strict;
4     use warnings;
5    
6     use Time::HiRes qw/time/;
7     use Data::Dump qw/dump/;
8 dpavlin 14 use Carp qw/confess/;
9 dpavlin 19
10     # FIXME
11 dpavlin 10
12 dpavlin 21 our @view_classes = qw(
13     Frey::View
14     Frey::REST
15     Strix::View
16     );
17    
18     warn "Using view classes ", dump( @view_classes );
19    
20     foreach ( @view_classes ) {
21     my $path = $_;
22     $path =~ s!::!/!g;
23     $path .= '.pm';
24     require $path or warn "Can't require $_ from $path: $!";
25     }
26    
27 dpavlin 10 warn "available templates = ",dump( Template::Declare->templates );
28    
29 dpavlin 14 our @javascript;
30    
31 dpavlin 10 use Template::Declare;
32     use Template::Declare::Tags; # defaults to 'HTML'
33 dpavlin 21 Template::Declare->init( roots => \@view_classes, around_template => sub {
34 dpavlin 10 my ($orig, $path, $args, $code) = @_;
35     my $t = time;
36     html {
37 dpavlin 14 head {
38     title { $path }
39     link {
40     { rel is 'stylesheet' }
41     { href is 'static/app.css' }
42     { type is 'text/css' }
43     { media is 'screen' }
44     };
45     foreach my $js ( @javascript ) {
46     script {
47     { type is 'text/javascript' }
48     { src is $js }
49     }
50     }
51     }
52 dpavlin 10 body {
53     $orig->();
54     }
55     }
56     warn "TEMPLATE $path ",dump($args),sprintf(" in %.4fs\n",time - $t);
57     });
58    
59     sub view {
60     my $self = shift;
61     return Template::Declare->show( @_ );
62     }
63 dpavlin 14
64     sub add_javascript {
65     my $self = shift;
66     my $js = shift or confess "no JavaScript path";
67     # return unless -e $js; # FIXME
68     warn "Added javascript $js\n";
69     push @javascript, $js;
70     }

  ViewVC Help
Powered by ViewVC 1.1.26