--- trunk/lib/HTML.pm 2008/06/28 22:13:05 10
+++ trunk/lib/Frey/HTML.pm 2008/06/29 16:24:41 23
@@ -1,32 +1,96 @@
-package HTML;
+package Frey::HTML;
use strict;
use warnings;
use Time::HiRes qw/time/;
use Data::Dump qw/dump/;
-use View;
+use Carp qw/confess/;
-use Data::Dump qw/dump/;
+=head1 NAME
+
+Frey::HTML - generate html pages
+
+=head2 METHODS
+
+=cut
+
+# FIXME
+
+our @view_classes = qw(
+ Frey::View
+ Frey::REST
+ Strix::View
+);
+
+warn "Using view classes ", dump( @view_classes );
+
+foreach ( @view_classes ) {
+ my $path = $_;
+ $path =~ s!::!/!g;
+ $path .= '.pm';
+ require $path or warn "Can't require $_ from $path: $!";
+}
warn "available templates = ",dump( Template::Declare->templates );
+our @javascript;
+our $debug = 0;
+
use Template::Declare;
use Template::Declare::Tags; # defaults to 'HTML'
-Template::Declare->init( roots => ['HTML','View'], around_template => sub {
+Template::Declare->init( roots => \@view_classes, around_template => sub {
my ($orig, $path, $args, $code) = @_;
my $t = time;
html {
- head {}
+ head {
+ title { $path }
+ link {
+ { rel is 'stylesheet' }
+ { href is 'static/app.css' }
+ { type is 'text/css' }
+ { media is 'screen' }
+ };
+ foreach my $js ( @javascript ) {
+ script {
+ { type is 'text/javascript' }
+ { src is $js }
+ }
+ }
+ }
body {
$orig->();
}
- }
- warn "TEMPLATE $path ",dump($args),sprintf(" in %.4fs\n",time - $t);
+ };
+ warn "TEMPLATE $path ",dump($args),sprintf(" in %.4fs\n",time - $t) if $debug;
});
-sub view {
-# warn "## view",dump( @_ );
+=head2 page
+
+Wrap template into html page
+
+ Frey::HTML->page( 'template_name', $req, $args );
+
+=cut
+
+sub page {
my $self = shift;
+ warn "## page $_[0]\n";
return Template::Declare->show( @_ );
}
+
+=head2 add_javascript
+
+Add javascript to current page
+
+ Frey::HTML->add_javascript( 'static/javascript.js' );
+
+=cut
+
+sub add_javascript {
+ my $self = shift;
+ my $js = shift or confess "no JavaScript path";
+# return unless -e $js; # FIXME
+ warn "Added javascript $js\n";
+ push @javascript, $js;
+}