App-Basis-ConvertText2
view release on metacpan or search on metacpan
t/02_plugins.t view on Meta::CPAN
sub extract_args {
my $buf = shift;
my ( %attr, $eaten );
return \%attr if ( !$buf );
while ( $buf =~ s|^\s?(([a-zA-Z][a-zA-Z0-9\.\-_]*)\s*)|| ) {
$eaten .= $1;
my $attr = lc $2;
my $val;
# The attribute might take an optional value (first we
# check for an unquoted value)
if ( $buf =~ s|(^=\s*([^\"\'>\s][^>\s]*)\s*)|| ) {
$eaten .= $1;
$val = $2;
# or quoted by " or '
}
elsif ( $buf =~ s|(^=\s*([\"\'])(.*?)\2\s*)||s ) {
$eaten .= $1;
$val = $3;
# truncated just after the '=' or inside the attribute
}
elsif ($buf =~ m|^(=\s*)$|
or $buf =~ m|^(=\s*[\"\'].*)|s )
{
$buf = "$eaten$1";
last;
}
else {
# assume attribute with implicit value
$val = $attr;
}
$attr{$attr} = $val;
}
return \%attr;
}
# -----------------------------------------------------------------------------
# barcodes
$obj = App::Basis::ConvertText2::Plugin::Barcode->new();
$content = '12345678';
$params = { type => 'ean8' };
$out = $obj->process( 'barcode', $content, $params, $TEST_DIR );
ok( has_file($out), 'barcode created a file' );
$content = 'http://news.bbc.co.uk';
$params = { height => 50, version => 2 };
$out = $obj->process( 'qrcode', $content, $params, $TEST_DIR );
ok( has_file($out), 'qrcode created a file' );
# chart
$obj = App::Basis::ConvertText2::Plugin::Chart->new();
$content = "apples,bananas,cake,cabbage,edam,fromage,tomatoes,chips
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55";
$params = extract_args('title="chart1" size="400x400" xaxis="things xways" yaxis="Vertical things" format="pie" legends="a,b,c,d,e,f,g,h"');
$out = $obj->process( 'chart', $content, $params, $TEST_DIR );
ok( has_file($out), 'chart created a file' );
# sparkline
$content = '1,4,5,20,4,5,3,1';
$obj = App::Basis::ConvertText2::Plugin::Sparkline->new();
$params = extract_args("title='sparkline' scheme='blue'");
$out = $obj->process( 'sparkline', $content, $params, $TEST_DIR );
ok( has_file($out), 'sparkline created a file' );
# venn
$content = 'abel edward momo albert jack julien chris
edward isabel antonio delta albert kevin jake
gerald jake kevin lucia john edward';
$obj = App::Basis::ConvertText2::Plugin::Venn->new();
$params = extract_args("title='sample venn diagram' legends='team1 team2 team3' scheme='rgb' explain='1'");
$out = $obj->process( 'sparkline', $content, $params, $TEST_DIR );
ok( has_file($out), 'venn created a file' );
# links
$obj = App::Basis::ConvertText2::Plugin::Text->new();
$content = "pandoc | http://johnmacfarlane.net/pandoc
PrinceXML | http://www.princexml.com
markdown | http://daringfireball.net/projects/markdown
msc | http://www.mcternan.me.uk/mscgen/
ditaa | http://ditaa.sourceforge.net
PlantUML | http://plantuml.sourceforge.net
See Salt | http://plantuml.sourceforge.net/salt.html
graphviz | http://graphviz.org
JSON | https://en.wikipedia.org/wiki/Json
YAML | https://en.wikipedia.org/wiki/Yaml
";
$params = undef;
$out = $obj->process( 'links', $content, $params, $TEST_DIR );
ok( $out && $out =~ /<ul/, 'links created some content' );
# yamlasjson
$content = 'epg:
- triplet: [1,2,3,7]
channel: BBC3
date: 2013-10-20
time: 20:30
crid: dvb://112.4a2.5ec;2d22~20131020T2030000ZâPT01H30M
- triplet: [1,2,3,9]
channel: BBC4
date: 2013-11-20
time: 21:00
crid: dvb://112.4a2.5ec;2d22~20131120T2100000ZâPT01H30M
';
# page
$params = undef;
$obj = App::Basis::ConvertText2::Plugin::Text->new();
$out = $obj->process( 'yamlasjson', $content, $params, $TEST_DIR );
ok( $out && $out =~ /~~~~\{\.json/, 'yamlasjson created some content' );
# table
$content = 'apples,bananas,cake,cabbage,edam,fromage,tomatoes,chips
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55';
$params = undef;
$obj = App::Basis::ConvertText2::Plugin::Text->new();
$out = $obj->process( 'table', $content, $params, $TEST_DIR );
ok( $out && $out =~ /<table.*?>\s?<tr><td>apples/sm, 'table created' );
# version
$content = '0.1 2014-04-12
* removed ConvertFile.pm
* using Path::Tiny rather than other things
* changed to use pandoc fences ~~~~{.tag} rather than xml format <tag>
0.006 2014-04-10
* first release to github
';
$params = undef;
( run in 1.598 second using v1.01-cache-2.11-cpan-39bf76dae61 )