Beispiel #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 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();
 }
 /**
  * @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->getAsXhtml();
         $html = $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.');
     }
 }
 /**
  * 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);
 }
Beispiel #5
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);
         }
     }
 }