コード例 #1
0
ファイル: project.php プロジェクト: TypeFriendly/TypeFriendly
 /**
  * Generates the output document.
  *
  * @staticvar standardOutput $lastOutput The last output used.
  */
 public function generate()
 {
     static $lastOutput = NULL;
     $prog = tfProgram::get();
     $reparse = false;
     if ($lastOutput != $this->output) {
         $lastOutput = $this->output;
         $reparse = true;
     }
     $this->fs->safeMkDir('output/' . $this->output, TF_READ | TF_WRITE | TF_EXEC);
     $this->fs->cleanUpDirectory('output/' . $this->output);
     $this->copyMedia();
     $this->outputObj = $out = $this->prog->fs->loadObject('outputs/' . $this->output . '.php', $this->output);
     if ($reparse) {
         $parsers = tfParsers::get();
         $refs = array();
         $refTitles = array();
         foreach ($this->pages as &$page) {
             $refs[$page['Id']] = $this->outputObj->toAddress($page['Id']);
             $refTitles[$page['Id']] = ($this->config['showNumbers'] ? $page['FullNumber'] . '. ' : '') . (!isset($page['Tags']['ShortTitle']) ? $page['Tags']['Title'] : $page['Tags']['ShortTitle']);
         }
         $parsers->getParser()->predef_urls = $refs;
         $parsers->getParser()->predef_titles = $refTitles;
     }
     foreach ($this->pages as &$page) {
         if (!tfTags::validateTags($page['Tags'])) {
             throw new Exception('Tag validation error in "' . $page['Id'] . '": ' . PHP_EOL . tfTags::getError());
         }
     }
     $out->init($this, 'output/' . $this->output . '/');
     foreach ($this->pages as &$page) {
         if (!$this->parsed) {
             $page['Markdown'] = $page['Content'];
         }
         $parsers->getParser()->fn_id_prefix = str_replace('.', '_', $page['Id']) . ':';
         $parsers->getParser()->page_id = $page['Id'];
         $page['Content'] = $parsers->parse($page['Markdown']);
         $out->generate($page);
         $prog->console->stderr->write('.');
     }
     $prog->console->stderr->write(PHP_EOL);
     $this->parsed = true;
     $out->close();
 }