[Jifty-commit] r3847 - in jifty/branches/virtual-models: . lib/Jifty/Action lib/Jifty/Plugin lib/Jifty/View/Declare t t/TestApp-Plugin-Chart/t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Aug 10 17:00:55 EDT 2007


Author: sterling
Date: Fri Aug 10 17:00:54 2007
New Revision: 3847

Modified:
   jifty/branches/virtual-models/   (props changed)
   jifty/branches/virtual-models/Makefile.PL
   jifty/branches/virtual-models/lib/Jifty/Action/Record.pm
   jifty/branches/virtual-models/lib/Jifty/Plugin/Chart.pm
   jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm
   jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/chart_img_behaviour.js
   jifty/branches/virtual-models/t/13-sessions.t
   jifty/branches/virtual-models/t/TestApp-Plugin-Chart/t/chart.t
   jifty/branches/virtual-models/t/TestApp-Plugin-Chart/t/gd_graph.t

Log:
 r8512 at riddle:  andrew | 2007-08-10 16:00:10 -0500
 Merge down from trunk.
  r8486 at riddle:  andrew | 2007-08-10 08:57:04 -0500
  Removing extra comma from JavaScript list.
  r8487 at riddle:  andrew | 2007-08-10 08:57:20 -0500
   r8480 at riddle (orig r3837):  agentz | 2007-08-10 04:09:35 -0500
    r1254 at agentz-office:  agentz | 2007-08-10 17:08:14 +0800
    Makefile.PL - do NOT skip any tests under t/ unintentionally ;)
   
   r8481 at riddle (orig r3838):  clkao | 2007-08-10 04:27:34 -0500
   Correct a crud component path.
   r8482 at riddle (orig r3839):  clkao | 2007-08-10 04:42:40 -0500
   In action argument creation from model, do not assume refers_to
   always want a select based on id which we might not be referring to.
   Allow user to override render_as for refers_to columns.
   
  
  r8491 at riddle:  andrew | 2007-08-10 09:18:27 -0500
  Chart plugin configuration updates:
   * Deprecating the renderer option.
   * Adding the DefaultRenderer option to replace renderer.
   * Adding the PreloadRenderers option to allow additional renderers to be preloaded.
   * Updated the documentation.
   * Made sure that the configuration is always passed to the renderer constructor, even if they are loaded late.
  r8499 at riddle:  andrew | 2007-08-10 11:26:05 -0500
  Fixing the chart plugin tests to match up with changes that have happened to the API since they were written.
  r8501 at riddle:  andrew | 2007-08-10 11:26:40 -0500
   r8500 at riddle (orig r3844):  sartak | 2007-08-10 11:20:53 -0500
    r30163 at caladan:  sartak | 2007-08-10 12:20:01 -0400
    todo-ify failing tests in t/13-sessions.t
   
  
  r8506 at riddle:  andrew | 2007-08-10 15:49:46 -0500
  Fix to a JavaScript bug performing the rerendering of IMG graphs.
 


Modified: jifty/branches/virtual-models/Makefile.PL
==============================================================================
--- jifty/branches/virtual-models/Makefile.PL	(original)
+++ jifty/branches/virtual-models/Makefile.PL	Fri Aug 10 17:00:54 2007
@@ -173,7 +173,7 @@
 install_share;
 
 # Test all of our sub-dist tests too
-tests('t/*.t t/*/t/*.t');
+tests('t/*.t t/*/*.t t/*/*/*.t t/*/*/*/*.t');
 
 WriteAll;
 

Modified: jifty/branches/virtual-models/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Action/Record.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Action/Record.pm	Fri Aug 10 17:00:54 2007
@@ -196,7 +196,10 @@
 
             elsif ( defined (my $refers_to = $column->refers_to) ) {
                 if ( UNIVERSAL::isa( $refers_to, 'Jifty::Record' ) ) {
+                    $info->{render_as} = $render_as || 'Select';
+                }
 
+                if ( $info->{render_as} eq 'Select' ) {
                     my $collection = Jifty::Collection->new(
                         record_class => $refers_to,
                         current_user => $self->record->current_user
@@ -205,14 +208,13 @@
 
                     my $method = $refers_to->_brief_description();
 
+                    # FIXME: we should get value_from with the actualy refered by key
                     $info->{valid_values} = [
                         {   display_from => $refers_to->can($method) ? $method : "id",
                             value_from => 'id',
                             collection => $collection
                         }
                     ];
-
-                    $info->{render_as} = 'Select';
                 } else {
                     # No need to generate arguments for
                     # JDBI::Collections, as we can't do anything

Modified: jifty/branches/virtual-models/lib/Jifty/Plugin/Chart.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Plugin/Chart.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Plugin/Chart.pm	Fri Aug 10 17:00:54 2007
@@ -7,7 +7,7 @@
 use Jifty::Plugin::Chart::Web;
 use Scalar::Util qw/ blessed /;
 
-__PACKAGE__->mk_accessors(qw/ renderer renderers /);
+__PACKAGE__->mk_accessors(qw/ renderer renderers plugin_args /);
 
 =head1 NAME
 
@@ -49,13 +49,29 @@
 
 =head1 CONFIGURATION
 
-The plugin takes a single configuration option called C<renderer>. This may be set to a chart renderer class, which is just an implementation of L<Jifty::Plugin::Chart::Renderer>. The default, L<Jifty::Plugin::Chart::Renderer::Chart>, uses L<Chart> to render charts as PNG files which are then included in your pages for you.
-
 Here is an example configuration for F<config.yml>:
 
   Plugins:
     - Chart:
-        renderer: Chart
+        DefaultRenderer: PlotKit
+        PreloadRenderers:
+         - XMLSWF
+         - SimpleBars
+         - App::Renderer::Custom
+
+The available options are:
+
+=over
+
+=item DefaultRenderer
+
+This is the name of the class to use as the default renderer. L<Jifty::Plugin::Chart::Renderer::Chart> is the current default, but that could change in the future. It's recommended that you set this to your preference.
+
+=item PreloadRenderers
+
+This is a list of other render classes to load during initialization. If they are not loaded during initialization some renderers may not work correctly the first time they are run because they are not able to inform Jifty of the CSS or JS files they need before that part of the page is already rendered. If you use the "renderer" option of L<Jifty::Plugin::Chart::Web/chart>, then you should make sure any value you use is set here in the configuration to make sure it works properly.
+
+=back
 
 =head1 METHODS
 
@@ -68,15 +84,35 @@
 sub init {
     my $self = shift;
     my %args = (
-        renderer => 'Chart',
+        DefaultRenderer => 'Chart',
         @_,
     );
 
+    # Save the arguments for use in init_renderer() later
+    $self->plugin_args( \%args );
+
+    # Deprecating the old form
+    if (defined $args{renderer}) {
+        warn 'DEPRECATED: renderer argument to Chart plugin is deprecated.'
+            .' Use DefaultRenderer instead.';
+        $args{DefaultRenderer} = delete $args{renderer};
+    }
+
     # Create the empty renderers list
     $self->renderers({});
 
+    # Pre-load any renderers they plan to use
+    if (defined $args{PreloadRenderers}) {
+        $args{PreloadRenderers} = [ $args{PreloadRenderers} ]
+            unless ref $args{PreloadRenderers};
+
+        for my $renderer (@{ $args{PreloadRenderers} }) {
+            $self->init_renderer( $renderer );
+        }
+    }
+
     # Load the default renderer
-    $self->renderer( $self->init_renderer( $args{renderer}, %args ) );
+    $self->renderer( $self->init_renderer( $args{DefaultRenderer}, %args ) );
 
     push @Jifty::Web::ISA, 'Jifty::Plugin::Chart::Web';
 }
@@ -112,7 +148,7 @@
         or warn $@;
 
     # Initialize the renderer
-    $renderer = $renderer_class->new( @_ );
+    $renderer = $renderer_class->new( %{ $self->plugin_args } );
 
     # Remember it
     $self->renderers->{ $renderer_class } = $renderer;

Modified: jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm	Fri Aug 10 17:00:54 2007
@@ -432,7 +432,7 @@
     my $item_path   = shift;
     my $object_type = $self->object_type;
     if ( $collection->pager->total_entries == 0 ) {
-        show('no_items_found');
+        show('./no_items_found');
     }
 
     div {

Modified: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/chart_img_behaviour.js
==============================================================================
--- jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/chart_img_behaviour.js	(original)
+++ jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/chart_img_behaviour.js	Fri Aug 10 17:00:54 2007
@@ -26,8 +26,8 @@
         query['width']  = dim.width + 'px';
         query['height'] = dim.height + 'px';
 
-        url = path + '?' + query.toQueryString();
+        url = path + '?' + $H(query).toQueryString();
 
         e.src = url;
-    },
+    }
 });

Modified: jifty/branches/virtual-models/t/13-sessions.t
==============================================================================
--- jifty/branches/virtual-models/t/13-sessions.t	(original)
+++ jifty/branches/virtual-models/t/13-sessions.t	Fri Aug 10 17:00:54 2007
@@ -7,7 +7,7 @@
 
 =cut
 
-use Jifty::Test tests => 25;
+use Jifty::Test tests => 19;
 
 my ($first_id, $third_id);
 
@@ -63,29 +63,35 @@
 }
 
 # test null char
+TODO:
 {
-    my $session = Jifty::Web::Session->new();
-    $session->load_by_kv(user => "first\0sneaky!");
-    ok($session->id, "got a session");
-    isnt($session->id, $first_id, "'first\\0sneaky!' different from 'first'");
-    is($session->get('hello'), undef, "first\\0sneaky has no session data yet");
-}
-
-{
-    my $session = Jifty::Web::Session->new();
-    $session->load_by_kv(user => "\0third");
-    ok($session->id, "got a session");
-    $third_id = $session->id;
-
-    $session->set(a => 'apple');
-}
-
-{
-    my $session = Jifty::Web::Session->new();
-    $session->load_by_kv(user => "\0third");
-    ok($session->id, "got a session");
-    is($session->id, $third_id, "same session as before");
-
-    is($session->get('a'), 'apple', "'set', destroy, 'get' works");
+    local $TODO = "something doesn't like \\0, and it generates a lot of warnings, so the tests here are commented out instead of todo'd";
+    ok(0, $TODO);
 }
 
+#{
+#    my $session = Jifty::Web::Session->new();
+#    $session->load_by_kv(user => "first\0sneaky!");
+#    ok($session->id, "got a session");
+#    isnt($session->id, $first_id, "'first\\0sneaky!' different from 'first'");
+#    is($session->get('hello'), undef, "first\\0sneaky has no session data yet");
+#}
+#
+#{
+#    my $session = Jifty::Web::Session->new();
+#    $session->load_by_kv(user => "\0third");
+#    ok($session->id, "got a session");
+#    $third_id = $session->id;
+#
+#    $session->set(a => 'apple');
+#}
+#
+#{
+#    my $session = Jifty::Web::Session->new();
+#    $session->load_by_kv(user => "\0third");
+#    ok($session->id, "got a session");
+#    is($session->id, $third_id, "same session as before");
+#
+#    is($session->get('a'), 'apple', "'set', destroy, 'get' works");
+#}
+#

Modified: jifty/branches/virtual-models/t/TestApp-Plugin-Chart/t/chart.t
==============================================================================
--- jifty/branches/virtual-models/t/TestApp-Plugin-Chart/t/chart.t	(original)
+++ jifty/branches/virtual-models/t/TestApp-Plugin-Chart/t/chart.t	Fri Aug 10 17:00:54 2007
@@ -22,8 +22,10 @@
 
 use Jifty::Plugin::Chart::Renderer::Chart;
 
-(Jifty->find_plugin('Jifty::Plugin::Chart'))[0]
-    ->renderer('Jifty::Plugin::Chart::Renderer::Chart');
+my $chart_plugin = (Jifty->find_plugin('Jifty::Plugin::Chart'))[0];
+$chart_plugin->renderer(
+    $chart_plugin->init_renderer('Jifty::Plugin::Chart::Renderer::Chart')
+);
 
 my $server = Jifty::Test->make_server;
 ok($server, 'got a server');

Modified: jifty/branches/virtual-models/t/TestApp-Plugin-Chart/t/gd_graph.t
==============================================================================
--- jifty/branches/virtual-models/t/TestApp-Plugin-Chart/t/gd_graph.t	(original)
+++ jifty/branches/virtual-models/t/TestApp-Plugin-Chart/t/gd_graph.t	Fri Aug 10 17:00:54 2007
@@ -22,8 +22,10 @@
 
 use Jifty::Plugin::Chart::Renderer::GD::Graph;
 
-(Jifty->find_plugin('Jifty::Plugin::Chart'))[0]
-    ->renderer('Jifty::Plugin::Chart::Renderer::GD::Graph');
+my $chart_plugin = (Jifty->find_plugin('Jifty::Plugin::Chart'))[0];
+$chart_plugin->renderer(
+    $chart_plugin->init_renderer('Jifty::Plugin::Chart::Renderer::GD::Graph')
+);
 
 my $server = Jifty::Test->make_server;
 ok($server, 'got a server');


More information about the Jifty-commit mailing list