Fix the grepping of tags in FS.
[gruta.git] / Gruta / Renderer / Grutatxt.pm
bloba474bf6991c44d38129a110d8f0c4a15f4e85e5e
1 package Gruta::Renderer::Grutatxt;
3 use strict;
4 use warnings;
6 use Grutatxt;
8 sub new {
9 my $class = shift;
10 my %args = @_;
12 my $r = bless( { renderer_id => 'grutatxt' }, $class );
14 $r->{title} = '';
15 $r->{marks} = [];
16 $r->{abstract} = 0;
18 $r->{grutatxt} = Grutatxt->new(
19 'header-offset' => 1,
20 'table-headers' => 1,
21 'title' => \$r->{title},
22 'marks' => $r->{marks},
23 'abstract' => \$r->{abstract}
26 return $r;
29 sub _process {
30 my $self = shift;
31 my $str = shift;
33 return $self->{grutatxt}->process($str);
36 sub story {
37 my $self = shift;
38 my $story = shift; # ::Data::Story
40 my @o = $self->_process( $story->get('content') );
42 my $to;
44 if ($self->{marks}->[0]) {
45 # story has a separator
46 $to = $self->{marks}->[0] - 1;
48 else {
49 # use first paragraph
50 $to = $self->{abstract};
53 $to = scalar(@o) - 1 if $to >= scalar(@o);
55 $story->set('title', $self->{title}) if $self->{title};
56 $story->set('abstract', join("\n", @o[0 .. $to]));
57 $story->set('body', join("\n", @o));
59 return $self;