Example #1
0
 public function run()
 {
     $this->stdio->outln($this->version->getInfo());
     $this->stdio->outln();
     try {
         $getopt = $this->context->getopt($this->getOptions());
         # For the interactive session.
         if ($getopt->get('--init')) {
             $doc = $this->interactiveTemplateToDocument();
             $doc->saveRaw();
             $this->stdio->outln();
             $this->stdio->outln('Customized template written to ' . $doc->getFilepath());
             $this->converter->convert($doc, $this->placeholders);
             $targetPath = $doc->saveTarget();
             $this->stdio->outln('Converted document written to ' . $targetPath);
             exit(Status::SUCCESS);
         }
         $this->validate($getopt);
         $sourceFile = $getopt->get(1);
         if ($sourceFile === null) {
             $this->showHelp();
             exit(Status::USAGE);
         }
         if (!is_file($sourceFile)) {
             throw new \RuntimeException('File not found: ' . $sourceFile);
         }
         $doc = Document::fromFile($sourceFile);
         $this->converter->convert($doc, $this->placeholders);
         $targetFile = $doc->getTargetFilepath($getopt->get('--target'));
         if ($getopt->get('--diff')) {
             $this->showDiff($doc, $targetFile);
         }
         if ($getopt->get('--dry-run')) {
             // Show full output when diff is not wanted
             if (!$getopt->get('--diff')) {
                 $this->stdio->outln('Output:');
                 $this->stdio->outln('<<green>>---<<reset>>');
                 $this->stdio->outln($doc->getContent());
                 $this->stdio->outln('<<green>>---<<reset>>');
             }
         } else {
             $doc->saveTarget($targetFile);
         }
         $this->stdio->outln(sprintf('Saved output from <<green>>%s<<reset>> to <<green>>%s<<reset>>.', $doc->getFilepath(), $targetFile));
     } catch (\Exception $e) {
         $this->stdio->exception($e);
         exit(Status::FAILURE);
     }
 }
Example #2
0
 /**
  * @dataProvider complementaryEscapeProvider
  *
  * @param string $content
  * @param string $expectedContent
  */
 public function testEscape($content, $expectedContent)
 {
     $converter = new Converter();
     $escapedContent = $converter->escape($content);
     $this->assertSame($expectedContent, $escapedContent);
 }