[Rt-commit] r2202 - in experiments/Bamboo: . doc doc/ex ex ex/petstore ex/petstore/bin ex/petstore/doc ex/petstore/etc ex/petstore/lib ex/petstore/lib/PetStore ex/petstore/lib/PetStore/Model ex/petstore/templates lib/Bamboo/View t

jesse at bestpractical.com jesse at bestpractical.com
Thu Feb 10 00:37:33 EST 2005


Author: jesse
Date: Thu Feb 10 00:37:32 2005
New Revision: 2202

Added:
   experiments/Bamboo/doc/
   experiments/Bamboo/doc/ex/
   experiments/Bamboo/doc/howworks
   experiments/Bamboo/ex/
   experiments/Bamboo/ex/petstore/
   experiments/Bamboo/ex/petstore/bin/
   experiments/Bamboo/ex/petstore/doc/
   experiments/Bamboo/ex/petstore/etc/
   experiments/Bamboo/ex/petstore/lib/
   experiments/Bamboo/ex/petstore/lib/PetStore/
   experiments/Bamboo/ex/petstore/lib/PetStore/Model/
   experiments/Bamboo/ex/petstore/lib/PetStore/Model/Cart.pm
   experiments/Bamboo/ex/petstore/lib/PetStore/Model/Product.pm
   experiments/Bamboo/ex/petstore/lib/PetStore/Model/ProductCollection.pm
   experiments/Bamboo/ex/petstore/lib/PetStore/Model/User.pm
   experiments/Bamboo/ex/petstore/lib/PetStore/Model/UserCollection.pm
   experiments/Bamboo/ex/petstore/templates/
   experiments/Bamboo/ex/petstore/templates/cart.html
   experiments/Bamboo/ex/petstore/templates/checkout.html
   experiments/Bamboo/ex/petstore/templates/department.html
   experiments/Bamboo/ex/petstore/templates/edit_product.html
   experiments/Bamboo/ex/petstore/templates/home.html
   experiments/Bamboo/ex/petstore/templates/inventory.html
   experiments/Bamboo/lib/Bamboo/View/Widget.pm
   experiments/Bamboo/t/10widget.t
Modified:
   experiments/Bamboo/   (props changed)
   experiments/Bamboo/META.yml
Log:
 r4649 at hualien:  jesse | 2005-02-10T05:32:36.969798Z
 flesh on them bones


Modified: experiments/Bamboo/META.yml
==============================================================================
--- experiments/Bamboo/META.yml	(original)
+++ experiments/Bamboo/META.yml	Thu Feb 10 00:37:32 2005
@@ -12,4 +12,4 @@
 no_index:
   directory:
     - inc
-generated_by: Module::Install version 0.35
+generated_by: Module::Install version 0.36

Added: experiments/Bamboo/doc/howworks
==============================================================================
--- (empty file)
+++ experiments/Bamboo/doc/howworks	Thu Feb 10 00:37:32 2005
@@ -0,0 +1,75 @@
+so. you've got:
+
+    MODEL
+
+        This is your backend. it's what has your business logic.
+        It might do its own validation. It might not.
+
+
+    VIEW
+
+        This is the bit that lets you describe your presentation
+        layer.  When the user gets to a certain place, what 
+        should they see?  Where can the user go from here?
+
+        Note that it doesn't deal with "how do we process the
+        user's input"
+
+        What can it do:
+
+            * Display arbitrary html
+            * Build a form, containing:
+            * Display values, labels or edit widgets for 
+              a given model class attribute
+
+                ==NOTE: I probably don't want to actually
+                encourage users to be able to edit attributes
+                instead, users should use the "call a method" edit
+                widgets as described below
+
+            * Display labels and edit widgets for any class
+              method's parameters
+
+
+    CONTROLLER
+   
+        The user has handed us some input in the context
+        of some page view and some webform. How are we going to
+        cope with it.  From here we can:
+
+            * canonicalize the input
+            * validate the input
+            * if the input looks good:
+                * process it, pick up status messages
+                  and warnings
+
+                * push the user to the next page
+
+
+            * If the input looks bad:
+                * push the user back to the form they sent
+                  in, possibly with errors inline and notes
+                OR * push the user to an error page
+
+
+
+        Before any page is displayed, the page's pre_hook is run.
+        This pre_hook will set up objects the page needs to display, 
+        complex computation done for the page, etc.
+
+
+        After the page is displayed, the display post_hook is run.
+
+
+        When a form is submitted or a page is called, Bamboo runs:
+
+            * The pre-processor for the form being submitted 
+            * The validators for each method the form is calling
+            * The processor for the page
+            * The processor for each method described in the form, in
+              order.
+            * The redirector to the next page or the reloader to reload 
+              with errors.
+   
+            Each stage is free to modify the data that Bamboo uses to manage
+            the next stage.

Added: experiments/Bamboo/ex/petstore/lib/PetStore/Model/Cart.pm
==============================================================================

Added: experiments/Bamboo/ex/petstore/lib/PetStore/Model/Product.pm
==============================================================================

Added: experiments/Bamboo/ex/petstore/lib/PetStore/Model/ProductCollection.pm
==============================================================================

Added: experiments/Bamboo/ex/petstore/lib/PetStore/Model/User.pm
==============================================================================

Added: experiments/Bamboo/ex/petstore/lib/PetStore/Model/UserCollection.pm
==============================================================================

Added: experiments/Bamboo/ex/petstore/templates/cart.html
==============================================================================

Added: experiments/Bamboo/ex/petstore/templates/checkout.html
==============================================================================

Added: experiments/Bamboo/ex/petstore/templates/department.html
==============================================================================

Added: experiments/Bamboo/ex/petstore/templates/edit_product.html
==============================================================================
--- (empty file)
+++ experiments/Bamboo/ex/petstore/templates/edit_product.html	Thu Feb 10 00:37:32 2005
@@ -0,0 +1,73 @@
+Model:
+
+Petshop::Product;
+
+sub ClassAccessible {
+
+    id => { read => 1, write => 0 },
+    Name => { read => 1, write => 1, type => varchar, size => 32 },
+    Department { read => 1, write => 1, type => varchar, size => 24 },
+    Discovered { read =>1, write => 1, type => date }
+    
+
+}
+
+sub Update {
+    my %args = ( @_ );
+    # takes key=> value pairs from ClassAccessible...
+    # actually lives in the superclass. 
+    
+}
+
+
+<% form_start( next => 'product_list.html') %>
+<h1>Edit a product: <% form_value(stash('product') => 'Name') %></h1>
+% foreach $attr (method_params(stash('product'), 'Update' ) {
+<% form_method_call_label_param(stash('product'),  'Update',  $attr ) %> 
+<% form_method_call_param(stash('product'), 'Update', $attr ) %> 
+% }
+<% form_submit %>
+<% form_end %>
+
+That should transform to:
+
+pre-controller looks up the item id you're called with and 
+
+sticks stash('product')
+
+
+Renders to:
+
+
+<form method="post" action="product.html">
+    <input type="hidden" name="0-Bamboo::-0-Meta-OnSuccessNextPage" value="product_list.html">
+<h1>Edit a product: Goldfish</h1>
+
+
+<label id="1-PetStore::Product-23-Update-Name">Name</label>
+<input type="text" size=24" name="1-PetStore::Product-23-Update-Name" value="Goldfish"/>
+<label id="1-PetStore::Product-23-Update-Department">Department</label>
+<input type="text" size=24" name="1-PetStore::Product-23-Update-Department" value="Fish"/>
+<label id="1-PetStore::Product-23-Update-Discovered">Name</label>
+<input type="text" size=24" name="1-PetStore::Product-23-Update-Discovered" value="2004-01-01"/>
+
+<input type="submit">
+
+</form>
+
+
+# This example todo:
+
+    figure out how validation could possibly work for Update without having to hardcode update for every module.
+    or do we ditch update for the individual mutators?
+
+    flesh out the model
+
+    a create demo
+
+    a list demo
+
+    an error-condition demo
+
+    a non-input demo
+    

Added: experiments/Bamboo/ex/petstore/templates/home.html
==============================================================================

Added: experiments/Bamboo/ex/petstore/templates/inventory.html
==============================================================================
--- (empty file)
+++ experiments/Bamboo/ex/petstore/templates/inventory.html	Thu Feb 10 00:37:32 2005
@@ -0,0 +1,15 @@
+Current inventory, by departments:
+
+% foreach $department ($CONTROLLER->fetch('departments')) {
+<h1><%$department->name%></h1>
+
+<ul>
+% foreach $item ($department->products) {
+
+<li><% link_to('products.html',  item => $item) %>
+
+</li>
+% }
+
+</ul>
+% }

Added: experiments/Bamboo/lib/Bamboo/View/Widget.pm
==============================================================================
--- (empty file)
+++ experiments/Bamboo/lib/Bamboo/View/Widget.pm	Thu Feb 10 00:37:32 2005
@@ -0,0 +1,20 @@
+use warnings;
+use strict;
+
+package Bamboo::View::Widget;
+
+use Spiffy -base;
+field 'default';
+
+field 'name' => 'unnamed';
+
+sub render {
+    my $self = shift;
+    my @bits = ('input', 'name="'.$self->name .'"');
+
+    push @bits, 'value="'.$self->default.'"' if ($self->default);
+
+
+    return ("<". join(" ", at bits) ." />");
+}
+

Added: experiments/Bamboo/t/10widget.t
==============================================================================
--- (empty file)
+++ experiments/Bamboo/t/10widget.t	Thu Feb 10 00:37:32 2005
@@ -0,0 +1,21 @@
+use Test::More qw/no_plan/;
+
+use_ok('Bamboo::View::Widget');
+
+my $widget = Bamboo::View::Widget->new();
+isa_ok($widget, 'Spiffy');
+isa_ok($widget,'Bamboo::View::Widget');
+
+can_ok($widget, 'name');
+can_ok($widget, 'default');
+can_ok($widget, 'render');
+
+is($widget->name() ,'unnamed');
+
+$widget->name('test');
+
+is($widget->name, 'test');
+
+my $out = $widget->render();
+
+is($out, '<input name="test" />');


More information about the Rt-commit mailing list