[Jifty-commit] r2060 - in jifty/trunk: . lib/Jifty/Plugin
lib/Jifty/Plugin/REST plugins/REST
t/TestApp-Plugin-REST/lib/TestApp/Plugin/REST/Model
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Oct 22 21:46:23 EDT 2006
Author: jesse
Date: Sun Oct 22 21:46:22 2006
New Revision: 2060
Added:
jifty/trunk/lib/Jifty/Plugin/REST.pm
jifty/trunk/t/TestApp-Plugin-REST/lib/TestApp/Plugin/REST/Model/Group.pm
Removed:
jifty/trunk/plugins/REST/
Modified:
jifty/trunk/ (props changed)
jifty/trunk/META.yml
jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
jifty/trunk/t/TestApp-Plugin-REST/t/02-basic-use.t
Log:
r29156 at pinglin: jesse | 2006-10-22 18:46:06 -0700
* more REST plugin hackery
Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml (original)
+++ jifty/trunk/META.yml Sun Oct 22 21:46:22 2006
@@ -6,6 +6,7 @@
name: Jifty
no_index:
directory:
+ - share
- t
- doc
- inc
@@ -73,7 +74,7 @@
Locale::Maketext::Lexicon: 0.60
Log::Log4perl: 0
MIME::Types: 0
- Module:::CoreList: 0
+ Module::CoreList: 0
Module::Pluggable: 2.95
Module::ScanDeps: 0
Object::Declare: 0.13
Added: jifty/trunk/lib/Jifty/Plugin/REST.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/REST.pm Sun Oct 22 21:46:22 2006
@@ -0,0 +1,8 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::REST;
+use base qw/Jifty::Plugin/;
+
+our $VERSION = 0.01;
+1;
Modified: jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm Sun Oct 22 21:46:22 2006
@@ -9,7 +9,7 @@
use Data::Dumper ();
use XML::Simple;
-before qr{^ (/=/ .*) \. (js|json|yml|yaml|perl|xml|pl) $}x => run {
+before qr{^ (/=/ .*) \. (js|json|yml|yaml|perl|pl) $}x => run {
$ENV{HTTP_ACCEPT} = $2;
dispatch $1;
};
@@ -102,6 +102,37 @@
}
+#sub render_as_html {
+# my $prefix = shift;
+# my $url = shift;
+# my $content = shift;
+# warn "my content is $content";
+# if (ref($content) eq 'ARRAY') {
+# return start_html(-encoding => 'UTF-8', -declare_xml => 1, -title => 'models'),
+# ul(map {
+# li($prefix ?
+# a({-href => "$url/".Jifty::Web->escape_uri($_)}, Jifty::Web->escape($_))
+# : Jifty::Web->escape($_) )
+# } @{$content} || ''),
+# end_html();
+# }
+# elsif (ref($content) eq 'HASH') {
+# return start_html(-encoding => 'UTF-8', -declare_xml => 1, -title => 'models'),
+# dl(map {
+# dt($prefix ?
+# a({-href => "$url/".Jifty::Web->escape_uri($_)}, Jifty::Web->escape($_))
+# : Jifty::Web->escape($_)),
+# dd(html_dump($content->{$_})),
+# } sort keys %{$content} ),
+# end_html();
+# }
+# else {
+# return start_html(-encoding => 'UTF-8', -declare_xml => 1, -title => 'models'),
+# Jifty::Web->escape($content),
+# end_html();
+# }
+#}
+#
sub render_as_html {
my $prefix = shift;
my $url = shift;
@@ -152,6 +183,9 @@
}
}
+
+
+
sub action { resolve($_[0], 'Jifty::Action', Jifty->api->actions) }
sub model { resolve($_[0], 'Jifty::Record', Jifty->class_loader->models) }
@@ -173,9 +207,38 @@
list(['model'], map {s/::/./g; $_ } Jifty->class_loader->models);
}
+our @column_attrs =
+qw( name
+ type
+ default
+ validator
+ readable writable
+ length
+ mandatory
+ virtual
+ distinct
+ sort_order
+ refers_to by
+ alias_for_column
+ aliased_as
+ since until
+
+ label hints render_as
+ valid_values
+);
+
sub list_model_columns {
my ($model) = model($1);
- outs(['model', $model], { map { $_->name => { %$_ } } sort { $a->sort_order <=> $b->sort_order} $model->new->columns });
+
+ my %cols;
+ map {
+ my $col = $_;
+ $cols{$col->name} = { map { $_ => $col->$_() } @column_attrs} ;
+ } $model->new->columns;
+
+ outs(
+ [ 'model', $model ], \%cols
+ );
}
sub list_model_items {
@@ -205,7 +268,7 @@
my $rec = $model->new;
$rec->load_by_cols( $column => $key );
$rec->id or abort(404);
- outs( ['model', $model, $column, $key], { map {$_ => $rec->$_()} map {$_->name} $rec->columns});
+ outs( ['model', $model, $column, $key], { map {$_ => $rec->$_()} map {$_->name} $rec->columns});
}
sub replace_item {
Added: jifty/trunk/t/TestApp-Plugin-REST/lib/TestApp/Plugin/REST/Model/Group.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Plugin-REST/lib/TestApp/Plugin/REST/Model/Group.pm Sun Oct 22 21:46:22 2006
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+
+package TestApp::Plugin::REST::Model::Group;
+use Jifty::DBI::Schema;
+
+use TestApp::Plugin::REST::Record schema {
+
+};
+
+# Your model-specific methods go here.
+
+1;
+
Modified: jifty/trunk/t/TestApp-Plugin-REST/t/02-basic-use.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-REST/t/02-basic-use.t (original)
+++ jifty/trunk/t/TestApp-Plugin-REST/t/02-basic-use.t Sun Oct 22 21:46:22 2006
@@ -13,7 +13,7 @@
use lib 't/lib';
use Jifty::SubTest;
-use Jifty::Test tests => 61;
+use Jifty::Test tests => 66;
use Jifty::Test::WWW::Mechanize;
my $server = Jifty::Test->make_server;
@@ -34,8 +34,9 @@
$mech->get_ok("$URL/=/model.yml", "Got model list");
my $list = Jifty::YAML::Load($mech->content);
-is(scalar @$list, 1, "Got one model");
-is($list->[0],'TestApp.Plugin.REST.Model.User');
+is(scalar @$list, 2, "Got one model");
+is($list->[0],'TestApp.Plugin.REST.Model.Group');
+is($list->[1],'TestApp.Plugin.REST.Model.User');
# on GET '/=/model/*' => \&list_model_keys;
$mech->get_ok('/=/model/User');
@@ -83,7 +84,12 @@
# on GET '/=/action' => \&list_actions;
-my @actions = qw(TestApp.Plugin.REST.Action.CreateUser
+my @actions = qw(
+ TestApp.Plugin.REST.Action.CreateGroup
+ TestApp.Plugin.REST.Action.UpdateGroup
+ TestApp.Plugin.REST.Action.DeleteGroup
+ TestApp.Plugin.REST.Action.SearchGroup
+ TestApp.Plugin.REST.Action.CreateUser
TestApp.Plugin.REST.Action.UpdateUser
TestApp.Plugin.REST.Action.DeleteUser
TestApp.Plugin.REST.Action.SearchUser
@@ -93,15 +99,16 @@
$mech->get_ok('/=/action/');
is($mech->status, 200);
-
for (@actions) {
$mech->content_contains($_);
}
-
$mech->get_ok('/=/action.yml');
my @got = @{get_content()};
-is(join(",",sort @actions), join(",", sort(@got)), "Got all the actions as YAML");
+is(
+ join(",", sort @got ),
+ join(",",sort @actions),
+, "Got all the actions as YAML");
# on GET '/=/action/*' => \&list_action_params;
More information about the Jifty-commit
mailing list