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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations)
Sun Jun 29 16:24:41 2008 UTC (14 years, 5 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 package Frey::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 =head1 NAME
11
12 Frey::HTML - generate html pages
13
14 =head2 METHODS
15
16 =cut
17
18 # FIXME
19
20 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 warn "available templates = ",dump( Template::Declare->templates );
36
37 our @javascript;
38 our $debug = 0;
39
40 use Template::Declare;
41 use Template::Declare::Tags; # defaults to 'HTML'
42 Template::Declare->init( roots => \@view_classes, around_template => sub {
43 my ($orig, $path, $args, $code) = @_;
44 my $t = time;
45 html {
46 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 body {
62 $orig->();
63 }
64 };
65 warn "TEMPLATE $path ",dump($args),sprintf(" in %.4fs\n",time - $t) if $debug;
66 });
67
68 =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 my $self = shift;
78 warn "## page $_[0]\n";
79 return Template::Declare->show( @_ );
80 }
81
82 =head2 add_javascript
83
84 Add javascript to current page
85
86 Frey::HTML->add_javascript( 'static/javascript.js' );
87
88 =cut
89
90 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