[Jifty-commit] r3114 - in jifty/trunk/examples/Doxory: . bin doc
etc lib lib/Doxory lib/Doxory/Action lib/Doxory/Model log
share share/po share/web share/web/static share/web/templates t var
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Apr 8 15:49:37 EDT 2007
Author: dpavlin
Date: Sun Apr 8 15:49:35 2007
New Revision: 3114
Added:
jifty/trunk/examples/Doxory/
jifty/trunk/examples/Doxory/Makefile.PL
jifty/trunk/examples/Doxory/bin/
jifty/trunk/examples/Doxory/bin/jifty (contents, props changed)
jifty/trunk/examples/Doxory/doc/
jifty/trunk/examples/Doxory/doxory (contents, props changed)
jifty/trunk/examples/Doxory/etc/
jifty/trunk/examples/Doxory/etc/config.yml
jifty/trunk/examples/Doxory/lib/
jifty/trunk/examples/Doxory/lib/Doxory/
jifty/trunk/examples/Doxory/lib/Doxory/Action/
jifty/trunk/examples/Doxory/lib/Doxory/Dispatcher.pm
jifty/trunk/examples/Doxory/lib/Doxory/Model/
jifty/trunk/examples/Doxory/lib/Doxory/Model/Choice.pm
jifty/trunk/examples/Doxory/lib/Doxory/Model/User.pm
jifty/trunk/examples/Doxory/lib/Doxory/Model/Vote.pm
jifty/trunk/examples/Doxory/lib/Doxory/View.pm
jifty/trunk/examples/Doxory/log/
jifty/trunk/examples/Doxory/share/
jifty/trunk/examples/Doxory/share/po/
jifty/trunk/examples/Doxory/share/web/
jifty/trunk/examples/Doxory/share/web/static/
jifty/trunk/examples/Doxory/share/web/templates/
jifty/trunk/examples/Doxory/t/
jifty/trunk/examples/Doxory/t/00-model-User.t
jifty/trunk/examples/Doxory/var/
jifty/trunk/examples/Doxory/var/jifty-server.pid
jifty/trunk/examples/Doxory/var/mason/
Log:
added audryt Doxory from doc/talks/yapcasia2007-doxory.pdf
Added: jifty/trunk/examples/Doxory/Makefile.PL
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/Makefile.PL Sun Apr 8 15:49:35 2007
@@ -0,0 +1,8 @@
+use inc::Module::Install;
+
+name 'Doxory';
+version '0.01';
+requires 'Jifty' => '0.70117';
+requires 'Regexp::Common::profanity_us';
+
+WriteAll;
Added: jifty/trunk/examples/Doxory/bin/jifty
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/bin/jifty Sun Apr 8 15:49:35 2007
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use File::Basename qw(dirname);
+use UNIVERSAL::require;
+
+BEGIN {
+ Jifty::Util->require or die $UNIVERSAL::require::ERROR;
+ my $root = Jifty::Util->app_root;
+ unshift @INC, "$root/lib" if ($root);
+}
+
+use Jifty::Script;
+local $SIG{INT} = sub { warn "Stopped\n"; exit; };
+Jifty::Script->dispatch();
Added: jifty/trunk/examples/Doxory/doxory
==============================================================================
Binary file. No diff available.
Added: jifty/trunk/examples/Doxory/etc/config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/etc/config.yml Sun Apr 8 15:49:35 2007
@@ -0,0 +1,51 @@
+---
+framework:
+ SkipAccessControl: 1
+ AdminMode: 0
+ ApplicationClass: Doxory
+ ApplicationName: Doxory
+ ApplicationUUID: 181049AC-E029-11DB-A5EB-227D19064FA1
+ Database:
+ CheckSchema: 1
+ Database: doxory
+ Driver: SQLite
+ Host: localhost
+ Password: ''
+ RecordBaseClass: Jifty::DBI::Record::Cachable
+ User: ''
+ Version: 0.0.1
+ DevelMode: 1
+ L10N:
+ PoDir: share/po
+ Lang: en
+ LogLevel: INFO
+ Mailer: Sendmail
+ MailerArgs: []
+
+ Plugins:
+ - SkeletonApp: {}
+ - REST: {}
+ - Halo: {}
+ - ErrorTemplates: {}
+ - CompressedCSSandJS: {}
+ - Authentication::Password: {}
+
+ PubSub:
+ Backend: Memcached
+ Enable: ~
+ TemplateClass: Doxory::View
+ SkipAccessControl: 1
+ Web:
+ BaseURL: http://localhost
+ DataDir: var/mason
+ Globals: []
+
+ MasonConfig:
+ autoflush: 0
+ default_escape_flags: h
+ error_format: text
+ error_mode: fatal
+ Port: 8888
+ ServeStaticFiles: 1
+ StaticRoot: share/web/static
+ TemplateRoot: share/web/templates
Added: jifty/trunk/examples/Doxory/lib/Doxory/Dispatcher.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/lib/Doxory/Dispatcher.pm Sun Apr 8 15:49:35 2007
@@ -0,0 +1,43 @@
+package Doxory::Dispatcher;
+use strict;
+use warnings;
+use Jifty::Dispatcher -base;
+
+before '*' => run {
+ if (Jifty->web->current_user->id) {
+ my $top = Jifty->web->navigation;
+ $top->child( 'Pick!' => url => '/pick' );
+ $top->child( 'Choices' => url => '/choices' );
+ }
+ elsif ($1 !~ /^login|^signup/) {
+ tangent 'login';
+ }
+};
+
+#on '/' => show 'new_choice';
+
+on pick => run {
+ my $choices = Doxory::Model::ChoiceCollection->new;
+ my $votes = $choices->join(
+ type => 'left',
+ alias1 => 'main', column1 => 'id',
+ table2 => 'votes', column2 => 'choice',
+ );
+ $choices->limit(
+ leftjoin => $votes, column => 'voter',
+ value => Jifty->web->current_user->id,
+ );
+ $choices->limit(
+ alias => $votes, column => 'voter',
+ operator => 'IS', value => 'NULL',
+ );
+
+ if (my $c = $choices->first) {
+ set choice => $c;
+ }
+ else {
+ show 'nothing_to_pick';
+ }
+};
+
+1;
Added: jifty/trunk/examples/Doxory/lib/Doxory/Model/Choice.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/lib/Doxory/Model/Choice.pm Sun Apr 8 15:49:35 2007
@@ -0,0 +1,64 @@
+use strict;
+use warnings;
+
+package Doxory::Model::Choice;
+use Jifty::DBI::Schema;
+
+use Doxory::Record schema {
+ column name =>
+ label is 'I need help deciding...',
+ render as 'textarea';
+
+ column a =>
+ label is 'On the one hand',
+ render as 'textarea',
+ is mandatory;
+
+ column b =>
+ label is 'On the other hand',
+ render as 'textarea',
+ is mandatory;
+
+ column asked_by =>
+ label is 'Asked by',
+ default is defer { Jifty->web->current_user->id },
+ references Doxory::Model::User;
+};
+use Regexp::Common 'profanity_us';
+
+sub validate_name {
+ my ($self, $name) = @_;
+ if ($name =~ /$RE{profanity}/i) {
+ return (0, 'Would you speak like that in front of your mother? *cough*');
+ }
+ return 1;
+}
+
+sub canonicalize_name {
+ my ($self, $name) = @_;
+
+ $name =~ s/$RE{profanity}/**expletives**/gi;
+ return $name;
+}
+
+sub in_favor_of_a {
+ my $self = shift;
+ $self->in_favor_of('a');
+}
+
+sub in_favor_of_b {
+ my $self = shift;
+ $self->in_favor_of('b');
+}
+
+sub in_favor_of {
+ my $self = shift;
+ my $suggestion = shift;
+ my $votes = Doxory::Model::VoteCollection->new();
+ Carp::cluck unless ($self->id);
+ $votes->limit(column => 'choice', value => $self->id);
+ $votes->limit(column => 'suggestion' => value => $suggestion);
+ return $votes;
+}
+
+1;
Added: jifty/trunk/examples/Doxory/lib/Doxory/Model/User.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/lib/Doxory/Model/User.pm Sun Apr 8 15:49:35 2007
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+
+package Doxory::Model::User;
+use Jifty::DBI::Schema;
+
+use Doxory::Record schema {
+
+column name =>
+ label is 'Username',
+ hints is 'Other people see this when you ask questions.',
+ is distinct, is mandatory;
+
+column email =>
+ label is 'Email',
+ hints is 'We will not sell it to anybody. Honest.',
+ default is '',
+ is distinct, is immutable;
+
+};
+
+use Jifty::Plugin::User::Mixin::Model::User;
+use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
+
+# Your model-specific methods go here.
+1;
+
Added: jifty/trunk/examples/Doxory/lib/Doxory/Model/Vote.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/lib/Doxory/Model/Vote.pm Sun Apr 8 15:49:35 2007
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+
+package Doxory::Model::Vote;
+use Jifty::DBI::Schema;
+
+use Doxory::Record schema {
+ column choice =>
+ references Doxory::Model::Choice;
+
+ column voter =>
+ references Doxory::Model::User;
+
+ column suggestion =>
+ valid are qw( a b skip );
+
+ column comments =>
+ label is 'Comments?',
+ render as 'textarea';
+};
+
+1;
Added: jifty/trunk/examples/Doxory/lib/Doxory/View.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/lib/Doxory/View.pm Sun Apr 8 15:49:35 2007
@@ -0,0 +1,84 @@
+package Doxory::View;
+use utf8;
+use strict;
+use warnings;
+use Jifty::View::Declare -base;
+
+template '/' => page {
+ h1 { 'Ask a question!' }
+ div { show 'new_choice' }
+};
+
+private template new_choice => sub {
+ form {
+ my $action = new_action( class => 'CreateChoice' );
+ render_action( $action => ['name', 'a', 'b'] );
+ form_submit( label => 'Ask the crowd!' );
+ }
+};
+
+template choices => page {
+ h1 { 'My Choices' }
+ dl {
+ my $choices = Doxory::Model::ChoiceCollection->new;
+ $choices->limit(
+ column => 'asked_by',
+ value => Jifty->web->current_user->id,
+ );
+ while (my $c = $choices->next) {
+ dt { $c->name, ' (', $c->asked_by->name, ')' }
+ dd {
+ b { $c->a, ' (', $c->in_favor_of_a->count, ')' }
+ em { 'vs' }
+ b { $c->b, ' (', $c->in_favor_of_b->count, ')' }
+ }
+ }
+ }
+};
+
+template pick => page {
+ my $choice = get('choice');
+ my $action = new_action( class => 'CreateVote' );
+ my $redir = new_action(
+ class => "Jifty::Action::Redirect",
+ arguments => { url => '/pick' },
+ );
+ # XXX - For some reason passing it in on the previous line doesn't work.
+ my %args = (
+ choice => $choice->id,
+ voter => Jifty->web->current_user->id,
+ );
+
+ h1 { $choice->asked_by->name, ': ', $choice->name }
+ div { form {
+ my ($x, $y) = map { $action->button(
+ submit => [ $action, $redir ],
+ label => $choice->$_,
+ arguments => { suggestion => $_, %args },
+ ) } ((rand > 0.5) ? ('a', 'b') : ('b', 'a'));
+
+ span { $x } em { 'or' } span { $y } em { 'or' } span {
+ $action->button(
+ submit => [ $action, $redir ],
+ label => 'None of the above',
+ arguments => { suggestion => 'skip', %args },
+ );
+ }
+
+ p { render_param( $action => 'comments' ) }
+ } }
+};
+
+template nothing_to_pick => page {
+ h1 { "There's nothing for you to pick." }
+
+ p { "No one you know is angsting about anything. Everybody knows where
+ they're going to dinner, what to do on their next date and whether to
+ drop that class. You have such lovely and well adjusted friends." }
+
+ h2 { "Maybe it's time to ask for some advice..." };
+
+ show 'new_choice';
+};
+
+1;
Added: jifty/trunk/examples/Doxory/t/00-model-User.t
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/t/00-model-User.t Sun Apr 8 15:49:35 2007
@@ -0,0 +1,49 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+A basic test harness for the User model.
+
+=cut
+
+use Jifty::Test tests => 11;
+
+# Make sure we can load the model
+use_ok('Doxory::Model::User');
+
+# Grab a system user
+my $system_user = Doxory::CurrentUser->superuser;
+ok($system_user, "Found a system user");
+
+# Try testing a create
+my $o = Doxory::Model::User->new(current_user => $system_user);
+my ($id) = $o->create();
+ok($id, "User create returned success");
+ok($o->id, "New User has valid id set");
+is($o->id, $id, "Create returned the right id");
+
+# And another
+$o->create();
+ok($o->id, "User create returned another value");
+isnt($o->id, $id, "And it is different from the previous one");
+
+# Searches in general
+my $collection = Doxory::Model::UserCollection->new(current_user => $system_user);
+$collection->unlimit;
+is($collection->count, 2, "Finds two records");
+
+# Searches in specific
+$collection->limit(column => 'id', value => $o->id);
+is($collection->count, 1, "Finds one record with specific id");
+
+# Delete one of them
+$o->delete;
+$collection->redo_search;
+is($collection->count, 0, "Deleted row is gone");
+
+# And the other one is still there
+$collection->unlimit;
+is($collection->count, 1, "Still one left");
+
Added: jifty/trunk/examples/Doxory/var/jifty-server.pid
==============================================================================
--- (empty file)
+++ jifty/trunk/examples/Doxory/var/jifty-server.pid Sun Apr 8 15:49:35 2007
@@ -0,0 +1 @@
+8972
\ No newline at end of file
More information about the Jifty-commit
mailing list