aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction
diff options
context:
space:
mode:
authorgroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-01-21 22:08:47 +0000
committergroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-01-21 22:08:47 +0000
commitcb92a3a388a813d1309757155a4b7750eb9f5504 (patch)
treea149a0d6e129517b44ab6d41a0d89ff101be91c8 /lib/Reaction
parentc6ea0238337f4b071be1670e01cfa0a6467db101 (diff)
downloadreaction-cb92a3a388a813d1309757155a4b7750eb9f5504.tar.gz
reaction-cb92a3a388a813d1309757155a4b7750eb9f5504.zip
add a default 404 and 403 action, use the 404 on collection controller, make html source less ugly by eliminating unnecessary whitespace
Diffstat (limited to 'lib/Reaction')
-rw-r--r--lib/Reaction/UI/Controller/Collection.pm2
-rw-r--r--lib/Reaction/UI/Controller/Root.pm12
-rw-r--r--lib/Reaction/UI/LayoutSet.pm5
-rw-r--r--lib/Reaction/UI/LayoutSet/TT.pm11
4 files changed, 22 insertions, 8 deletions
diff --git a/lib/Reaction/UI/Controller/Collection.pm b/lib/Reaction/UI/Controller/Collection.pm
index 9606695..77a0005 100644
--- a/lib/Reaction/UI/Controller/Collection.pm
+++ b/lib/Reaction/UI/Controller/Collection.pm
@@ -41,7 +41,7 @@ sub base :Action :CaptureArgs(0) {
sub object :Chained('base') :PathPart('id') :CaptureArgs(1) {
my ($self, $c, $key) = @_;
my $object = $self->get_collection($c)->find($key);
- confess "Object? what object?" unless $object; # should be a 404.
+ $c->detach("/error_404") unless $object;
$c->stash(object => $object);
}
diff --git a/lib/Reaction/UI/Controller/Root.pm b/lib/Reaction/UI/Controller/Root.pm
index 75273fb..51b0655 100644
--- a/lib/Reaction/UI/Controller/Root.pm
+++ b/lib/Reaction/UI/Controller/Root.pm
@@ -31,6 +31,18 @@ sub end :Private {
$ctx->stash->{window}->flush;
}
+sub error_404 :Private {
+ my ($self, $c) = @_;
+ $c->res->body("Error 404: File not Found");
+ $c->res->status(404);
+}
+
+sub error_403 :Private {
+ my ($self, $c) = @_;
+ $c->res->body("Error 403: Forbidden");
+ $c->res->status(403);
+}
+
1;
=head1 NAME
diff --git a/lib/Reaction/UI/LayoutSet.pm b/lib/Reaction/UI/LayoutSet.pm
index da4ecdc..792bb70 100644
--- a/lib/Reaction/UI/LayoutSet.pm
+++ b/lib/Reaction/UI/LayoutSet.pm
@@ -80,7 +80,10 @@ class LayoutSet which {
my ($data, $text) = ($1, $2);
if ($data =~ /^for layout (\S+)/) {
my $fname = $1;
- $layouts->{$fname} = $text;
+ #remove extra whitespace without killing indentation
+ #remove all empty leading lines. and trailing whitespace
+ ($layouts->{$fname}) =
+ ($text =~ /^(?:\s*\n)*((?:.*?\n)*(?:.*?\S+.*?\n))\s*$/m);
} elsif ($data =~ /^extends (\S+)/) {
my $super_name = $1;
$self->super($build_args->{view}->create_layout_set($super_name))
diff --git a/lib/Reaction/UI/LayoutSet/TT.pm b/lib/Reaction/UI/LayoutSet/TT.pm
index 2046c41..c131bdb 100644
--- a/lib/Reaction/UI/LayoutSet/TT.pm
+++ b/lib/Reaction/UI/LayoutSet/TT.pm
@@ -27,12 +27,11 @@ class TT is LayoutSet, which {
my $name = $self->name;
$name =~ s/\//__/g; #slashes are not happy here...
my $layouts = $self->layouts;
- my $tt_source = qq{[% VIEW ${name};\n\n}.
- join("\n\n",
- map {
- qq{BLOCK $_; -%]\n}.$layouts->{$_}.qq{\n[% END;};
- } keys %$layouts
- ).qq{\nEND; # End view\ndata.view = ${name};\n %]};
+
+ my $tt_source = join("\n", "[%- VIEW ${name};",
+ (map {("BLOCK $_; -%]" . $layouts->{$_} ."[%- END;") } keys %$layouts),
+ "END; # End view\ndata.view = ${name}; -%]" );
+
$tt_object->process(\$tt_source, $tt_args)
|| confess "Template processing error: ".$tt_object->error
." processing:\n${tt_source}";