/[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 23 - (hide annotations)
Sun Jun 29 16:24:41 2008 UTC (14 years, 7 months ago) by dpavlin
File size: 1662 byte(s)
another major refactor and version bump [0.01]

- return 404 errors for resources which doesn't exist
- move HTML page wrapper is now in Fray::HTML->page
- dispatch to defined Template::Declare templates
- display available templates on status screen
- NOTE very clean and unobfuscated mapping
- a bits of documentation all over the place
1 dpavlin 23 package Frey::HTML;
2 dpavlin 10
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 dpavlin 23 =head1 NAME
11    
12     Frey::HTML - generate html pages
13    
14     =head2 METHODS
15    
16     =cut
17    
18 dpavlin 19 # FIXME
19 dpavlin 10
20 dpavlin 21 our @view_classes = qw(
21     Frey::View
22     Frey::REST
23     Strix::View
24     );
25    
26     warn "Using view classes ", dump( @view_classes );
27    
28     foreach ( @view_classes ) {
29     my $path = $_;
30     $path =~ s!::!/!g;
31     $path .= '.pm';
32     require $path or warn "Can't require $_ from $path: $!";
33     }
34    
35 dpavlin 10 warn "available templates = ",dump( Template::Declare->templates );
36    
37 dpavlin 14 our @javascript;
38 dpavlin 23 our $debug = 0;
39 dpavlin 14
40 dpavlin 10 use Template::Declare;
41     use Template::Declare::Tags; # defaults to 'HTML'
42 dpavlin 21 Template::Declare->init( roots => \@view_classes, around_template => sub {
43 dpavlin 10 my ($orig, $path, $args, $code) = @_;
44     my $t = time;
45     html {
46 dpavlin 14 head {
47     title { $path }
48     link {
49     { rel is 'stylesheet' }
50     { href is 'static/app.css' }
51     { type is 'text/css' }
52     { media is 'screen' }
53     };
54     foreach my $js ( @javascript ) {
55     script {
56     { type is 'text/javascript' }
57     { src is $js }
58     }
59     }
60     }
61 dpavlin 10 body {
62     $orig->();
63     }
64 dpavlin 23 };
65     warn "TEMPLATE $path ",dump($args),sprintf(" in %.4fs\n",time - $t) if $debug;
66 dpavlin 10 });
67    
68 dpavlin 23 =head2 page
69    
70     Wrap template into html page
71    
72     Frey::HTML->page( 'template_name', $req, $args );
73    
74     =cut
75    
76     sub page {
77 dpavlin 10 my $self = shift;
78 dpavlin 23 warn "## page $_[0]\n";
79 dpavlin 10 return Template::Declare->show( @_ );
80     }
81 dpavlin 14
82 dpavlin 23 =head2 add_javascript
83    
84     Add javascript to current page
85    
86     Frey::HTML->add_javascript( 'static/javascript.js' );
87    
88     =cut
89    
90 dpavlin 14 sub add_javascript {
91     my $self = shift;
92     my $js = shift or confess "no JavaScript path";
93     # return unless -e $js; # FIXME
94     warn "Added javascript $js\n";
95     push @javascript, $js;
96     }

  ViewVC Help
Powered by ViewVC 1.1.26