protected function _buildOnlineDocuments(API_Model $model) { $config = array('view_dir' => dirname(__FILE__) . '/api/view'); $render = new QView_Render_PHP($config); error_reporting(0); $sort = array('core', 'mvc', 'orm', 'form', 'database', 'helper', 'cache', 'webcontrols', 'behavior'); $arr = $model->packages; $packages = array(); foreach ($sort as $name) { $packages[$name] = $arr[$name]; unset($arr[$name]); } $packages = array_merge($packages, $arr); $render->assign('packages', $packages); $render->assign('classes', $model->classes); $render->assign('class_url', '/docs/qeephp-api/%CLASS%'); $render->assign('index_url', '/docs/qeephp-api/'); foreach ($model->classes as $class) { $render->assign('class', $class); $contents = $render->fetch('class'); $filename = 'class-' . str_replace('_', '-', strtolower($class->name)) . '.php'; echo "write file \"{$filename}\"...\n"; file_put_contents($this->_output_dir . DS . $filename, $contents); } // 生成索引页 $contents = $render->fetch('index'); $filename = 'index.php'; echo "write file \"{$filename}\"...\n"; file_put_contents($this->_output_dir . DS . $filename, $contents); // 生成内部索引页 $contents = $render->fetch('book-index'); $filename = 'book-index.php'; echo "write file \"{$filename}\"...\n"; file_put_contents($this->_output_dir . DS . $filename, $contents); // 复制附属文件 $this->_copyAssets(dirname(__FILE__) . '/api/assets'); }
/** * 渲染指定的视图文件 * * 渲染时,视图要使用的数据保存在控件的 $_view 属性中。 * * @param string $filename * @param array $more_vars * * @return string */ protected function _fetchView($filename, array $more_vars = null) { $vars = $this->_view; $vars['_ctx'] = $this->_context; $vars['_CTL_ID'] = $this->id(); $vars['_BASE_DIR'] = $this->_context->baseDir(); $vars['_BASE_URI'] = $this->_context->baseUri(); $vars['_REQUEST_URI'] = $this->_context->requestUri(); if (is_array($more_vars)) { $vars = array_merge($vars, $more_vars); } //if (is_null($this->_render)) //{ $this->_render = new $this->_render_class(dirname($filename)); //} $this->_render->vars($vars); $extname = pathinfo($filename, PATHINFO_EXTENSION); $pextname = $this->_render->extname(); if (empty($extname) || $extname != $pextname && !empty($pextname)) { $filename .= '.' . ($pextname ? $pextname : 'php'); } return $this->_render->parse($filename); }
/** * 渲染指定的视图文件 * * 渲染时,视图要使用的数据保存在控件的 $_view 属性中。 * * @param string $filename * @param array $more_vars * * @return string */ protected function _fetchView($filename, array $more_vars = null) { $vars = $this->_view; /** * TODO! 全局变量应该放到 控件抽象类 _before_render() 中 */ $vars['_ctx'] = $this->_context; $vars['_CTL_ID'] = $this->id(); $vars['_BASE_DIR'] = $this->_context->baseDir(); $vars['_BASE_URI'] = $this->_context->baseUri(); $vars['_REQUEST_URI'] = $this->_context->requestUri(); // if (is_array($more_vars)) { $vars = array_merge($vars, $more_vars); } if (strpos($filename, 'view:') === 0) { $filename = Q::ini('app_config/APP_DIR') . DS . 'view' . DS . ltrim(substr($filename, 5), '/\\'); } elseif ($filename[0] != DS && strpos($filename, ':') === false) { $_class_name = strtolower(get_class($this)); $_sep = explode('_', $_class_name); array_pop($_sep); $filename = Q::ini('app_config/APP_DIR') . DS . implode($_sep, DS) . DS . ltrim($filename, '/\\'); } if (is_null($this->_render)) { $this->_render = new $this->_render_class(dirname($filename)); } else { // TODO! 假如共享视图解析器实例,需在此做必要处理 } $this->_render->assign($vars); $extname = pathinfo($filename, PATHINFO_EXTENSION); $pextname = $this->_render->extname(); if (empty($extname) || $extname != $pextname && !empty($pextname)) { $filename .= '.' . ($pextname ? $pextname : 'php'); } return $this->_render->parse($filename); }
protected function _buildOnlineDocuments(Doc_Book $book, $extname = '.php', array $templates = null) { $default_templates = array('chapter' => 'chapter', 'section' => 'section', 'index' => 'index', 'book-index' => 'book-index'); if (is_array($templates)) { $templates = array_merge($default_templates, $templates); } else { $templates = $default_templates; } // 初始化 $config = array('view_dir' => dirname(__FILE__) . '/book/view'); $render = new QView_Render_PHP($config); $render->assign('book', $book); self::texySetting(array('image' => array('root' => $this->_img_root . "/{$book->name}/images", 'linkedRoot' => $this->_img_root . "/{$book->name}/images"))); // 生成索引页 $files = array(); $path = "index{$extname}"; $this->_buildPage($render, $templates['index'], $path); $files[] = $path; // 生成内部索引页 if (!empty($templates['book-index'])) { $files = array(); $path = "book-index{$extname}"; $this->_buildPage($render, $templates['book-index'], $path); $files[] = $path; } // 生成各个章节的页面 foreach ($book->chapters as $chapter) { $path = $chapter->nodename() . $extname; $this->_buildPage($render, $templates['chapter'], $path, array('chapter' => $chapter)); $files[] = $path; foreach ($chapter->sections as $section) { $path = $section->nodename() . $extname; $this->_buildPage($render, $templates['section'], $path, array('section' => $section)); $files[] = $path; } } // 复制附属文件 $this->_copyAssets($this->_source_dir . '/assets'); return $files; }