add unformat() method to articles and test new doclink[] changes
authorTony Cook <tony@develop-help.com>
Thu, 3 Mar 2016 23:51:18 +0000 (10:51 +1100)
committerTony Cook <tony@develop-help.com>
Thu, 3 Mar 2016 23:51:38 +0000 (10:51 +1100)
site/cgi-bin/modules/BSE/FormatterBase.pm
t/060-generate/010-generate.t

index c5d91180db933a02d149a6ea5bffec41d988e151..8f3496d5a546542b0bf909973bb2c3409f889b7f 100644 (file)
@@ -1,7 +1,7 @@
 package BSE::FormatterBase;
 use strict;
 
-our $VERSION = "1.000";
+our $VERSION = "1.001";
 
 =head1 NAME
 
@@ -113,6 +113,78 @@ sub format {
   return $formatter->format($text);
 }
 
+=item unformat()
+
+Remove body text type formatting.
+
+Parameters:
+
+=over
+
+=item *
+
+C<text> - the body text to format, defaults to the article's body text
+
+=item *
+
+C<images> - the images to use for the image[] tags, defaults to the
+article's images.
+
+=item *
+
+C<files> - the files to use for the file[] tags, defaults to the
+article's files.
+
+=item *
+
+C<gen> - must be set to the parent generator object for embedding to
+work.
+
+=item *
+
+C<articles> - the articles collection class.  Internal use only.
+
+=item *
+
+C<abs_urls> - whether to use absolute URLs.  Default: FALSE.
+
+=item *
+
+C<cfg> - the config object.  Defaults to the global config object.
+
+=back
+
+=cut
+
+sub unformat {
+  my ($self, %opts) = @_;
+
+  my $cfg = $opts{cfg} || BSE::Cfg->single;
+
+  my $text = $opts{text};
+  defined $text or $text = $self->body;
+  my $images = $opts{images};
+  defined $images or $images = [ $self->images ];
+  my $files = $opts{files};
+  defined $files or $files = [ $self->files ];
+  my $gen = $opts{gen};
+  my $articles = $opts{articles} || "BSE::TB::Articles";
+  my $abs_urls = $opts{abs_urls};
+  defined $abs_urls or $abs_urls = 0;
+
+  my $formatter_class = $self->formatter_class;
+
+  my $auto_images;
+  my $formatter = $formatter_class->new(gen => $gen, 
+                                       articles => $articles,
+                                       abs_urls => $abs_urls, 
+                                       auto_images => \$auto_images,
+                                       images => $images, 
+                                       files => $files);
+
+  return $formatter->remove_format($text);
+}
+
 1;
 
 =back
index 184e090e59885f48780afa2102ae79ab1f265d18..276a1d10f1bc77e2fe21d2bcbfa28ef14000468a 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use BSE::Test ();
-use Test::More tests=>173;
+use Test::More tests=>176;
 use File::Spec;
 use FindBin;
 use Cwd;
@@ -92,6 +92,7 @@ my $grandkid = add_article
    parentid => $kids[1]{id},
    title => "Grandkid",
    body => "grandkid",
+   linkAlias => "gk-$alias_id",
   );
 
 my $prefix = "test" . time;
@@ -750,6 +751,19 @@ TEMPLATE
 <p>Embedded</p>
 EXPECTED
 
+# unformatter tests
+template_test "doclink[] unformatted", $parent, <<TEMPLATE, <<EXPECTED;
+<:= article.unformat("text", "doclink[gk-$alias_id]", "gen", generator) |raw:>
+<:= article.unformat("text", "doclink[gk-$alias_id|My title]", "gen", generator) |raw:>
+<:= article.unformat("text", "popdoclink[gk-$alias_id]", "gen", generator) |raw:>
+<:= article.unformat("text", "popdoclink[gk-$alias_id|My title]", "gen", generator) |raw:>
+TEMPLATE
+Grandkid
+My title
+Grandkid
+My title
+EXPECTED
+
 ############################################################
 # Cleanup