Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add "article" class

  • Loading branch information...
commit b192cc23397880e444b8e08d5e617d36bcbf5216 1 parent 98f5470
@jrockway authored
View
3  README
@@ -0,0 +1,3 @@
+Ai is the Japanese word for love, but that's not why this is called
+that. It's Angerwhale Iterim; a blogging solution that moves blogging
+closer to angerwhale-ng!
View
29 lib/Ai/Article.pm
@@ -0,0 +1,29 @@
+use MooseX::Declare;
+
+role Ai::Article with KiokuDB::Role::ID::Content {
+ use Digest::SHA1 qw(sha1_hex);
+
+ has [qw/title content/] => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+ );
+
+ requires 'content_as_html';
+ requires 'post_date';
+ requires 'mod_date';
+
+ method gather_digestable_data {
+ return ($self->title, $self->content);
+ }
+
+ method kiokudb_object_id {
+ my $data = join "\0\r\n", map {
+ length("$_"). ":$_"
+ } $self->gather_digestable_data;
+
+ return 'article:sha1:'. sha1_hex($data);
+ }
+}
+
+1;
View
11 lib/Ai/Article/Markdown.pm
@@ -0,0 +1,11 @@
+use MooseX::Declare;
+
+role Ai::Article::Markdown with Ai::Article {
+ use Text::MultiMarkdown 'markdown';
+
+ method content_as_html {
+ return markdown( $self->content );
+ }
+}
+
+1;
View
8 lib/Ai/Article/Simple.pm
@@ -0,0 +1,8 @@
+use MooseX::Declare;
+
+class Ai::Article::Simple
+ with Ai::Article
+ with Ai::Article::Versioned
+ with Ai::Article::Markdown {
+
+}
View
37 lib/Ai/Article/Versioned.pm
@@ -0,0 +1,37 @@
+use MooseX::Declare;
+
+role Ai::Article::Versioned with Ai::Article {
+ use Ai::Types qw(Article);
+ use MooseX::Types::DateTime qw(DateTime);
+
+ has 'revision_date' => (
+ is => 'ro',
+ isa => DateTime,
+ required => 1,
+ );
+
+ has 'previous_revision' => (
+ is => 'ro',
+ isa => Article,
+ predicate => 'has_previous_revision',
+ );
+
+ method post_date {
+ return $self->previous_revision->post_date if $self->has_previous_revision;
+ return $self->revision_date;
+ }
+
+ method mod_date {
+ return $self->revision_date;
+ }
+
+ around gather_digestable_data {
+ return $self->$orig, $self->mod_date, (
+ $self->has_previous_revision ?
+ $self->previous_revision->kiokudb_object_id :
+ '<base>'
+ );
+ }
+}
+
+1;
View
22 lib/Ai/Types.pm
@@ -0,0 +1,22 @@
+package Ai::Types;
+use strict;
+use warnings;
+
+use KiokuDB::Set;
+use MooseX::Types -declare => [qw/Site Article Search Page Link Set PathPart/];
+use MooseX::Types::Moose qw(Str);
+
+role_type Site, { role => 'Ai::Site' };
+role_type Article, { role => 'Ai::Article' };
+role_type Search, { role => 'Ai::Search' };
+role_type Page, { role => 'Ai::Page' };
+role_type Link, { role => 'Ai::Link' };
+
+role_type Set, { role => 'KiokuDB::Set' };
+
+
+subtype PathPart, as Str,
+ where { !m{/} },
+ message { 'PathPart must not contain a /' };
+
+1;
View
40 t/blog-article.t
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+use Test::More;
+
+use Ai::Article::Simple;
+
+my $date2 = DateTime->new( year => 2009, month => 1, day => 1, hour => 10 );
+my $date = DateTime->new( year => 2009, month => 1, day => 1, hour => 1 );
+
+my $article = Ai::Article::Simple->new(
+ title => 'OH HAI',
+ content => 'Here is a *lolcat*!',
+ revision_date => $date2,
+ previous_revision => Ai::Article::Simple->new(
+ title => 'OH HAI',
+ content => 'Here is a lolcat',
+ revision_date => $date,
+ ),
+);
+
+is $article->post_date, $date, 'got post date';
+is $article->mod_date, $date2, 'got modification date';
+is $article->previous_revision->mod_date, $date, 'got previous mod date';
+is $article->previous_revision->post_date, $date, 'got previous post date';
+
+my $html = $article->content_as_html;
+chomp $html;
+is $html, '<p>Here is a <em>lolcat</em>!</p>', 'got html';
+
+my $identical_article = Ai::Article::Simple->new(
+ title => 'OH HAI',
+ content => 'Here is a lolcat',
+ revision_date => $date,
+);
+
+is $article->previous_revision->kiokudb_object_id,
+ $identical_article->kiokudb_object_id,
+ 'content-addressing works OK';
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.