[Catalyst-commits] r7185 - trunk/examples/CatalystAdvent/root/2007

jshirley at dev.catalyst.perl.org jshirley at dev.catalyst.perl.org
Wed Nov 28 19:55:03 GMT 2007


Author: jshirley
Date: 2007-11-28 19:55:03 +0000 (Wed, 28 Nov 2007)
New Revision: 7185

Modified:
   trunk/examples/CatalystAdvent/root/2007/3.pod
Log:
More meats on day 3.

Modified: trunk/examples/CatalystAdvent/root/2007/3.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2007/3.pod	2007-11-28 16:03:58 UTC (rev 7184)
+++ trunk/examples/CatalystAdvent/root/2007/3.pod	2007-11-28 19:55:03 UTC (rev 7185)
@@ -23,7 +23,7 @@
 The examples that are listed here are available from the Catalyst subversion
 repository, available via:
 
- svn co http://dev.catalystframework.org/repos/Catalyst/trunk/examples/CatalystREST-YUI
+ svn co http://dev.catalystframework.org/repos/Catalyst/trunk/examples/RestYUI
 
 It is a good idea to check out the sources of the sample application to better
 follow along with the examples.  Included is the necessary YUI javascript files
@@ -54,6 +54,29 @@
 
 =back
 
+=head2 Starting the Catalyst Application
+
+We're taking last year's AdventREST example app and slightly modifying it to
+add support for YUI.
+
+So, to get started you can check out that application from subversion by doing:
+ 
+ svn co http://dev.catalystframework.org/repos/Catalyst/trunk/examples/AdventREST
+
+Or check out the completed RestYUI application.
+
+The only fundamental change to the application is adding the Template Toolkit
+view:
+
+ script/adventrest_create.pl view TT TT
+
+Also, we have to grab the static files for YUI itself.  As of writing this,
+version 2.3.1 is available from L<http://sourceforge.net/project/downloading.php?group_id=165715&filename=yui_2.3.1.zip>.  Check the latest version at
+L<http://developer.yahoo.com/yui/>
+
+After extracting the files from the zip archive, just copy over the .js files to
+the root/static directory.
+
 =head2 Preparing the REST WebService
 
 To gain access to the REST services, we'll be accessing both the C<list> and the
@@ -101,9 +124,9 @@
            result_set => {
                totalResultsAvailable => $rs->pager->total_entries,
                totalResultsReturned  => $rs->pager->entries_on_this_page,
-               firstResultPosition   => $rs->pager->current_page
+               firstResultPosition   => $rs->pager->current_page,
                result => [ @user_list ]
-           ;}
+           }
        });
    };
 
@@ -111,12 +134,27 @@
 
 =head2 Connecting with YUI
 
-After the webservice is up, it is time to setup the Yahoo DataSource object:
+After the webservice is up, it is time to setup the Yahoo DataSource object.
 
+We'll create a simple template off of the index action in C<Root.pm>, so
+create this action in Root.pm:
+
+ sub index : Private {
+     my ( $self, $c ) = @_;
+     $c->forward( $c->view('TT') );
+ }
+
+That will just direct the action for "/" to go to TT, and render an "index.tt"
+template.
+
+The C<index.tt> file is pretty basic, and after the HTML tags this is the crux
+of what gets the job done:
+
     /* Create the YAHOO.util.DataSource object, the parameter is the
        URI to your REST service
     */
-    this.myDataSource = new YAHOO.util.DataSource("/rest/user_list?");
+    this.myDataSource = new YAHOO.util.DataSource("[%
+         c.uri_for( c.controller('User').action_for('user_list') ) %]");
     this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
     this.myDataSource.connXhrMode = "queueRequests";
     this.myDataSource.responseSchema = {




More information about the Catalyst-commits mailing list