/[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 27 - (show annotations)
Sun Jun 29 20:11:27 2008 UTC (15 years, 9 months ago) by dpavlin
File size: 1872 byte(s)
dump better output on page
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 carp/;
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 ",dump($_[0],ref($_[1]),$_[2]),"\n";
79 my $page = eval { Template::Declare->show( @_ ) };
80 if ( $@ ) {
81 carp "ERROR: $@";
82 $page = Template::Declare->show( 'error', $_[1], "page" . dump($_[0], ref($_[1])) . "\n$@" );
83 warn $page;
84 }
85 return $page;
86 }
87
88 =head2 add_javascript
89
90 Add javascript to current page
91
92 Frey::HTML->add_javascript( 'static/javascript.js' );
93
94 =cut
95
96 sub add_javascript {
97 my $self = shift;
98 my $js = shift or confess "no JavaScript path";
99 # return unless -e $js; # FIXME
100 warn "Added javascript $js\n";
101 push @javascript, $js;
102 }

  ViewVC Help
Powered by ViewVC 1.1.26