Esempio n. 1
0
 public static function menu()
 {
     $classes = Kodoc::classes();
     foreach ($classes as $class) {
         if (isset($classes['kohana_' . $class])) {
             // Remove extended classes
             unset($classes['kohana_' . $class]);
         }
     }
     ksort($classes);
     $menu = array();
     $route = Route::get('docs/api');
     foreach ($classes as $class) {
         $class = Kodoc::factory($class);
         $link = HTML::anchor($route->uri(array('class' => $class->class->name)), $class->class->name);
         if (isset($class->tags['package'])) {
             foreach ($class->tags['package'] as $package) {
                 $menu[$package][] = $link;
             }
         } else {
             $menu['Kohana'][] = $link;
         }
     }
     // Sort the packages
     ksort($menu);
     $output = array('<ol>');
     foreach ($menu as $package => $list) {
         // Sort the class list
         sort($list);
         $package = HTML::anchor($route->uri(array('class' => $package)), $package);
         $output[] = "<li>{$package}\n\t<ul><li>" . implode("</li><li>", $list) . "</li></ul>\n</li>";
     }
     $output[] = '</ol>';
     return implode("\n", $output);
 }
Esempio n. 2
0
 public static function packages()
 {
     // If we already found the packages just return them
     if (!empty(Kodoc::$packages)) {
         return Kodoc::$packages;
     }
     $files = Kodoc::classes();
     $packages = array();
     foreach ($files as $group => $classes) {
         // We have to parse config files differently
         if ($group === 'config') {
             foreach ($classes as $config) {
                 $config = Kodoc::parse_config($config);
                 if (isset($config->tags['package'])) {
                     foreach ($config->tags['package'] as $package) {
                         $packages[strtolower($package)]['configs'][$config->name] = $config->name;
                     }
                 } else {
                     $packages['unknown']['configs'][$config->name] = $config->name;
                 }
             }
         } else {
             foreach ($classes as $class) {
                 $class = Kodoc::factory($class);
                 if (isset($class->tags['package'])) {
                     foreach ($class->tags['package'] as $package) {
                         $packages[strtolower($package)][$group][$class->name] = $class->name;
                     }
                 } else {
                     $packages['unknown'][$group][$class->name] = $class->name;
                 }
             }
         }
     }
     // Sort the groups in each package
     foreach ($packages as &$package) {
         foreach ($package as &$group) {
             ksort($group);
         }
         ksort($package);
     }
     return Kodoc::$packages = $packages;
 }
Esempio n. 3
0
 public function action_api()
 {
     // Get the class from the request
     $class = $this->request->param('class', 'Kohana');
     // Set the template title
     $this->template->title = $class;
     $this->template->content = View::factory('userguide/api/class')->set('doc', Kodoc::factory($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);
     // Get the docs URI
     $guide = Route::get('docs/guide');
     // Add the breadcrumb
     $breadcrumb = array();
     $breadcrumb[$guide->uri(array('page' => NULL))] = __('User Guide');
     $breadcrumb[$this->request->route->uri()] = $this->title('api');
     $breadcrumb[] = $this->template->title;
 }
Esempio n. 4
0
 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->request->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', Kodoc::factory($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);
     // 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()] = 'API Browser';
     $breadcrumb[] = $this->template->title;
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 public static function api_menu()
 {
     $classes = Kodoc::classes();
     ksort($classes);
     $menu = array();
     $route = Route::get('jelly/docs/api');
     foreach ($classes as $class) {
         $class = Kodoc::factory($class);
         $link = HTML::anchor($route->uri(array('class' => $class->class->name)), $class->class->name);
         // Only include classes in the Jelly or Jelly Test packages
         if (isset($class->tags['package'])) {
             foreach ($class->tags['package'] as $package) {
                 if (in_array($package, array('Jelly', 'Jelly Test'))) {
                     $menu[$package][] = $link;
                 }
             }
         }
     }
     // Sort the packages
     ksort($menu);
     $output = array('<ol>');
     foreach ($menu as $package => $list) {
         // Sort the class list
         sort($list);
         $output[] = "<li><strong>{$package}</strong>\n\t<ul><li>" . implode("</li><li>", $list) . "</li></ul>\n</li>";
     }
     $output[] = '</ol>';
     return implode("\n", $output);
 }