Changeset 23 in text-formbuilder
- Timestamp:
- 11/15/04 16:58:41 (20 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changes
r19 r23 1 1 Release history for Text::FormBuilder. 2 2 3 0.06 4 * marked Parse::RecDescent as an explicit dependency 5 * added a single-quoted string to the grammar that 6 can be used in the labels and default values to include 7 characters in [^\w\t ] 8 * generated code leaves out overwrriten options 9 * allow option lists to have simple multiword and quoted 10 string values 11 3 12 0.05 - 9 Nov 2004 4 13 * First CPAN release -
trunk/Makefile.PL
r19 r23 1 #use 5.008004;2 1 use ExtUtils::MakeMaker; 3 2 # See lib/ExtUtils/MakeMaker.pm for details of how to influence … … 9 8 PREREQ_PM => { 10 9 CGI::FormBuilder => 2.13, 10 Parse::RecDescent => 1.94, 11 11 Text::Template => 1.44, 12 12 }, # e.g., Module::Name => 1.1 -
trunk/lib/Text/FormBuilder.pm
r21 r23 11 11 use Text::FormBuilder::Parser; 12 12 use CGI::FormBuilder; 13 14 # the default options passed to CGI::FormBuilder->new 15 my %DEFAULT_OPTIONS = ( 16 method => 'GET', 17 javascript => 0, 18 keepextras => 1, 19 ); 13 20 14 21 sub new { … … 133 140 134 141 135 136 137 138 # TODO: use lines instead of fields139 # TODO: change template to do groups140 141 142 # TODO: configurable threshold for this 142 143 foreach (@{ $self->{form_spec}{fields} }) { … … 144 145 } 145 146 147 148 149 146 150 $self->{form} = CGI::FormBuilder->new( 147 method => 'GET', 148 javascript => 0, 149 keepextras => 1, 151 %DEFAULT_OPTIONS, 150 152 title => $self->{form_spec}{title}, 151 #fields => [ map { $$_{name} } @{ $self->{form_spec}{fields} } ],152 153 template => { 153 154 type => 'Text', … … 171 172 $self->{built} = 1; 172 173 173 # TEMP: dump @lines structure174 use YAML;175 warn YAML::Dump($self->{form_spec}->{lines}), "\n";176 177 174 return $self; 178 175 } … … 215 212 216 213 my $headings = Data::Dumper->Dump([$self->{form_spec}{headings}],['headings']); 214 my $lines = Data::Dumper->Dump([$self->{form_spec}{lines}],['lines']); 217 215 my $fields = Data::Dumper->Dump([ [ map { $$_{name} } @{ $self->{form_spec}{fields} } ] ],['fields']); 218 216 219 my %options = %{ $self->{build_options} }; 217 my %options = ( 218 %DEFAULT_OPTIONS, 219 title => $self->{form_spec}{title}, 220 template => { 221 type => 'Text', 222 engine => { 223 TYPE => 'STRING', 224 SOURCE => $self->{build_options}{form_only} ? $self->_form_template : $self->_template, 225 DELIMITERS => [ qw(<% %>) ], 226 }, 227 data => { 228 lines => $self->{form_spec}{lines}, 229 headings => $self->{form_spec}{headings}, 230 author => $self->{form_spec}{author}, 231 description => $self->{form_spec}{description}, 232 }, 233 }, 234 %{ $self->{build_options} }, 235 ); 236 220 237 my $source = $options{form_only} ? $self->_form_template : $self->_template; 221 238 222 239 delete $options{form_only}; 223 240 224 my $form_options = keys %options > 0 ? Data::Dumper->Dump([ $self->{build_options}],['*options']) : '';241 my $form_options = keys %options > 0 ? Data::Dumper->Dump([\%options],['*options']) : ''; 225 242 226 243 my $field_setup = join( … … 239 256 my \$cgi = shift; 240 257 my \$cgi_form = CGI::FormBuilder->new( 241 method => 'GET',242 258 params => \$cgi, 243 javascript => 0,244 keepextras => 1,245 title => q[$title],246 fields => $fields,247 template => {248 type => 'Text',249 engine => {250 TYPE => 'STRING',251 SOURCE => q[$source],252 DELIMITERS => [ qw(<% %>) ],253 },254 data => {255 headings => $headings,256 author => q[$author],257 description => q[$description],258 },259 },260 259 $form_options 261 260 ); … … 269 268 1; 270 269 END 271 270 272 271 my $outfile = (split(/::/, $package))[-1] . '.pm'; 273 272 … … 299 298 <% (grep { $_->{required} } @fields) ? qq[<p id="instructions">(Required fields are marked in <strong>bold</strong>.)</p>] : '' %> 300 299 <% $start %> 300 <% 301 # drop in the hidden fields here 302 $OUT = join("\n", map { $$_{field} } grep { $$_{type} eq 'hidden' } @fields); 303 %> 304 301 305 <table> 302 306 303 <% for my $line (@lines) {307 <% TABLE_LINE: for my $line (@lines) { 304 308 305 309 if ($$line[0] eq 'head') { … … 308 312 #TODO: we only need the field names, not the full field spec in the lines strucutre 309 313 local $_ = $field{$$line[1]{name}}; 314 # skip hidden fields in the table 315 next TABLE_LINE if $$_{type} eq 'hidden'; 316 310 317 $OUT .= $$_{invalid} ? qq[ <tr class="invalid">] : qq[ <tr>]; 311 318 $OUT .= '<th class="label">' . ($$_{required} ? qq[<strong class="required">$$_{label}:</strong>] : "$$_{label}:") . '</th>'; … … 402 409 $parser->write_module('My::Form'); 403 410 411 =head1 REQUIRES 412 413 L<Parse::RecDescent>, L<CGI::FormBuilder>, L<Text::Template> 414 404 415 =head1 DESCRIPTION 405 416 … … 596 607 text # the default 597 608 textarea 609 password 610 file 611 checkbox 612 radio 598 613 select 599 radio 600 checkbox 614 hidden 601 615 static 602 616 … … 681 695 =head1 TODO 682 696 697 DWIM for single valued checkboxes (e.g. C<moreinfo|Send me more info:checkbox>) 698 699 Use the custom message file format for messages in the built in template 700 701 C<!section> directive to split up the table into multiple tables, each 702 with their own id and (optional) heading 703 704 Optional validated fields; marked like C<//EMAIL?> 705 706 Better examples in the docs (maybe a standalone or two as well) 707 708 Document the defaults that are passed to CGI::FormBuilder 709 683 710 C<!include> directive to include external formspec files 684 711 685 Field groups all on one line in the generated form686 687 712 Better tests! 688 713 714 =head1 BUGS 715 689 716 =head1 SEE ALSO 690 717 691 718 L<CGI::FormBuilder> 719 720 =head1 THANKS 721 722 Thanks to eszpee for pointing out some bugs in the default value parsing. 692 723 693 724 =head1 AUTHOR -
trunk/lib/Text/FormBuilder/grammar
r22 r23 164 164 list_var: /@[A-Z_]+/ { $list_var = $item[1] } 165 165 166 option: valuedisplay_text(?)167 { push @options, { $item {value}=> $item{'display_text(?)'}[0] } }166 option: (simple_multiword | quoted_string) display_text(?) 167 { push @options, { $item[1] => $item{'display_text(?)'}[0] } } 168 168 169 169 value: identifier
Note: See TracChangeset
for help on using the changeset viewer.