Changeset 82 in text-formbuilder
- Timestamp:
- 04/21/05 10:48:19 (20 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changes
r81 r82 2 2 3 3 0.11 4 * added as_script and as_module methods that just return the 5 Perl code 4 6 * added a !reset directive to name and include a reset button 5 7 * added a !submit directive to rename the submit button or to -
trunk/lib/Class/ParseText/Base.pm
r75 r82 78 78 croak '[' . (caller(0))[3] . '] No start rule given for the parser' unless defined $start_rule; 79 79 80 # set the trace in RecDescent if we have the debug flag 81 $::RD_TRACE = $self->{debug} ? 1 : undef; 82 80 83 $self->{$start_rule} = $self->{parser}->$start_rule($src); 81 84 -
trunk/lib/Text/FormBuilder.pm
r81 r82 36 36 th { text-align: left; } 37 37 th h2 { padding: .125em .5em; background: #eee; font-size: 1.25em; } 38 th.label { font-weight: normal; text-align: right; vertical-align: top; }38 .label { font-weight: normal; text-align: right; vertical-align: top; } 39 39 td ul { list-style: none; padding-left: 0; margin-left: 0; } 40 40 .note { background: #eee; padding: .5em 1em; } … … 47 47 text_author => 'Created by %s', 48 48 text_madewith => 'Made with %s version %s', 49 text_required => ' (Required fields are marked in <strong>bold</strong>.)',49 text_required => '* denotes a <strong>required field</strong>.', 50 50 text_invalid => 'Missing or invalid value.', 51 51 ); … … 363 363 map { $object_name . '->field' . Data::Dumper->Dump([$_],['*field']) . ';' } @{ $self->{form_spec}{fields} } 364 364 ); 365 } 366 367 sub write_module {365 } 366 367 sub as_module { 368 368 my ($self, $package, $use_tidy) = @_; 369 369 … … 372 372 # remove a trailing .pm 373 373 $package =~ s/\.pm$//; 374 ## warn "[Text::FromBuilder::write_module] Removed extra '.pm' from package name\n" if $package =~ s/\.pm$//; 375 374 375 # auto-build 376 $self->build unless $self->{built}; 377 376 378 my $form_options = $self->_form_options_code; 377 379 my $field_setup = $self->_field_setup_code('$self'); … … 429 431 1; 430 432 END 431 _write_output_file($module, (split(/::/, $package))[-1] . '.pm', $use_tidy); 433 434 $module = _tidy_code($module, $use_tidy) if $use_tidy; 435 436 return $module; 437 } 438 439 sub write_module { 440 my ($self, $package, $use_tidy); 441 442 my $module = $self->as_module($package, $use_tidy); 443 444 _write_output_file($module, (split(/::/, $package))[-1] . '.pm'); 432 445 return $self; 433 446 } 434 447 435 sub write_script { 436 my ($self, $script_name, $use_tidy) = @_; 437 438 croak '[' . (caller(0))[3] . '] Expecting a script name' unless $script_name; 448 sub as_script { 449 my ($self, $use_tidy) = @_; 450 451 # auto-build 452 $self->build unless $self->{built}; 439 453 440 454 my $form_options = $self->_form_options_code; … … 460 474 } 461 475 END 462 463 _write_output_file($script, $script_name, $use_tidy); 476 $script = _tidy_code($script, $use_tidy) if $use_tidy; 477 478 return $script; 479 } 480 481 sub write_script { 482 my ($self, $script_name, $use_tidy) = @_; 483 484 croak '[' . (caller(0))[3] . '] Expecting a script name' unless $script_name; 485 486 my $script = $self->as_script($use_tidy); 487 488 _write_output_file($script, $script_name); 464 489 return $self; 465 490 } 466 491 492 sub _tidy_code { 493 my ($source_code, $use_tidy) = @_; 494 eval 'use Perl::Tidy'; 495 carp '[' . (caller(0))[3] . "] Can't tidy the code: $@" and return $source_code if $@; 496 497 # use the options string only if it begins with '_' 498 my $options = ($use_tidy =~ /^-/) ? $use_tidy : undef; 499 500 my $tidy_code; 501 Perl::Tidy::perltidy(source => \$source_code, destination => \$tidy_code, argv => $options || $TIDY_OPTIONS); 502 503 return $tidy_code; 504 } 505 506 467 507 sub _write_output_file { 468 my ($source_code, $outfile, $use_tidy) = @_; 469 if ($use_tidy) { 470 # clean up the generated code, if asked 471 eval 'use Perl::Tidy'; 472 unless ($@) { 473 Perl::Tidy::perltidy(source => \$source_code, destination => $outfile, argv => $TIDY_OPTIONS); 474 } else { 475 carp '[' . (caller(0))[3] . "] Can't tidy the code: $@" if $@; 476 # fallback to just writing it as-is 477 open OUT, "> $outfile" or die $!; 478 print OUT $source_code; 479 close OUT; 480 } 481 } else { 482 # otherwise, just print as is 483 open OUT, "> $outfile" or die $!; 484 print OUT $source_code; 485 close OUT; 486 } 508 my ($source_code, $outfile) = @_; 509 open OUT, "> $outfile" or croak '[' . (caller(1))[3] . "] Can't open $outfile for writing: $!"; 510 print OUT $source_code; 511 close OUT; 487 512 } 488 513 … … 531 556 # special case single value checkboxes 532 557 if ($$_{type} eq 'checkbox' && @{ $$_{options} } == 1) { 533 $OUT .= qq[<t h></th>];558 $OUT .= qq[<td></td>]; 534 559 } else { 535 $OUT .= '<t h class="label">' . ($$_{required} ? qq[<strong class="required">$$_{label}</strong>] : "$$_{label}") . '</th>';560 $OUT .= '<td class="label">' . ($$_{required} ? qq[* <strong class="required">$$_{label}</strong>] : "$$_{label}") . '</td>'; 536 561 } 537 562 … … 549 574 $OUT .= (grep { $$_{invalid} } @group_fields) ? qq[ <tr class="invalid">\n] : qq[ <tr>\n]; 550 575 551 $OUT .= ' <t hclass="label">';552 $OUT .= (grep { $$_{required} } @group_fields) ? qq[ <strong class="required">$$line[1]{label}</strong>] : "$$line[1]{label}";553 $OUT .= qq[</t h>\n];576 $OUT .= ' <td class="label">'; 577 $OUT .= (grep { $$_{required} } @group_fields) ? qq[* <strong class="required">$$line[1]{label}</strong>] : "$$line[1]{label}"; 578 $OUT .= qq[</td>\n]; 554 579 555 580 $OUT .= qq[ <td><span class="fieldgroup">]; … … 815 840 HTML to a file, or to STDOUT if no filename is given. 816 841 842 =head2 as_module 843 844 my $module_code = $parser->as_module($package, $use_tidy); 845 817 846 =head2 write_module 818 847 … … 857 886 # write tidier code 858 887 $parser->write_module('My::Form', 1); 888 889 If you set C<$use_tidy> to a string beginning with `-' C<write_module> will 890 interpret C<$use_tidy> as the formatting option switches to pass to Perl::Tidy. 891 892 =head2 as_script 893 894 my $script_code = $parser->as_script($use_tidy); 859 895 860 896 =head2 write_script
Note: See TracChangeset
for help on using the changeset viewer.