Dita-PCD
view release on metacpan or search on metacpan
lib/Dita/PCD.pm view on Meta::CPAN
sub pleaseChangeDita(%) #E Transform L[dita] files as specified by the directives in L<pcd> files.
{my (%options) = @_; # Execution options
checkKeys(\%options, # Check report options
{in=><<'END',
The input folder containing .dita files to be changed and .pcd files describing
the changes.
END
out=><<'END',
The output folder containing transformed copies of the input dita files.
END
reports=><<'END',
The output folder containing reports on the changes made.
END
optional=><<'END',
Do not complain if there are no .pcd files present.
END
});
my $in = $options{in}; # Input folder
my $out = $options{out}; # Output folder
my $reports = $options{reports}; # Reports folder
my $blocks = compilePcdFiles($in); # Blocks of changes
return undef if $options{optional} and !@$blocks; # No files to process and optional specified
@$blocks or confess "No .pcd files found in $in\n"; # No source files
my @dita = searchDirectoryTreesForMatchingFiles($in); # The dita files to be converted
for my $if(@dita) # Process each dita file against each change file
{next if fe($if) =~ m(\A(directory|pcd)\Z)i; # Skip files that are obviously not xml files
my $x = Data::Edit::Xml::new($if);
my $stats = transformDitaWithPcd($if, $x, $blocks); # Transform the parse tree with the compiled blocks tracing if required
# lll "File: $if\n", dump($stats);
my $o = swapFilePrefix($if, $in, $out); # Print the results
if ($x->ditaRoot)
{owf($o, $x->ditaPrettyPrintWithHeaders);
}
else
{owf($o, -p $x);
}
}
} # pleaseChangeDita
sub pleaseChangeDitaString($$%) #E Apply a pcd string to an xml string and return the resulting string
{my ($xml, $pcd, %options) = @_; # Xml, pcd options, options
my $blocks = compilePcdString($pcd); # Compiled Pcd
my $x = Data::Edit::Xml::new($xml); # Parse tree to transform
transformDitaWithPcd($options{file}//q(), $x, $blocks); # Transform the parse tree with the compiled pcd blocks
$x
} # pleaseChangeDitaString
sub pcdDitaTags
{qw(abstract alt anchorref annotation-xml apiname apply area author b bind body bodydiv brand bvar category cause cerror change-completed change-historylist change-item change-organization change-person change-request-id change-request-referen...
sub pcdUnitaryMethods{qw(addAttr addFirst addFirstAsText addLabels addLast addLastAsText addNext addNextAsText addPrev addPrevAsText addSingleChild addWrapWith an ancestry ap apn approxLocation at atOrBelow atStringContentMatches atText atTop attrAt ...
sub pcdRowActions
{qw(delete repeat copy cut after before)
}
sub pcdRowTypes
{qw(comment description method)
}
sub formatHtml($) #P Replace <> by < > to make example html displayable
{my ($string) = @_; # String
$string =~ s(<) (<)gs;
$string =~ s(>) (>)gs;
join "\n", q(<pre>), $string, q(</pre>);
}
sub printPcdExamplesHtml($;$) #P Print the PCD examples found in the module description of Data::Edit::Xml.
{my ($mod, $formatter) = @_; # Module description of Data::Edit::Xml, optional sub to format xml
my @h; # Html table showing before, pcd, after
my %m = $mod->methods->%*; # Module description
for my $m(sort keys %m)
{if (my $e = $m{$m}{example})
{my $i = join "\n", $e->before->@*; # Input Xml
my $b = $i =~ m(<(concept|reference|task)) ? $i : qq(<a>$i</a>); # Wrap input xml if no root tag supplied
my $c = join "\n", qq(Test:), map{qq( $_)} $e->code->@*; # Pcd
my $d = $e->doc; # Doc
my $braceable = sub # Demonstrates a braceable string
{my $u = $m{$m}{userFlags};
$u and $u =~ m(b) # Braceable marker
}->();
push @h, <<END; # Format PCD
<tr id="a$m" onclick="clickTitle(event, '$m')"><td class="bold">$m<td>$d
<tr id="b$m" class="hide pcdExample" onclick="clickExample(event)">
<td><td><table cellspacing="10" cellpadding="10" border="0">
END
if ($braceable && $formatter) # Braceable and we have a formatter to interpret it
{my $B = formatHtml $b;
my $A = formatHtml $formatter->($b); # Format input xml
push @h, <<END;
<tr><th>Input l[xml]<th><th>Output l[xml]
<tr><td>$B<td>Press <b>Save</b><td>$A
END
}
else
{my $B = sub # Format input xml
{my $x = eval {Data::Edit::Xml::new($b)};
if ($@)
{return qq(<h2>Error</h2><p>$b <p>$@) if $@;
}
( run in 0.823 second using v1.01-cache-2.11-cpan-9581c071862 )