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

Annotation of /trunk/lib/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (hide annotations)
Sun Jun 29 00:36:08 2008 UTC (15 years, 9 months ago) by dpavlin
File size: 1058 byte(s)
- HTML->add_javascript to include javascript in page
- put debug class around debug output
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 10 use View;
10    
11     warn "available templates = ",dump( Template::Declare->templates );
12    
13 dpavlin 14 our @javascript;
14    
15 dpavlin 10 use Template::Declare;
16     use Template::Declare::Tags; # defaults to 'HTML'
17     Template::Declare->init( roots => ['HTML','View'], around_template => sub {
18     my ($orig, $path, $args, $code) = @_;
19     my $t = time;
20     html {
21 dpavlin 14 head {
22     title { $path }
23     link {
24     { rel is 'stylesheet' }
25     { href is 'static/app.css' }
26     { type is 'text/css' }
27     { media is 'screen' }
28     };
29     foreach my $js ( @javascript ) {
30     script {
31     { type is 'text/javascript' }
32     { src is $js }
33     }
34     }
35     }
36 dpavlin 10 body {
37     $orig->();
38     }
39     }
40     warn "TEMPLATE $path ",dump($args),sprintf(" in %.4fs\n",time - $t);
41     });
42    
43     sub view {
44     my $self = shift;
45     return Template::Declare->show( @_ );
46     }
47 dpavlin 14
48     sub add_javascript {
49     my $self = shift;
50     my $js = shift or confess "no JavaScript path";
51     # return unless -e $js; # FIXME
52     warn "Added javascript $js\n";
53     push @javascript, $js;
54     }

  ViewVC Help
Powered by ViewVC 1.1.26