7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
use Carp qw/confess carp/; |
use Carp qw/confess carp/; |
9 |
|
|
10 |
|
#use Template::Declare; |
11 |
|
use base qw/Template::Declare/; |
12 |
|
use Template::Declare::Tags; # defaults to 'HTML' |
13 |
|
|
14 |
=head1 NAME |
=head1 NAME |
15 |
|
|
16 |
Frey::HTML - generate html pages |
Frey::HTML - generate html pages |
23 |
|
|
24 |
our @view_classes = qw( |
our @view_classes = qw( |
25 |
Frey::View |
Frey::View |
|
Frey::REST |
|
26 |
Strix::View |
Strix::View |
27 |
); |
); |
28 |
|
|
33 |
$path =~ s!::!/!g; |
$path =~ s!::!/!g; |
34 |
$path .= '.pm'; |
$path .= '.pm'; |
35 |
require $path or warn "Can't require $_ from $path: $!"; |
require $path or warn "Can't require $_ from $path: $!"; |
36 |
|
# this will import templates as fully qualified paths |
37 |
|
import_templates $_ under "/$_/"; |
38 |
} |
} |
39 |
|
|
40 |
warn "available templates = ",dump( Template::Declare->templates ); |
warn "available templates = ",dump( Template::Declare->templates ); |
42 |
our @javascript; |
our @javascript; |
43 |
our $debug = 0; |
our $debug = 0; |
44 |
|
|
|
use Template::Declare; |
|
|
use Template::Declare::Tags; # defaults to 'HTML' |
|
45 |
Template::Declare->init( roots => \@view_classes, around_template => sub { |
Template::Declare->init( roots => \@view_classes, around_template => sub { |
46 |
my ($orig, $path, $args, $code) = @_; |
my ($orig, $path, $args, $code) = @_; |
47 |
|
my $from = (caller(1))[3]; |
48 |
|
my $package = __PACKAGE__; |
49 |
|
if ( $from !~ m/$package/ ) { |
50 |
|
warn "SKIP around_template for $path from $from\n"; |
51 |
|
return $orig->(); |
52 |
|
} else { |
53 |
|
warn "WRAP around_temolate for $path from $from\n"; |
54 |
|
} |
55 |
|
|
56 |
my $t = time; |
my $t = time; |
57 |
html { |
html { |
58 |
head { |
head { |
68 |
{ type is 'text/javascript' } |
{ type is 'text/javascript' } |
69 |
{ src is "/$js" } |
{ src is "/$js" } |
70 |
} |
} |
71 |
} |
}; |
72 |
} |
} |
73 |
body { |
body { |
74 |
$orig->(); |
$orig->(); |
86 |
=cut |
=cut |
87 |
|
|
88 |
sub page { |
sub page { |
89 |
my $self = shift; |
my ( $self, $page, $req, $args ) = @_; |
90 |
warn "## page $_[0]\n"; |
warn "## buffer_stack ",dump( Template::Declare->buffer_stack ); |
91 |
my $page = eval { Template::Declare->show( @_ ) }; |
Template::Declare->buffer->clear; # XXX we need to manually do this! |
92 |
|
warn "## page $page ",dump($args),"\n"; |
93 |
|
my $out = eval { Template::Declare->show( $page, $req, $args ) }; |
94 |
if ( $@ ) { |
if ( $@ ) { |
95 |
carp "ERROR: $@"; |
carp "ERROR: $@"; |
96 |
$page = Template::Declare->show( 'error', $@ ); |
$out = Template::Declare->show( 'error', $req, "page $page " . dump($args) . ": $@" ); |
97 |
} |
} |
98 |
return $page; |
return $out; |
99 |
} |
} |
100 |
|
|
101 |
=head2 add_javascript |
=head2 add_javascript |
113 |
warn "Added javascript $js\n"; |
warn "Added javascript $js\n"; |
114 |
push @javascript, $js; |
push @javascript, $js; |
115 |
} |
} |
116 |
|
|
117 |
|
1; |