Create a gist now

Instantly share code, notes, and snippets.

HTML::Shakan::Renderer::HTML::DefinitionList
package HTML::Shakan::Renderer::HTML::DefinitionList;
use Any::Moose;
# use HTML::Shakan::Utils;
extends qw(
HTML::Shakan::Renderer::HTML
);
with qw(
HTML::Shakan::Renderer::HTML::SelectivelyEncodable
HTML::Shakan::Renderer::HTML::DateTimeSeparatable
);
has 'style_class' => (
is => 'rw',
isa => 'Str',
default => 'form',
);
sub render {
my ($self, $form) = @_;
my @res;
for my $field ($form->fields) {
unless ($field->id) {
$field->id(sprintf($self->id_tmpl(), $field->{name}));
}
if ($field->label) {
push @res, q{},
'<dt>',
sprintf( q{<label for="%s">%s</label>},
$field->{id},
$self->selectively_encode( $field->{label} )
),
'</dt>';
push @res, '<dd>',
$form->widgets->render( $form, $field ),
'</dd>';
}
else {
push @res, '<dt>',
'</dt>',
'<dd>',
$form->widgets->render( $form, $field ),
'</dd>',
q{};
}
}
unshift @res, defined $self->style_class
? sprintf('<dl class="%s">', $self->style_class)
: '<dl>';
push @res, '</dl>';
return $self->separate_datetime( join "\n", @res );
}
no Any::Moose;
__PACKAGE__->meta->make_immutable;
__END__
=head1 DESCRIPTION
HTML renderer for HTML::Shakan with definition list (C<< <dl> >>).
=head1 SEE ALSO
=over 4
=item HTML::Shakan::Renderer::HTML::DefinitionList
http://gist.github.com/148522
=item HTML::Shakan::Renderer::HTML::SelectivelyEncodable
http://gist.github.com/148523
=item HTML::Shakan::Renderer::HTML::DateTimeSeparatable
http://gist.github.com/148524
=back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment