[Jifty-commit] r6707 - in jifty/trunk: lib/Jifty/Plugin lib/Jifty/Plugin/Config lib/Jifty/Plugin/Config/Action share/plugins/Jifty/Plugin/Config share/plugins/Jifty/Plugin/Config/web/templates share/plugins/Jifty/Plugin/Config/web/templates/__jifty share/plugins/Jifty/Plugin/Config/web/templates/__jifty/config

Jifty commits jifty-commit at lists.jifty.org
Fri Mar 27 04:14:13 EDT 2009


Author: sunnavy
Date: Fri Mar 27 04:14:11 2009
New Revision: 6707

Added:
   jifty/trunk/lib/Jifty/Plugin/Config/
   jifty/trunk/lib/Jifty/Plugin/Config.pm
   jifty/trunk/lib/Jifty/Plugin/Config/Action/
   jifty/trunk/lib/Jifty/Plugin/Config/Action/Config.pm
   jifty/trunk/lib/Jifty/Plugin/Config/Dispatcher.pm
   jifty/trunk/share/plugins/Jifty/Plugin/Config/
   jifty/trunk/share/plugins/Jifty/Plugin/Config/web/
   jifty/trunk/share/plugins/Jifty/Plugin/Config/web/templates/
   jifty/trunk/share/plugins/Jifty/Plugin/Config/web/templates/__jifty/
   jifty/trunk/share/plugins/Jifty/Plugin/Config/web/templates/__jifty/config/
   jifty/trunk/share/plugins/Jifty/Plugin/Config/web/templates/__jifty/config/index.html

Log:
added config plugin to help beginners configure their apps, currently only database related stuff is in

Added: jifty/trunk/lib/Jifty/Plugin/Config.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Config.pm	Fri Mar 27 04:14:11 2009
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Config;
+use base qw/Jifty::Plugin/;
+
+=head2 NAME
+
+Jifty::Plugin::Config - Add configuration editor
+
+=head2  DESCRIPTION
+
+This plugin provides a basic configuration editor for your application.
+Basically, it tries to help you update the most important items in Jifty's config
+file, so you don't need to edit the config file directly.
+
+the updated config file will be saved in file $EVN{JIFTY_SITE_CONFIG} or
+etc/site_config.yml
+
+This plugin is designed mostly for beginners ;)
+
+=cut
+
+1;
+

Added: jifty/trunk/lib/Jifty/Plugin/Config/Action/Config.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Config/Action/Config.pm	Fri Mar 27 04:14:11 2009
@@ -0,0 +1,105 @@
+package Jifty::Plugin::Config::Action::Config;
+use strict;
+use warnings;
+
+use base qw/Jifty::Action/;
+use UNIVERSAL::require;
+use Jifty::YAML;
+use File::Spec;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+    param
+      database_type => label is 'Database type',    # loc
+      render as 'Select', available are defer {
+        my %map = (
+            mysql  => 'MySQL',                      
+            Pg     => 'PostgreSQL',                 
+            SQLite => 'SQLite',                     
+            Oracle => 'Oracle',                     
+        );
+
+        for ( keys %map ) {
+            my $m = 'DBD::' . $_;
+            delete $map{$_} unless $m->require;
+        }
+
+        [ map { { display => $map{$_}, value => $_ } } keys %map ];
+      },
+      default is defer { 
+          Jifty->config->framework('Database')->{'Driver'}
+      };
+    param
+      database_host => label is 'Database host',    # loc
+      hints is
+      "The domain name of your database server (like 'db.example.com')",    
+      default is defer {
+          Jifty->config->framework('Database')->{'Host'}
+      };
+
+    param
+      database_name => label is 'Database name',                            
+      default is defer {
+          Jifty->config->framework('Database')->{'Database'}
+      };
+    param
+      database_user => label is 'Database username for RT',                 
+      hints is
+'RT will connect to the database using this user.'
+      ,                                                                     
+      default is defer { 
+          Jifty->config->framework('Database')->{'User'}
+      };
+
+    param
+      database_password => label is 'Database password for RT',             
+      render as 'Password',
+      hints is 'The password RT should use to connect to the database.';
+
+};
+
+=head2 take_action
+
+=cut
+
+my %database_map = (
+    name => 'Database',
+    type => 'Driver',
+);
+
+sub take_action {
+    my $self = shift;
+
+    my $stash = Jifty->config->stash;
+    for my $arg ( $self->argument_names ) {
+        if ( $self->has_argument($arg) ) {
+            if ( $arg =~ /database_(\w+)/ ) {
+                my $key = $database_map{$1} || ucfirst $1;
+                my $database = $stash->{'framework'}{'Database'};
+                if ( $database->{$key} ne $self->argument_value($arg) ) {
+                    $database->{$key} = $self->argument_value($arg);
+                }
+            }
+        }
+    }
+
+    Jifty::YAML::DumpFile( $ENV{'JIFTY_SITE_CONFIG'}
+          || Jifty::Util->app_root . '/etc/site_config.yml', $stash );
+    Jifty->config->load;
+    $self->report_success unless $self->result->failure;
+
+    return 1;
+}
+
+=head2 report_success
+
+=cut
+
+sub report_success {
+    my $self = shift;
+
+    # Your success message here
+    $self->result->message('Success');
+}
+
+1;

Added: jifty/trunk/lib/Jifty/Plugin/Config/Dispatcher.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Config/Dispatcher.pm	Fri Mar 27 04:14:11 2009
@@ -0,0 +1,43 @@
+use warnings;
+use strict;
+
+package Jifty::Plugin::Config::Dispatcher;
+
+=head1 NAME
+
+Jifty::Plugin::Config::Dispatcher - dispatcher of the Config plugin
+
+=head1 DESCRIPTION
+
+Adds dispatching rules required for the Config plugin.
+
+=cut
+
+use Jifty::Dispatcher -base;
+
+=head1 RULES
+
+=head2 on '**'
+
+Adds 'Configuration' item to the top navigation
+
+=cut
+
+on '**' => run {
+    my $top = Jifty->web->navigation;
+
+    # for now leave check here, but we want Config to be
+    # real plugin someday
+    $top->child(
+        Configuration => url => "/__jifty/config/",
+        label         => _('Configuration'),
+        sort_order    => 990,
+    );
+    return ();
+};
+
+before '*' => run {
+    Jifty->api->allow('Jifty::Plugin::Config::Action::Config');
+};
+
+1;

Added: jifty/trunk/share/plugins/Jifty/Plugin/Config/web/templates/__jifty/config/index.html
==============================================================================
--- (empty file)
+++ jifty/trunk/share/plugins/Jifty/Plugin/Config/web/templates/__jifty/config/index.html	Fri Mar 27 04:14:11 2009
@@ -0,0 +1,20 @@
+<&| /_elements/wrapper, title => _('Jifty Configuration') &>
+
+<h1><% _('Configuration') %></h1>
+
+<% Jifty->web->form->start %>
+% for my $field ( @fields ) {
+<% $action->form_field($field) %>
+% }
+<% Jifty->web->form->submit( label => 'Save' ) %>
+<% Jifty->web->form->end %>
+
+</&>
+
+<%init>
+my $action = Jifty->web->new_action( class =>
+'Jifty::Plugin::Config::Action::Config' );
+my @fields = qw/database_type database_name database_host 
+database_user database_password/;
+</%init>
+


More information about the Jifty-commit mailing list