Changeset 50 in text-formbuilder


Ignore:
Timestamp:
12/16/04 13:55:34 (20 years ago)
Author:
peichman
Message:

fallthrough to CGI::FormBuilder builtin lists working (again); added a !note directive; discovered bug in parsing of !directive and !note

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r46 r50  
    11Release history for Text::FormBuilder. 
    22 
    3 0.07 
     30.07 - 16 Dec 2004 
    44    * added a create_form exported method to "do the right 
    55      thing" in simple cases 
     
    1010      script around the FormBuilder object 
    1111    * added external documentation of usage examples 
     12    * added a !note directive for inserting arbitrary text 
     13      between lines in the form 
    1214     
    13150.06 - 19 Nov 2004 
  • trunk/lib/Text/FormBuilder.pm

    r46 r50  
    77use vars qw($VERSION @EXPORT); 
    88 
    9 $VERSION = '0.07_03'; 
     9$VERSION = '0.07'; 
    1010@EXPORT = qw(create_form); 
    1111 
     
    3030th.label { font-weight: normal; text-align: right; vertical-align: top; } 
    3131td ul { list-style: none; padding-left: 0; margin-left: 0; } 
     32.note { background: #eee; } 
    3233.sublabel { color: #999; } 
    3334.invalid { background: red; } 
     
    246247    } 
    247248     
     249    # get user-defined lists; can't make this conditional because 
     250    # we need to be able to fall back to CGI::FormBuilder's lists 
     251    # even if the user didn't define any 
     252    my %lists = %{ $self->{form_spec}{lists} || {} }; 
     253     
    248254    # substitute in list names 
    249     if (my %lists = %{ $self->{form_spec}{lists} || {} }) { 
    250         foreach (@{ $self->{form_spec}{fields} }) { 
    251             next unless $$_{list}; 
    252              
    253             $$_{list} =~ s/^\@//;   # strip leading @ from list var name 
    254              
    255             # a hack so we don't get screwy reference errors 
    256             if (exists $lists{$$_{list}}) { 
    257                 my @list; 
    258                 push @list, { %$_ } foreach @{ $lists{$$_{list}} }; 
    259                 $$_{options} = \@list; 
    260             } else { 
    261                 # assume that the list name is a builtin  
    262                 # and let it fall through to CGI::FormBuilder 
    263                 $$_{options} = $$_{list}; 
    264             } 
    265         } continue { 
    266             delete $$_{list}; 
     255    foreach (@{ $self->{form_spec}{fields} }) { 
     256        next unless $$_{list}; 
     257         
     258        $$_{list} =~ s/^\@//;   # strip leading @ from list var name 
     259         
     260        # a hack so we don't get screwy reference errors 
     261        if (exists $lists{$$_{list}}) { 
     262            my @list; 
     263            push @list, { %$_ } foreach @{ $lists{$$_{list}} }; 
     264            $$_{options} = \@list; 
     265        } else { 
     266            # assume that the list name is a builtin  
     267            # and let it fall through to CGI::FormBuilder 
     268            $$_{options} = $$_{list}; 
    267269        } 
     270    } continue { 
     271        delete $$_{list}; 
    268272    } 
    269273     
     
    535539            if ($$line[0] eq 'head') { 
    536540                $OUT .= qq[  <tr><th class="subhead" colspan="2"><h3>$$line[1]</h3></th></tr>\n] 
     541            } elsif ($$line[0] eq 'note') { 
     542                $OUT .= qq[  <tr><td class="note" colspan="2">$$line[1]</td></tr>\n] 
    537543            } elsif ($$line[0] eq 'field') { 
    538544                local $_ = $field{$$line[1]}; 
     
    959965     
    960966    !head ... 
     967     
     968    !note { 
     969        ... 
     970    } 
    961971 
    962972=head2 Directives 
     
    983993=item C<!title> 
    984994 
     995Title of the form. 
     996 
    985997=item C<!author> 
     998 
     999Author of the form. 
    9861000 
    9871001=item C<!description> 
     
    10011015next to each other. 
    10021016 
     1017=item C<!note> 
     1018 
     1019A text note that can be inserted as a row in the form. This is useful for 
     1020special instructions at specific points in a long form. 
     1021 
    10031022=back 
     1023 
     1024B<Known BUG:> If you include an odd number of C<'> or C<"> characters in a 
     1025C<!description> or C<!note>, then that directive will mistakenly be skipped. 
     1026This is a bug casued by me taking a shortcut in the parser C<:-/> 
    10041027 
    10051028=head2 Fields 
     
    11851208=head1 BUGS 
    11861209 
     1210Having a single C<'> or C<"> in a C<!description> or C<!note> directive causes that 
     1211directive to get skipped. This is an issue with the C<perl_codeblock> shortcut in 
     1212Parse::RecDescent. 
     1213 
    11871214Creating two $parsers in the same script causes the second one to get the data 
    11881215from the first one. 
     
    11941221=head1 SEE ALSO 
    11951222 
    1196 L<CGI::FormBuilder> 
     1223L<http://textformbuilder.berlios.de> 
     1224 
     1225L<CGI::FormBuilder>, L<http://formbuilder.org> 
    11971226 
    11981227=head1 THANKS 
  • trunk/lib/Text/FormBuilder/grammar

    r42 r50  
    2525} 
    2626 
    27 form_spec: (list_def | description_def | validate_def | group_def | line)(s) 
     27form_spec: (list_def | description_def | validate_def | group_def | note | line)(s) 
    2828    { 
    2929        # grab the last section, if there is any 
     
    8484    } 
    8585 
     86note: '!note' <perl_codeblock> 
     87    {    
     88        (my $note = $item[2]) =~ s/^{\s*|\s*}$//g; 
     89        push @lines, [ 'note', $note ]; 
     90    } 
     91 
     92 
    8693field_line: <skip:'[ \t]*'> ( field | comment | blank ) "\n" 
    8794line: <skip:'[ \t]*'> ( title | author | pattern_def | section_head | heading | group_field | unknown_directive | field | comment | blank ) "\n" 
Note: See TracChangeset for help on using the changeset viewer.