summaryrefslogtreecommitdiffstats
path: root/lib/Narwhal/Component/Wiki.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-01-26 14:56:23 -0600
committerJesse Luehrs <doy@tozt.net>2011-01-26 14:56:23 -0600
commit0d2b29fd9d932f909f46209d17963752379ea545 (patch)
treee27792b5aa077339b22d8d6c6bd9597d296f519a /lib/Narwhal/Component/Wiki.pm
parentaf5867fd48b84c7ea1cba67574294334bb2cc19e (diff)
downloadnarwhal-0d2b29fd9d932f909f46209d17963752379ea545.tar.gz
narwhal-0d2b29fd9d932f909f46209d17963752379ea545.zip
initial sketch
Diffstat (limited to 'lib/Narwhal/Component/Wiki.pm')
-rw-r--r--lib/Narwhal/Component/Wiki.pm65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/Narwhal/Component/Wiki.pm b/lib/Narwhal/Component/Wiki.pm
new file mode 100644
index 0000000..5b89816
--- /dev/null
+++ b/lib/Narwhal/Component/Wiki.pm
@@ -0,0 +1,65 @@
+package Narwhal::Component::Wiki;
+use Moose;
+
+use Narwhal::Page;
+
+has kioku => (
+ isa => 'KiokuX::Model',
+ required => 1,
+ handles => 'KiokuDB::Role::API',
+);
+
+has tt => (
+ isa => 'Template',
+ required => 1,
+ handles => ['process'],
+);
+
+has scope => (
+ is => 'ro',
+ isa => 'KiokuDB::LiveObjects::Scope',
+ lazy => 1,
+ default => sub { shift->new_scope },
+);
+
+sub BUILD {
+ my $self = shift;
+ $self->scope;
+}
+
+sub page {
+ my $self = shift;
+ my ($req, $page) = @_;
+ my $page_obj = $self->lookup("page:$page");
+ return $req->new_response(404)
+ unless $page_obj;
+ my $out;
+ $self->process('page.tt', { uri_for => sub { '/' . $req->uri_for({@_}) }, text => $page_obj->text, page => $page }, \$out);
+ return $req->new_response(200, [], $out);
+}
+
+sub edit {
+ my $self = shift;
+ my ($req, $page) = @_;
+ if ($req->method eq 'POST') {
+ my $page_obj = Narwhal::Page->new(text => $req->param('text'));
+ $self->txn_do(sub {
+ $self->delete("page:$page");
+ $self->insert("page:$page" => $page_obj);
+ });
+ my $res = $req->new_response(303);
+ $res->location('/' . $req->uri_for({controller => 'wiki', action => 'page', page_name => $page}));
+ return $res;
+ }
+ else {
+ my $page_obj = $self->lookup("page:$page");
+ my $out;
+ $self->process('edit.tt', { uri_for => sub { '/' . $req->uri_for({@_}) }, text => ($page_obj ? $page_obj->text : ''), page => $page }, \$out);
+ return $req->new_response(200, [], $out);
+ }
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;