/** * Creates an html list of all classes sorted by category (or package if no category) * * @return string the html for the menu */ public static function menu() { $classes = Kodoc::classes(); ksort($classes); $menu = array(); $route = Route::get('docs/api'); foreach ($classes as $class) { if (Kodoc::is_transparent($class, $classes)) { continue; } $class = Kodoc_Class::factory($class); // Test if we should show this class if (!Kodoc::show_class($class)) { continue; } $link = HTML::anchor($route->uri(array('class' => $class->class->name)), $class->class->name); if (isset($class->tags['package'])) { foreach ($class->tags['package'] as $package) { if (isset($class->tags['category'])) { foreach ($class->tags['category'] as $category) { $menu[$package][$category][] = $link; } } else { $menu[$package]['Base'][] = $link; } } } else { $menu['[Unknown]']['Base'][] = $link; } } // Sort the packages ksort($menu); return View::factory('userguide/api/menu')->bind('menu', $menu); }
/** * Creates an html list of all classes sorted by category (or package if no category) * * @return string the html for the menu */ public static function menu() { $menu = Cache::instance()->get('kodocMenu'); if ($menu !== NULL) { return View::factory('userguide/api/menu')->bind('menu', $menu); } $profiler = Profiler::start('Userguide', 'build menu'); $classes = Kodoc::classes(); foreach ($classes as $class) { if (isset($classes['kohana_' . $class])) { // Remove extended classes unset($classes['kohana_' . $class]); } if (isset($classes['kodicms_' . $class])) { // Remove extended classes unset($classes['kodicms_' . $class]); } } ksort($classes); $menu = array(); $route = Route::get('docs/api'); foreach ($classes as $class) { $class = Kodoc_Class::factory($class); // Test if we should show this class if (!Kodoc::show_class($class)) { continue; } $link = HTML::anchor($route->uri(array('class' => $class->class->name)), $class->class->name); if (isset($class->tags['package'])) { foreach ($class->tags['package'] as $package) { if (isset($class->tags['category'])) { foreach ($class->tags['category'] as $category) { $menu[$package][$category][] = $link; } } else { $menu[$package]['Base'][] = $link; } } } else { $menu['[Unknown]']['Base'][] = $link; } } // Sort the packages ksort($menu); Cache::instance()->set('kodocMenu', $menu, Date::DAY); if (isset($profiler)) { Profiler::stop($profiler); } return View::factory('userguide/api/menu')->bind('menu', $menu); }
public function action_api() { // Enable the missing class autoloader. If a class cannot be found a // fake class will be created that extends Kodoc_Missing spl_autoload_register(array('Kodoc_Missing', 'create_class')); // Get the class from the request $class = $this->request->param('class'); // If no class was passed to the url, display the API index page if (!$class) { $this->template->title = 'Table of Contents'; $this->template->content = View::factory('userguide/api/toc')->set('classes', Kodoc::class_methods())->set('route', $this->request->route()); } else { // Create the Kodoc_Class version of this class. $_class = Kodoc_Class::factory($class); // If the class requested and the actual class name are different // (different case, orm vs ORM, auth vs Auth) redirect if ($_class->class->name != $class) { $this->redirect($this->request->route()->uri(array('class' => $_class->class->name))); } // If this classes immediate parent is Kodoc_Missing, then it should 404 if ($_class->class->getParentClass() and $_class->class->getParentClass()->name == 'Kodoc_Missing') { return $this->error('That class was not found. Check your url and make sure that the module with that class is enabled.'); } // If this classes package has been disabled via the config, 404 if (!Kodoc::show_class($_class)) { return $this->error('That class is in package that is hidden. Check the <code>api_packages</code> config setting.'); } // Everything is fine, display the class. $this->template->title = $class; $this->template->content = View::factory('userguide/api/class')->set('doc', $_class)->set('route', $this->request->route()); } // Attach the menu to the template $this->template->menu = Kodoc::menu(); // Bind the breadcrumb $this->template->bind('breadcrumb', $breadcrumb); // Add the breadcrumb $breadcrumb = array(); $breadcrumb[$this->guide->uri(array('page' => NULL))] = 'User Guide'; $breadcrumb[$this->request->route()->uri()] = 'API Browser'; $breadcrumb[] = $this->template->title; }
public function action_api() { // Enable the missing class autoloader spl_autoload_register(array('Kodoc_Missing', 'create_class')); // Get the class from the request $class = $this->request->param('class'); if ($class) { try { $_class = Kodoc_Class::factory($class); if (!Kodoc::show_class($_class)) { throw new Exception(__('That class is hidden')); } } catch (Exception $e) { return $this->error(__('API Reference: Class not found.')); } $this->template->title = $class; $this->template->content = View::factory('userguide/api/class')->set('doc', Kodoc::factory($class))->set('route', $this->request->route); } else { $this->template->title = __('Table of Contents'); $this->template->content = View::factory('userguide/api/toc')->set('classes', Kodoc::class_methods())->set('route', $this->request->route); } // Attach the menu to the template $this->template->menu = Kodoc::menu(); // Bind the breadcrumb $this->template->bind('breadcrumb', $breadcrumb); // Get the docs URI $guide = Route::get('docs/guide'); // Add the breadcrumb $breadcrumb = array(); $breadcrumb[$this->guide->uri(array('page' => NULL))] = __('User Guide'); $breadcrumb[$this->request->route->uri()] = $this->title('api'); $breadcrumb[] = $this->template->title; }