Permalink
Browse files

basic rendering of boxes and static content seems to work

  • Loading branch information...
1 parent 0b83488 commit 504ba9b0275b5988f008059a6484480fa2a9812c @jgsmith committed May 31, 2012
View
@@ -84,7 +84,7 @@ OokOok - Catalyst based application
=head1 DESCRIPTION
-[enter your description here]
+OokOok is a platform for creating web-based projects.
=head1 SEE ALSO
@@ -116,28 +116,16 @@ sub default :Chained('/') :PathPart('v') {
# for the requested resource
# We walk through the sitemap using the elements in @path
- my $sitemap = $c -> stash -> {edition} -> sitemap;
-
- my $page_uuid;
- while(@path && !$page_uuid && $sitemap) {
- my $slug = shift @path;
- if($sitemap->{$slug}) {
- if(!@path) {
- $page_uuid = $sitemap->{$slug}->{visual};
- }
- else {
- $sitemap = $sitemap->{$slug}->{children};
- }
- }
- }
+ $c -> stash -> {path} = [reverse $c -> stash -> {edition} -> page_path(@path)];
- if(!$page_uuid) {
+ # we expect as many entries in the stashed path as are in the @path
+ if(scalar(@{$c->stash->{path}}) != scalar(@path)) {
$c -> response->body( 'Page not found' );
$c -> response -> status(404);
$c -> detach;
}
- my $page = $c -> stash -> {project} -> page_for_date($page_uuid, $c -> stash -> {date});
+ my $page = $c -> stash -> {path} -> [0];
if(!$page) {
$c -> response->body( 'Page not found' );
@@ -2,7 +2,38 @@ package OokOok::Role::Schema::Result::HasEditions;
use Moose::Role;
-use Data::UUID;
+=head1 NAME
+
+OokOok::Role::Schema::Result::HasEditions
+
+=head1 SYNOPSIS
+
+ package OokOok::Schema::Result::Thing;
+
+ use Moose;
+ extends 'DBIx::Class::Core';
+ with 'OokOok::Role::Schema::Result::HasEditions';
+
+=head1 DESCRIPTION
+
+This role provides support for objects that have editions in OokOok.
+
+The class that uses this role must provide an C<editions> function that
+represents a 'has many' relationship with the edition objects.
+
+=cut
+
+requires 'editions';
+
+=head1 AUGMENTATIONS
+
+The following methods are overridden or otherwise altered in functionality.
+
+=head2 insert
+
+=cut
+
+use Data::UUID ();
use DateTime;
{
@@ -23,12 +54,24 @@ after insert => sub {
$_[0];
};
+=head2 delete
+
+=cut
+
before delete => sub {
if(grep { $_ -> is_frozen } $_[0] -> editions) {
die "Unable to delete with published editions";
}
};
+=head1 METHODS
+
+The following methods are added to the class.
+
+=head2 edition_for_date
+
+=cut
+
sub edition_for_date {
my($self, $date) = @_;
@@ -37,8 +80,16 @@ sub edition_for_date {
return $self -> _apply_date_constraint($q, "", $date) -> first;
}
+=head2 current_edition
+
+=cut
+
sub current_edition { $_[0] -> edition_for_date; }
+=head2 relation_for_date
+
+=cut
+
sub relation_for_date {
my($self, $relation, $uuid, $date) = @_;
@@ -88,3 +139,4 @@ sub _apply_date_constraint {
1;
__END__
+
@@ -2,6 +2,8 @@ package OokOok::Role::Schema::Result::HasVersions;
use Moose::Role;
+use Data::UUID ();
+
{
my $ug = Data::UUID -> new;
before insert => sub {
@@ -138,6 +138,10 @@ __PACKAGE__->has_many("layouts" => "OokOok::Schema::Result::Layout", "edition_id
cascade_copy => 0,
cascade_delete => 1,
});
+__PACKAGE__->has_many("snippets" => "OokOok::Schema::Result::Snippet", "edition_id", {
+ cascade_copy => 0,
+ cascade_delete => 1,
+});
__PACKAGE__->belongs_to("theme" => "OokOok::Schema::Result::Theme", "theme_id");
@@ -182,6 +186,38 @@ sub snippet {
return $self -> project -> snippet_for_date($name, $self -> frozen_on);
}
+sub page {
+ my($self, $uuid) = @_;
+
+ return $self -> project -> page_for_date($uuid, $self -> frozen_on);
+}
+
+sub page_path {
+ my($self, @path) = @_;
+
+ my $sitemap = $self -> sitemap;
+
+ my @pages;
+ my $page_uuid;
+
+ while(@path && $sitemap) {
+ my $slug = shift @path;
+ if($sitemap->{$slug}) {
+ $page_uuid = $sitemap->{$slug}->{visual};
+ $sitemap = $sitemap->{$slug}->{children};
+ if($page_uuid) {
+ push @pages, $self -> page($page_uuid);
+ }
+ else {
+ push @pages, undef;
+ }
+ }
+ }
+
+ return @pages;
+}
+
+
# You can replace this text with custom code or comments, and it will be preserved on regeneration
__PACKAGE__->meta->make_immutable;
1;
@@ -105,7 +105,6 @@ __PACKAGE__->set_primary_key("id");
# Created by DBIx::Class::Schema::Loader v0.07024 @ 2012-05-29 18:18:00
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nn3nDeoyVl11ZtFgc3Wlbw
-#use Data::UUID;
use Carp;
__PACKAGE__ -> belongs_to( "edition" => "OokOok::Schema::Result::Edition", "edition_id" );
@@ -50,6 +50,11 @@ __PACKAGE__->table("theme");
is_nullable: 0
size: 20
+=head2 created_on
+
+ data_type: 'datetime'
+ is_nullable: 0
+
=head2 user_id
data_type: 'integer'
@@ -62,6 +67,8 @@ __PACKAGE__->add_columns(
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"uuid",
{ data_type => "char", is_nullable => 0, size => 20 },
+ "created_on",
+ { data_type => "datetime", is_nullable => 0 },
"user_id",
{ data_type => "integer", is_nullable => 1 },
);
@@ -79,8 +86,8 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("id");
-# Created by DBIx::Class::Schema::Loader v0.07024 @ 2012-05-29 14:06:21
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Q2+q6sC+TiLLzP2oOq0lVQ
+# Created by DBIx::Class::Schema::Loader v0.07024 @ 2012-05-31 10:12:57
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Ef499mocYWSV2lNKH4y3Mw
__PACKAGE__ -> has_many(
editions => 'OokOok::Schema::Result::ThemeEdition',
@@ -52,6 +52,7 @@ __PACKAGE__->table("theme_edition");
=head2 name
data_type: 'varchar'
+ default_value: (empty string)
is_nullable: 0
size: 255
@@ -78,7 +79,7 @@ __PACKAGE__->add_columns(
"theme_id",
{ data_type => "integer", is_nullable => 0 },
"name",
- { data_type => "varchar", is_nullable => 0, size => 255 },
+ { data_type => "varchar", default_value => "", is_nullable => 0, size => 255 },
"description",
{ data_type => "text", is_nullable => 1 },
"created_on",
@@ -100,13 +101,15 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("id");
-# Created by DBIx::Class::Schema::Loader v0.07024 @ 2012-05-29 14:06:21
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:VoIP1/y0+FNane3nRY313Q
+# Created by DBIx::Class::Schema::Loader v0.07024 @ 2012-05-31 10:14:03
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dXvyxR135BeGnvRGdrQSNA
with 'OokOok::Role::Schema::Result::Edition';
__PACKAGE__ -> belongs_to("theme" => "OokOok::Schema::Result::Theme", "theme_id");
+__PACKAGE__ -> has_many("layouts" => "OokOok::Schema::Result::ThemeLayout", "theme_edition_id");
+
sub owner { $_[0] -> theme; }
# You can replace this text with custom code or comments, and it will be preserved on regeneration
Oops, something went wrong.

0 comments on commit 504ba9b

Please sign in to comment.