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

Contents of /trunk/lib/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (show annotations)
Sun Jun 29 13:12:59 2008 UTC (15 years, 9 months ago) by dpavlin
File size: 1315 byte(s)
require view classes on startup
1 package HTML;
2
3 use strict;
4 use warnings;
5
6 use Time::HiRes qw/time/;
7 use Data::Dump qw/dump/;
8 use Carp qw/confess/;
9
10 # FIXME
11
12 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 warn "available templates = ",dump( Template::Declare->templates );
28
29 our @javascript;
30
31 use Template::Declare;
32 use Template::Declare::Tags; # defaults to 'HTML'
33 Template::Declare->init( roots => \@view_classes, around_template => sub {
34 my ($orig, $path, $args, $code) = @_;
35 my $t = time;
36 html {
37 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 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
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