Changeset 64 in text-formbuilder for trunk


Ignore:
Timestamp:
03/10/05 16:40:27 (20 years ago)
Author:
peichman
Message:

fixed grammar so that outer {} and [] are no longer included in the (bracket_)block values
using bracket_block instead of hardcoded pattern for matching hints in formspec
removed dynamic lists from the grammar
some general code cleanup and tidying, in FormBuilder.pm and grammar
added fb.pl to the MANIFEST
bumped back FB version requirement to 3.0 (Makefile.PL)
test for FB3.02 for using growable fields; warn and ignore if verison isn't high enough

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r57 r64  
    55    * BUGFIX: !note and !description blocks can now 
    66      contain "unbalanced" quotes (fixed the gramamr) 
     7    * removed dynamic lists from the grammar 
    78     
    890.08 - 10 Jan 2005 
  • trunk/MANIFEST

    r53 r64  
    44README 
    55t/Text-FormBuilder.t 
     6bin/fb.pl 
    67lib/Text/FormBuilder.pm 
    78lib/Text/FormBuilder/Examples.pod 
  • trunk/Makefile.PL

    r61 r64  
    55    NAME              => 'Text::FormBuilder', 
    66    VERSION_FROM      => 'lib/Text/FormBuilder.pm', # finds $VERSION 
    7 ##     EXE_FILES         => [ 'bin/fb.pl' ], 
     7    EXE_FILES         => [ 'bin/fb.pl' ], 
    88    PREREQ_PM         => {  
    9                             CGI::FormBuilder => 3.001, 
     9                            CGI::FormBuilder => 3.0, 
    1010                            Parse::RecDescent => 1.94, 
    1111                            Text::Template => 1.44, 
  • trunk/lib/Text/FormBuilder.pm

    r63 r64  
    77use vars qw($VERSION @EXPORT); 
    88 
    9 $VERSION = '0.09_02'; 
     9$VERSION = '0.09'; 
    1010@EXPORT = qw(create_form); 
    1111 
     
    235235     
    236236    # remove extraneous undefined values 
     237    # also check for approriate version of CGI::FormBuilder 
     238    # for some advanced options 
     239    my $FB_version = CGI::FormBuilder->VERSION; 
    237240    for my $field (@{ $self->{form_spec}{fields} }) { 
    238241        defined $$field{$_} or delete $$field{$_} foreach keys %{ $field }; 
    239     } 
     242         
     243        unless ($FB_version >= '3.002') { 
     244            if ($$field{growable}) { 
     245                warn '[' . (caller(0))[3] . "] growable fields not supported by FB $FB_version (requires 3.002)"; 
     246                delete $$field{growable}; 
     247            } 
     248        } 
     249    }     
    240250     
    241251    # remove false $$_{required} params because this messes up things at 
     
    243253    # based on the existance of a 'required' param, not whether it is 
    244254    # true or defined 
     255    # TODO: check if this is still needed 
    245256    $$_{required} or delete $$_{required} foreach @{ $self->{form_spec}{fields} }; 
    246  
     257     
     258    # assign the field names to the sections 
    247259    foreach (@{ $self->{form_spec}{sections} }) { 
    248         #for my $line (grep { $$_[0] eq 'field' } @{ $$_{lines} }) { 
    249260        for my $line (@{ $$_{lines} }) { 
    250261            if ($$line[0] eq 'field') { 
    251262                $$line[1] = $$line[1]{name}; 
    252 ##                 $_ eq 'name' or delete $$line[1]{$_} foreach keys %{ $$line[1] }; 
    253 ##             } elsif ($$line[0] eq 'group') { 
    254 ##                 $$line[1] = [ map { $$_{name} } @{ $$line[1]{group} } ]; 
    255263            } 
    256264        } 
     
    353361    my %module_subs; 
    354362    my $d = Data::Dumper->new([ \%options ], [ '*options' ]); 
    355      
    356     use B::Deparse; 
    357     my $deparse = B::Deparse->new; 
    358 ##      
    359 ##     #TODO: need a workaround/better solution since Data::Dumper doesn't like dumping coderefs 
    360 ##     foreach (@{ $self->{form_spec}{fields} }) { 
    361 ##         if (ref $$_{validate} eq 'CODE') { 
    362 ##             my $body = $deparse->coderef2text($$_{validate}); 
    363 ##             #$d->Seen({ "*_validate_$$_{name}" => $$_{validate} }); 
    364 ##             #$module_subs{$$_{name}} = "sub _validate_$$_{name} $$_{validate}"; 
    365 ##         } 
    366 ##     }     
    367 ##     my $sub_code = join("\n", each %module_subs); 
    368363     
    369364    my $form_options = keys %options > 0 ? $d->Dump : ''; 
     
    10581053given). Growable fields have a button that allows the user to add a 
    10591054copy of the field input. Currently, this only works for C<text> and 
    1060 C<file> fields. Growable fields also require JavaScript to function 
    1061 correctly. 
     1055C<file> fields, and you must have L<CGI::FormBuilder> 3.02 or higher. 
     1056Growable fields also require JavaScript to function correctly. 
    10621057 
    10631058    # you can have as many people as you like 
     
    10881083     
    10891084    month:select@MONTHS 
    1090  
    1091 There is another form of the C<!list> directive: the dynamic list: 
    1092  
    1093     !list RANDOM &{ map { rand } (0..5) } 
    1094  
    1095 The code inside the C<&{ ... }> is C<eval>ed by C<build>, and the results 
    1096 are stuffed into the list. The C<eval>ed code can either return a simple 
    1097 list, as the example does, or the fancier C<< ( { value1 => 'Description 1'}, 
    1098 { value2 => 'Description 2}, ... ) >> form. 
    1099  
    1100 I<B<NOTE:> This feature of the language may go away unless I find a compelling 
    1101 reason for it in the next few versions. What I really wanted was lists that 
    1102 were filled in at run-time (e.g. from a database), and that can be done easily 
    1103 enough with the CGI::FormBuilder object directly.> 
    11041085 
    11051086If you want to have a single checkbox (e.g. for a field that says ``I want to 
     
    11811162Document the commmand line tool 
    11821163 
     1164Document use of the parser as a standalone module 
     1165 
    11831166Allow renaming of the submit button; allow renaming and inclusion of a  
    11841167reset button 
  • trunk/lib/Text/FormBuilder/grammar

    r63 r64  
    6060dynamic_list: '&' <perl_codeblock> 
    6161    { 
    62         my @results = (eval $item[2]); 
    63         if (ref $results[0] eq 'HASH') { 
    64             @options = @results; 
    65         } else {     
    66             @options = map { { $_ => $_ } } @results; 
    67         } 
     62        warn "[Text::FormBuilder] Dynamic lists have been removed from the formspec grammar"; 
    6863    } 
    6964 
    7065description_def: '!description' block 
    71     { warn "[Text::FormBuilder] Description redefined at input text line $thisline\n" if defined $description; 
    72      
    73     $description = $item[2]; 
    74     $description =~ s/^{\s*|\s*}$//g; 
     66    { 
     67        warn "[Text::FormBuilder] Description redefined at input text line $thisline\n" if defined $description; 
     68        $description = $item{block}; 
    7569    } 
    7670 
     
    8579    } 
    8680 
    87 note: '!note' block 
    88     {    
    89         (my $note = $item[2]) =~ s/^{\s*|\s*}$//g; 
    90         push @lines, [ 'note', $note ]; 
    91     } 
     81note: '!note' block  { push @lines, [ 'note', $item{block} ]; } 
     82 
     83 
     84#TODO: allow \ escape for [] {} in these blocks 
    9285 
    9386# curly-brace delimited block, that can contain properly 
    94 # nested curly brackets, along with any other characters 
    95 # return with the '{...}' so that nested blocks get the 
    96 # brackets treated as literals 
    97 block: '{' <skip:''> block_content(s) '}' 
    98     { 
    99         '{' . join('', @{ $item[3] }) . '}'; 
    100     } 
    101  
    102 block_content: /[^\{\}]+?/ | block 
    103  
    104  
     87# nested curly braces, along with any other characters 
     88# inner blocks return with the '{...}' so that nested 
     89# blocks get the braces treated as literals 
     90block: '{' <skip:''> block_content(s) '}' { join('', @{ $item[3] }) } 
     91inner_block: '{' <skip:''> block_content(s) '}'  { '{' . join('', @{ $item[3] }) . '}' } 
     92block_content: /[^\{\}]+?/ | inner_block 
     93 
     94# square brace delimited block, that can contain properly 
     95# nested square brackets, along with any other characters 
     96# inner bracket blocks return with the '[...]' so that nested 
     97# blocks get the braces treated as literals 
     98bracket_block: '[' <skip:''> bracket_block_content(s) ']' { join('', @{ $item[3] }) } 
     99inner_bracket_block: '[' <skip:''> bracket_block_content(s) ']' { '[' . join('', @{ $item[3] }) . ']'; } 
     100bracket_block_content: /[^\[\]]+?/ | inner_bracket_block 
     101 
     102 
     103# field lines are the subset of lines that are allowed in a !group directive 
    105104field_line: <skip:'[ \t]*'> ( field | comment | blank ) "\n" 
     105 
    106106line: <skip:'[ \t]*'> ( title | author | pattern_def | section_head | heading | group_field | field_group | unknown_directive | field | comment | blank ) "\n" 
    107107 
     
    159159group_type: ':' var_name 
    160160 
     161# this is the real heart of the thing 
    161162field: name field_size(?) growable(?) label(?) hint(?) type(?) default(?) option_list(?) validate(?) 
    162163    { 
     
    217218label: '|' (simple_multiword | quoted_string) { $item[2] } 
    218219 
    219 hint: '[' /[^\]]+/ ']'    { $item[2] } 
     220hint: bracket_block 
    220221 
    221222type: ':' builtin_field 
     
    245246value: identifier 
    246247 
    247 display_text: brace_block 
    248     { (my $text = $item[1]) =~ s/^\[\s*|\s*\]$//g; $text } 
    249  
    250 # square brace delimited block, that can contain properly 
    251 # nested square braces, along with any other characters 
    252 # return with the '[...]' so that nested blocks get the 
    253 # braces treated as literals 
    254 brace_block: '[' <skip:''> brace_block_content(s) ']' 
    255     { 
    256         '[' . join('', @{ $item[3] }) . ']'; 
    257     } 
    258 brace_block_content: /[^\[\]]+?/ | brace_block 
    259  
    260  
    261 validate: '//' (optional_pattern | required_pattern)    { $item[2] } 
    262  
    263 optional_pattern: /[A-Z_]+/ '?' { $required = 0; $item[1] } 
    264  
    265 required_pattern: /[A-Z_]+/ { $required = 1; $item[1] } 
     248display_text: bracket_block 
     249 
     250 
     251validate: '//' (optional_pattern | required_pattern) 
     252 
     253optional_pattern: var_name '?'  { $required = 0; $item[1] } 
     254 
     255required_pattern: var_name { $required = 1; $item[1] } 
    266256 
    267257comment: '#' /.*/ 
Note: See TracChangeset for help on using the changeset viewer.