[Jifty-commit] jifty branch, jifty_client, updated. 7fdefac9a12c3c8da19ee67861a0c0edcd165e26
Jifty commits
jifty-commit at lists.jifty.org
Sat May 1 01:51:22 EDT 2010
The branch, jifty_client has been updated
via 7fdefac9a12c3c8da19ee67861a0c0edcd165e26 (commit)
from d6f38c6c0ad445312e3422cb1cf2a9627177a770 (commit)
Summary of changes:
lib/Jifty/Plugin/REST/Dispatcher.pm | 38 ++++++++++++++++++++++++++++++++++-
1 files changed, 37 insertions(+), 1 deletions(-)
- Log -----------------------------------------------------------------
commit 7fdefac9a12c3c8da19ee67861a0c0edcd165e26
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Sat May 1 13:48:35 2010 +0800
Begin a .joose output format for models
clkao and I decided this is saner than doing the same kind of thing
client-side in javascript. one benefit is that you can do:
<script src="http://hiveminder.com/=/model/Task.joose">
(or a local cache of it)
diff --git a/lib/Jifty/Plugin/REST/Dispatcher.pm b/lib/Jifty/Plugin/REST/Dispatcher.pm
index 95f855d..3da801c 100644
--- a/lib/Jifty/Plugin/REST/Dispatcher.pm
+++ b/lib/Jifty/Plugin/REST/Dispatcher.pm
@@ -14,7 +14,7 @@ use Jifty::JSON ();
use Data::Dumper ();
use XML::Simple;
-before qr{^ (/=/ .*) \. (js|json|yml|yaml|perl|pl|xml|html) $}x => run {
+before qr{^ (/=/ .*) \. (js|json|joose|yml|yaml|perl|pl|xml|html) $}x => run {
Jifty->web->request->env->{HTTP_ACCEPT} = $2;
dispatch $1;
};
@@ -239,6 +239,27 @@ sub output_format {
freezer => sub { 'var $_ = ' . Jifty::JSON::encode_json( @_ ) },
};
}
+ elsif ($accept =~ /joose/i) {
+ my $freezer;
+
+ # Special case showing a particular model to construct a Joose class
+ if ( defined $prefix
+ and $prefix->[0] eq 'model'
+ and scalar @$prefix == 2 )
+ {
+ $freezer = sub { show_joose_class($prefix->[1]) };
+ }
+ else {
+ $freezer = sub { 'var $_ = ' . Jifty::JSON::encode_json( @_ ) },
+ }
+
+ return {
+ format => 'Joose',
+ extension => 'js',
+ content_type => 'application/javascript; charset=UTF-8',
+ freezer => $freezer,
+ };
+ }
elsif ($accept =~ qr{^(?:application/x-)?(?:perl|pl)$}i) {
return {
format => 'Perl',
@@ -919,6 +940,21 @@ sub show_action_form {
last_rule;
}
+=head2 show_joose_class $MODEL_CLASS
+
+Takes a single parameter, the class of an model.
+
+Generates a Joose class definition of the model's attributes.
+
+=cut
+
+sub show_joose_class {
+ my ($model) = model(shift);
+ Jifty::Util->require($model) or abort(404);
+ (my $class_name = $model) =~ s/.*:://;
+ return "Class('$class_name');";
+}
+
=head2 run_action
Expects $1 to be the name of an action we want to run.
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list