Skip to content
Browse files

Steal the form field class from Jifty

  • Loading branch information...
1 parent c0bde4d commit 38e2243ba3a0af1383a11736a77823fe032b3f49 @sartak sartak committed Nov 4, 2009
Showing with 43 additions and 0 deletions.
  1. +43 −0 lib/Jifty/Web/Form/Field/Wikitext.pm
View
43 lib/Jifty/Web/Form/Field/Wikitext.pm
@@ -0,0 +1,43 @@
+package Jifty::Web::Form::Field::Wikitext;
+use warnings;
+use strict;
+use base qw/Jifty::Web::Form::Field::Textarea/;
+
+use Text::WikiFormat;
+use HTML::Scrubber;
+
+__PACKAGE__->mk_accessors(qw(rows cols));
+
+=head1 NAME
+
+Jifty::Web::Form::Field::Wikitext - A textarea that renders wiki syntax
+
+=head2 render_value
+
+Renders the value using L<Text::WikiFormat>.
+
+=cut
+
+sub render_value {
+ my $self = shift;
+ my $field = '<span';
+ $field .= qq! class="@{[ $self->classes ]} value"> !;
+ if (defined $self->current_value) {
+ my $text = "@{[$self->current_value]}";
+ my $scrubber = HTML::Scrubber->new;
+ my $scrubbed = $scrubber->scrub($text);
+
+ $field .= Text::WikiFormat::format($scrubbed, {}, {
+ extended => 1,
+ absolute_links => 1,
+ implicit_links => 0, # XXX: make this configurable
+ prefix => Jifty->web->url,
+ });
+ }
+ $field .= qq!</span>\n!;
+ Jifty->web->out($field);
+ return '';
+}
+
+1;
+

0 comments on commit 38e2243

Please sign in to comment.
Something went wrong with that request. Please try again.