Ejemplo n.º 1
0
 /**
  * Transforms the given text into HTML
  *
  * @param string $text
  *
  * @return string The HTML Output
  */
 public function parse($text)
 {
     $rstDoc = new \ezcDocumentRst($rstOptions = new \ezcDocumentRstOptions($this->config));
     $rstDoc->loadString($text);
     $htmlDoc = $rstDoc->getAsXhtml();
     return $htmlDoc->save();
 }
 public function testDocumentVisitorNotices()
 {
     $xhtml = new ezcDocumentRst();
     $errors = $xhtml->validateFile(dirname(__FILE__) . '/files/rst/validation/visitor_warning.txt');
     $this->assertTrue($errors[0] instanceof ezcDocumentValidationError, 'Expected an array of ezcDocumentValidationError objects to be returned');
     $this->assertSame(1, count($errors), 'Expected three errors to be found in validated document.');
     $this->assertTrue($errors[0]->getOriginalError() instanceof ezcDocumentVisitException, 'Expected an array of ezcDocumentVisitException objects to be returned');
     $this->assertSame('Visitor error: Warning: \'Too few anonymous reference targets.\' in line 0 at position 0.', (string) $errors[0]);
 }
Ejemplo n.º 3
0
 public function testCreateDocumentFromErrneousDocbook()
 {
     $doc = new ezcDocumentDocbook();
     $doc->options->failOnError = false;
     $doc->loadFile(dirname(__FILE__) . '/files/docbook/errorneous.xml');
     $rst = new ezcDocumentRst();
     try {
         $rst->createFromDocbook($doc);
         $this->fail('Expected ezcDocumentVisitException.');
     } catch (ezcDocumentVisitException $e) {
         /* Expected */
     }
 }
Ejemplo n.º 4
0
 /**
  * Sets the Scrybe-specific options, registers the roles and directives and loads the file.
  *
  * @param ConverterInterface $converter
  * @param File $file
  */
 public function __construct(ConverterInterface $converter, File $file)
 {
     parent::__construct();
     $this->options->xhtmlVisitor = 'phpDocumentor\\Plugin\\Scrybe\\Converter\\RestructuredText\\Visitors\\Creator';
     $this->options->errorReporting = E_PARSE | E_ERROR;
     $this->registerDirective('code-block', 'phpDocumentor\\Plugin\\Scrybe\\Converter\\RestructuredText\\Directives\\CodeBlock');
     $this->registerDirective('toctree', 'phpDocumentor\\Plugin\\Scrybe\\Converter\\RestructuredText\\Directives\\Toctree');
     $this->registerDirective('image', 'phpDocumentor\\Plugin\\Scrybe\\Converter\\RestructuredText\\Directives\\Image');
     $this->registerDirective('figure', 'phpDocumentor\\Plugin\\Scrybe\\Converter\\RestructuredText\\Directives\\Figure');
     $this->registerRole('doc', 'phpDocumentor\\Plugin\\Scrybe\\Converter\\RestructuredText\\Roles\\Doc');
     $this->file = $file;
     $this->converter = $converter;
     $this->loadString($file->fread());
 }
 /**
  * @dataProvider getErroneousTestDocuments
  */
 public function testParseErroneousRstFile($file, $message)
 {
     try {
         $document = new ezcDocumentRst();
         $document->options->errorReporting = E_PARSE | E_ERROR | E_WARNING;
         $document->registerDirective('my_custom_directive', 'ezcDocumentTestDummyDirective');
         $document->registerDirective('user', 'ezcDocumentTestDummyDirective');
         $document->registerDirective('book', 'ezcDocumentTestDummyDirective');
         $document->registerDirective('function', 'ezcDocumentTestDummyDirective');
         $document->registerDirective('replace', 'ezcDocumentTestDummyDirective');
         $document->loadFile($file);
         $docbook = $document->getAsDocbook();
         $xml = $docbook->save();
         $document = $parser->parse($tokenizer->tokenizeFile($file));
         $this->fail('Expected some exception.');
     } catch (ezcDocumentException $e) {
         $this->assertSame($message, $e->getMessage(), 'Different parse error expected.');
     }
 }
 public function testDocumentHeaderLevel()
 {
     $from = dirname(__FILE__) . '/files/rst/xhtml_body/s_002_titles.txt';
     $to = dirname(__FILE__) . '/files/rst/xhtml_body/s_002_titles_header_level.html';
     $document = new ezcDocumentRst();
     $document->options->errorReporting = E_PARSE | E_ERROR | E_WARNING;
     $document->options->xhtmlVisitor = 'ezcDocumentRstXhtmlBodyVisitor';
     $document->options->xhtmlVisitorOptions->headerLevel = 3;
     $document->registerDirective('my_custom_directive', 'ezcDocumentTestDummyXhtmlDirective');
     $document->registerDirective('user', 'ezcDocumentTestDummyXhtmlDirective');
     $document->registerDirective('book', 'ezcDocumentTestDummyXhtmlDirective');
     $document->registerDirective('function', 'ezcDocumentTestDummyXhtmlDirective');
     $document->registerDirective('replace', 'ezcDocumentTestDummyXhtmlDirective');
     $document->loadFile($from);
     $html = $document->getAsXhtml();
     $html->options->xmlHeader = true;
     $xml = $html->save();
     // Store test file, to have something to compare on failure
     $tempDir = $this->createTempDir('html_') . '/';
     file_put_contents($tempDir . basename($to), $xml);
     $this->assertEquals(file_get_contents($to), $xml, 'Document not visited as expected.');
     // Remove tempdir, when nothing failed.
     $this->removeTempDir();
 }
Ejemplo n.º 7
0
<?php

require 'tutorial_autoload.php';
// Convert some input RSTfile to docbook
$document = new ezcDocumentRst();
$document->loadFile('./article/introduction.txt');
$pdf = new ezcDocumentPdf();
$pdf->options->errorReporting = E_PARSE | E_ERROR | E_WARNING;
$pdf->createFromDocbook($document->getAsDocbook());
file_put_contents(__FILE__ . '.pdf', $pdf);
Ejemplo n.º 8
0
 /**
  * Generates the documentation of the extension, if created in RST format in the doc/ folder, plus optionally
  * API docs via doxygen; options: --doxygen=/path/to/doxygen
  *
  * Builds an html file of all doc/*.rst files, and removes the source, then, if
  * configured in the options file, uses doxygen to create html documentation of
  * php source code in doc/api. The location of the doxygen binary can be specified
  * via a configuration option
  *
  * @todo allow config file to specify doc dir
  * @todo use local doxygen file if found, instead of std one
  * @todo create api doc from php files using phpdoc too
  *       example cli cmd: ${phpdocinstall}phpdoc -t ${phpdocdir}/html -ti 'eZ Publish' -pp -s -d lib/ezdb/classes,lib/ezdbschema/classes,lib/ezdiff/classes,lib/ezfile/classes,lib/ezi18n/classes,lib/ezimage/classes,lib/ezlocale/classes,lib/ezmath/classes,lib/ezpdf/classes,lib/ezsession/classes,lib/ezsoap/classes,lib/eztemplate/classes,lib/ezutils/classes,lib/ezxml/classes,kernel/classes,kernel/private/classes,kernel/common,cronjobs,update/common/scripts > ${phpdocdir}/generate.log
  */
 static function run_generate_documentation($task = null, $args = array(), $cliopts = array())
 {
     $opts = self::getOpts(@$args[0], @$args[1], $cliopts);
     if (!SharedLock::acquire($opts['extension']['name'], LOCK_EX, $opts)) {
         throw new PakeException("Source code locked by another process");
     }
     $destdir = self::getBuildDir($opts) . '/' . $opts['extension']['name'];
     $docdir = $destdir . '/doc';
     $files = pakeFinder::type('file')->name('*.rst')->in($docdir);
     foreach ($files as $i => $file) {
         $dst = substr($file, 0, -3) . 'html';
         $document = new ezcDocumentRst();
         $document->loadFile($file);
         $docbook = $document->getAsXhtml();
         file_put_contents($dst, $docbook->save());
         pake_echo_action('file+', $dst);
         pake_remove($file, '');
     }
     /*
      * A few extension have Makefiles to generate documentation
      * We remove them as well as the original .rst files
      * NB: this is not done anymore since version 0.1. Use files.to_exclude option instead
      */
     //pake_remove( pakeFinder::type( 'file' )->name( 'Makefile' )->in( $destdir ), '' );
     // doxygen
     if ($opts['create']['doxygen_doc']) {
         pake_mkdirs($docdir . '/api');
         $doxygen = self::getTool('doxygen', $opts);
         $doxyfile = $destdir . '/doxyfile';
         pake_copy(self::getResourceDir() . '/doxyfile_master', $doxyfile, array('override' => true));
         file_put_contents($doxyfile, "\nPROJECT_NAME = " . $opts['extension']['name'] . "\nPROJECT_NUMBER = " . $opts['version']['alias'] . $opts['releasenr']['separator'] . $opts['version']['release'] . "\nOUTPUT_DIRECTORY = " . $docdir . '/api' . "\nINPUT = " . $destdir . "\nEXCLUDE = " . $destdir . '/settings' . "\nSTRIP_FROM_PATH = " . $destdir, FILE_APPEND);
         $out = pake_sh($doxygen . ' ' . escapeshellarg($doxyfile));
         pake_remove($doxyfile, '');
         // cleanup leftover files, just in case dot tool is not found
         $files = pakeFinder::type('file')->name(array('*.dot', '*.md5', '*.map', 'installdox'))->in($docdir . '/api');
         pake_remove($files, '');
     }
     SharedLock::release($opts['extension']['name'], LOCK_EX, $opts);
 }
Ejemplo n.º 9
0
 /**
  * Create document from structure
  *
  * Build a ezcDocumentDocument object from the structure created during the
  * visiting process.
  *
  * @param mixed $content 
  * @return ezcDocumentDocument
  */
 protected function createDocument($content)
 {
     // Append footnotes and citations to document
     $content = $this->finishDocument($content);
     // Create document object out of contents
     $rst = new ezcDocumentRst();
     $rst->loadString($content);
     return $rst;
 }
Ejemplo n.º 10
0
 /**
  * Transform directive to HTML
  *
  * Create a XHTML structure at the directives position in the document.
  * 
  * @param DOMDocument $document 
  * @param DOMElement $root 
  * @return void
  */
 public function toXhtml(DOMDocument $document, DOMElement $root)
 {
     $file = $this->getFile(trim($this->node->parameters));
     if ($root->tagName === 'p') {
         // The include is inline. There is no way to handle the embedding
         // of another document inside a paragraph properly.
         throw new ezcDocumentVisitException(E_PARSE, 'Caanot embed include inside a paragraph.');
     }
     if (isset($this->node->options['literal'])) {
         // If the file should be included as a literal, just pass it
         // through in such a block.
         $literal = $document->createElement('pre', htmlspecialchars(file_get_contents($file)));
         $root->appendChild($literal);
     } else {
         // Otherwise we reenter the complete parsing process with the new file.
         $doc = new ezcDocumentRst();
         $doc->loadFile($file);
         // Get XHtml DOM tree from the parsed file
         $html = $doc->getAsXhtml();
         $tree = $html->getDomDocument();
         // Import all contents below the body node.
         $article = $tree->getElementsByTagName('body')->item(0);
         foreach ($article->childNodes as $child) {
             $imported = $document->importNode($child, true);
             $root->appendChild($imported);
         }
     }
 }
Ejemplo n.º 11
0
<?php

require 'tutorial_autoload.php';
$document = new ezcDocumentRst();
$document->loadFile('../tutorial.txt');
$docbook = $document->getAsDocbook();
echo $docbook->save();
Ejemplo n.º 12
0
<?php

require 'tutorial_autoload.php';
// Load custom directive
require '00_01_address_directive.php';
$document = new ezcDocumentRst();
$document->registerDirective('address', 'myAddressDirective');
$document->loadString(<<<EORST
Address example
===============

.. address:: John Doe
    :street: Some Lane 42
EORST
);
$docbook = $document->getAsDocbook();
echo $docbook->save();
Ejemplo n.º 13
0
<?php

require 'tutorial_autoload.php';
$docbook = new ezcDocumentDocbook();
$docbook->loadFile('docbook.xml');
$rst = new ezcDocumentRst();
$rst->createFromDocbook($docbook);
echo $rst->save();