[Bps-public-commit] Prophet - A disconnected, replicated p2p database branch, master, updated. 01f641f375286a18a95f17032453461593b58f32

spang at bestpractical.com spang at bestpractical.com
Mon Jan 19 10:46:44 EST 2009


The branch, master has been updated
       via  01f641f375286a18a95f17032453461593b58f32 (commit)
       via  90f0cd6b194298e633442280951d5e9b2aeda746 (commit)
       via  e2de995a37a3226d1e2abe7c810bc4c7ff4162a4 (commit)
       via  f3349acce22821ec1cfd25d30b4c972f6e070942 (commit)
      from  060cf539aa2f1707b2bf6673c8dc3dc051cd3c72 (commit)

Summary of changes:
 .gitignore                           |    1 +
 lib/Prophet/CLI/TextEditorCommand.pm |   75 ++++++++++++++++++++++++++++++++--
 lib/Prophet/Record.pm                |    2 +-
 3 files changed, 73 insertions(+), 5 deletions(-)

- Log -----------------------------------------------------------------
commit f3349acce22821ec1cfd25d30b4c972f6e070942
Author: Christine Spang <spang at bestpractical.com>
Date:   Mon Jan 19 14:23:51 2009 +0200

    add .prove to gitignore

diff --git a/.gitignore b/.gitignore
index f97dba5..23a437f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ blib/
 pm_to_blib
 Makefile*
 *~
+.prove

commit e2de995a37a3226d1e2abe7c810bc4c7ff4162a4
Author: Christine Spang <spang at bestpractical.com>
Date:   Mon Jan 19 14:47:21 2009 +0200

    clean up user interaction when templates have errors

diff --git a/lib/Prophet/CLI/TextEditorCommand.pm b/lib/Prophet/CLI/TextEditorCommand.pm
index abcc2fa..16334fd 100644
--- a/lib/Prophet/CLI/TextEditorCommand.pm
+++ b/lib/Prophet/CLI/TextEditorCommand.pm
@@ -4,6 +4,14 @@ use Params::Validate qw/validate/;
 
 requires 'process_template';
 
+=head2 try_to_edit template => \$tmpl [, record => $record ]
+
+Edits the given template if possible. Passes the updated
+template in to process_template (errors in the updated template
+must be handled there, not here).
+
+=cut
+
 sub try_to_edit {
     my $self = shift;
     my %args = validate( @_,
@@ -26,15 +34,29 @@ sub try_to_edit {
     );
 }
 
+=head2 handle_template_errors error => 'foo', template_ref => \$tmpl_str, bad_template => 'bar', rtype => 'ticket'
+
+Should be called in C<process_template> if errors (usually validation ones)
+occur while processing a record template. This method prompts the user to
+re-edit and updates the template given by C<template_ref> to contain the bad
+template (given by the arg C<bad_template> prefixed with the error messages
+given in the C<error> arg.
+
+Other arguments are: C<rtype>: the type of the record being edited. All
+arguments are required.
+
+=cut
+
 sub handle_template_errors {
     my $self = shift;
-    my %args = validate( @_, { error => 1, template_ref => 1, bad_template => 1 } );
+    my %args = validate( @_, { error => 1, template_ref => 1,
+                               bad_template => 1, rtype => 1 } );
 
-    $self->prompt_Yn("Want to return back to editing?") || die "Aborted.\n";
+    $self->prompt_Yn("Whoops, an error occurred processing your $args{rtype}.\nTry editing again? (Errors will be shown.)") || die "Aborted.\n";
 
     ${ $args{'template_ref'} }
-        = "=== Your template contained errors ====\n\n"
-        . $args{error} . "\n\n"
+        = "=== Errors in this $args{rtype} ====\n\n"
+        . $args{error} . "\n"
         . $args{bad_template};
     return 0;
 }

commit 90f0cd6b194298e633442280951d5e9b2aeda746
Author: Christine Spang <spang at bestpractical.com>
Date:   Mon Jan 19 17:37:24 2009 +0200

    we want a newline between multiple errors

diff --git a/lib/Prophet/Record.pm b/lib/Prophet/Record.pm
index edce48a..eaacd3d 100644
--- a/lib/Prophet/Record.pm
+++ b/lib/Prophet/Record.pm
@@ -593,7 +593,7 @@ sub validate_prop_from_recommended_values {
         return 1 if scalar grep { $args->{props}{$prop} eq $_ } @options;
 
         $args->{errors}{$prop}
-            = "'" . $args->{props}->{$prop} . "' is not a valid $prop";
+            = "'" . $args->{props}->{$prop} . "' is not a valid $prop\n";
         return 0;
     }
     return 1;

commit 01f641f375286a18a95f17032453461593b58f32
Author: Christine Spang <spang at bestpractical.com>
Date:   Mon Jan 19 17:39:29 2009 +0200

    move some non-sd-specific methods dealing with templates into Prophet::CLI::TextEditorCommand

diff --git a/lib/Prophet/CLI/TextEditorCommand.pm b/lib/Prophet/CLI/TextEditorCommand.pm
index 16334fd..20d72c2 100644
--- a/lib/Prophet/CLI/TextEditorCommand.pm
+++ b/lib/Prophet/CLI/TextEditorCommand.pm
@@ -4,6 +4,51 @@ use Params::Validate qw/validate/;
 
 requires 'process_template';
 
+=head2 separator_pattern
+
+A pattern that will match on lines that count as section separators
+in record templates. Separator string text is remembered as C<$1>.
+
+=cut
+
+use constant separator_pattern => qr/^=== (.*) ===$/;
+
+=head2 comment_pattern
+
+A pattern that will match on lines that count as comments in
+record templates.
+
+=cut
+
+use constant comment_pattern => qr/^\s*#/;
+
+=head2 build_separator $text
+
+Takes a string and returns it in separator form. A separator is a
+line of text that denotes a section in a template.
+
+=cut
+
+sub build_separator {
+    my $self = shift;
+    my $text = shift;
+
+    return "=== $text ===";
+}
+
+=head2 build_template_section header => '=== foo ===' [, data => 'bar']
+
+Takes a header text string and (optionally) a data string and formats
+them into a template section.
+
+=cut
+
+sub build_template_section {
+    my $self = shift;
+    my %args = validate (@_, { header => 1, data => 0 });
+    return $self->build_separator($args{'header'}) ."\n\n". ( $args{data} || '');
+}
+
 =head2 try_to_edit template => \$tmpl [, record => $record ]
 
 Edits the given template if possible. Passes the updated
@@ -55,7 +100,7 @@ sub handle_template_errors {
     $self->prompt_Yn("Whoops, an error occurred processing your $args{rtype}.\nTry editing again? (Errors will be shown.)") || die "Aborted.\n";
 
     ${ $args{'template_ref'} }
-        = "=== Errors in this $args{rtype} ====\n\n"
+        = "=== errors in this $args{rtype} ====\n\n"
         . $args{error} . "\n"
         . $args{bad_template};
     return 0;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list