Data-Edit-Xml-To-Dita

 view release on metacpan or  search on metacpan

lib/Data/Edit/Xml/To/DitaVb.pm  view on Meta::CPAN


      my $bookMap = isAMap($x) && !$x->isAllBlankText ? $x :                    # Create a bookmap unless we have been left with a convincing bookmap
        $x->ditaSampleBookMap
         (chapters=>$topicRef, title=>$title, notices=>$notices);

      cleanUpBookMap($project, $bookMap);                                       # Clean up book map
      lintBookMap($project, $x, $bookMap, $title);                              # Lint bookmap
     }
    else                                                                        # Not creating a book map for a single item
     {$project->targets =                                                       # Source file to target file details
        createTarget($project->source, $topicPath, $x->tag, q(topic));
     }
   }
  else                                                                          # No recognized structure so we will just create a bookmap so we get errors that we can see
   {my $bookMap = isAMap($x) ? $x : $x->wrapWith_bookmap;                       # Either its a bookmap or its something that we might be able to improve into being a bookmap
    cleanUpBookMap($project, $bookMap);                                         # Clean up book map
    lintBookMap($project, $x, $bookMap, $title);                                # Lint bookmap
   }
 } # cutOutTopics

sub convertDocument($$)                                                         #r Convert one document.
 {my ($project, $x) = @_;                                                       # Project == document to convert, parse tree.
  $x->wrapDown_conbody_concept unless couldBeCutOuut($x) or isAMap($x);         # Turn it into a concept if not already a recognizable type
  $x->ditaObviousChanges;
  $x                                                                            # Return parse tree
 }

sub convertProject($)                                                           #P Convert one document held in folder L<in|/in> into topic files held in L<out|/out>.
 {my ($project) = @_;                                                           # Project == document to convert
  ddd "convertProject           $$:", $project->source;

#  undef &Data::Edit::Xml::byStart;                                              # Print the name of the projects still being converted
#        *Data::Edit::Xml::byStart = sub
#   {my (undef, $file, $line) = caller(1);
#    lll "convertProject converting $$:", $project->source, "at $file line $line";
#   };

  my $x = parseProject $project;                                                # Reload parse into this process
  return $project unless $x;                                                    # Parse failed

  my $y = convertDocument($project, $x);                                        # Convert document optionally returning a new parse tree
  $x = $y if ref($y) and ref($y) eq ref($x);                                    # Continue with new parse tree if one provided

  cutOutTopics($project, $x);                                                   # Cut out topics
  $project->targets or confess                                                  # Check every source file has a target file
    "No target for project from source file:\n".$project->source;

  ddd "convertProject finished  $$:", $project->source;
  $project                                                                      # Conversion succeeded for project
 } # convertProject

sub xrefResults                                                                 #P Run Xref to fix check results
 {if (xref)
   {$xrefResults = Data::Edit::Xml::Xref::xref                                  # Check and perhaps fix any cross references
     (addNavTitles              => xrefAddNavTitles,
      allowUniquePartialMatches => xrefAllowUniquePartialMatches,
      changeBadXrefToPh         => changeBadXrefToPh,
      deguidize                 => &deguidize,
      fixBadRefs                => &fixBadRefs,
      fixDitaRefs               => &fixDitaRefs ? targets : undef,              # Location of targets if we are going to fix dita refs in the output corpus that were valid in the input corpus
      fixRelocatedRefs          => &fixRelocatedRefs,                           # Fix references to relocated files that adhere to the GB Standard.
      fixXrefsByTitle           => &fixXrefsByTitle,                            # Fix xref by unique title
      inputFolder               => &out,
      matchTopics               => &xrefMatchTopics,
      maximumNumberOfProcesses  => &maximumNumberOfProcesses,
      reports                   => &reports,
     );
   }
  else
   {ddd "Xref not requested";
   }

  undef
 }

sub lintResultsDefault                                                          #P Lint results held in folder L<out|/out>and write reports to folder L<reports|/reports>.
 {if (lint)                                                                     # Only if lint requested
   {lll "Lint conversion results";
    if (my $report = $lintReport = Data::Edit::Xml::Lint::report                # Lint report
     (out, qr(\.(dita|ditamap|xml)\Z)))
     {xrefResults;                                                              # Xref results  - xref relies on lint results
      my $d = dateTimeStamp;
      my $p = pleaseSee;
      my $r = $report->print;

      my $x = sub                                                               # Include xref results
       {return q() unless $xrefResults;
        $xrefResults->statusLine. " Tags To Text: ".
          $xrefResults->tagsTextsRatio // q();
       }->();

      if (my $n = &numberOfFiles)                                               # Check number of files if a count has been supplied
       {if (my $r = $report->numberOfFiles)
         {if ($r != $n)
           {cluck "Number of output files: $r does not match expected number: $n";
       } } }

      my $s = <<END;                                                            # rrrr - write summary.txt
Summary of passing and failing projects on $d.\t\tVersion: $VERSION

$r

$x

$p
END
      say STDERR $s;                                                            # Write lint results
      owf(summaryFile, $s);
      Flip::Flop::lint();

      if (my $fails = $report->failingFiles)                                    # Copy failing files into their own folder  for easy access s
       {if (@$fails)
         {for my $file(@$fails)
           {my $f = $file->[2];                                                 # Failing file name
            my $F = fpf(fails, fne $f);                                         # Shorten file name path so we can find the file easily
            copyFile($f, $F);
           }
         }
       }

      $lintResults = join "\n\n", ($r =~ s(\n.*\Z) ()sr), $x, $p;               # Lint results summary, used to create GitHub notification after upload is complete



( run in 0.933 second using v1.01-cache-2.11-cpan-71847e10f99 )