Ejemplo n.º 1
0
 public function before()
 {
     if ($this->request->action === 'media') {
         // Do not template media files
         $this->auto_render = FALSE;
     } else {
         // Grab the necessary routes
         $this->media = Route::get('docs/media');
         $this->api = Route::get('docs/api');
         $this->guide = Route::get('docs/guide');
         if (isset($_GET['lang'])) {
             $lang = $_GET['lang'];
             // Load the accepted language list
             $translations = array_keys(Kohana::message('userguide', 'translations'));
             if (in_array($lang, $translations)) {
                 // Set the language cookie
                 Cookie::set('userguide_language', $lang, Date::YEAR);
             }
             // Reload the page
             $this->request->redirect($this->request->uri);
         }
         // Set the translation language
         I18n::$lang = Cookie::get('userguide_language', Kohana::config('userguide')->lang);
         // Use customized Markdown parser
         define('MARKDOWN_PARSER_CLASS', 'Kodoc_Markdown');
         // Load Markdown support
         require Kohana::find_file('vendor', 'markdown/markdown');
         // Set the base URL for links and images
         Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/';
         Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/';
     }
     parent::before();
 }
Ejemplo n.º 2
0
 public function __construct()
 {
     parent::__construct();
     // Create a custom 404 handler for this controller
     Event::clear('system.404', array('Kohana_404_Exception', 'trigger'));
     Event::add('system.404', array($this, 'error'));
     // Do we have anything cached?
     if (Kohana::config('userguide.cache')) {
         $this->cache = Cache::instance();
     }
     if (Router::$method === 'media') {
         // Do not template media files
         $this->auto_render = FALSE;
     }
     // Use customized Markdown parser
     define('MARKDOWN_PARSER_CLASS', 'Kodoc_Markdown');
     // Load Markdown support
     require Kohana::find_file('vendor', 'markdown', TRUE);
     // Set the base URL for links and images
     Kodoc_Markdown::$base_url = url::site('userguide') . '/';
     Kodoc_Markdown::$image_url = url::site('userguide/media') . '/';
     // Disable eAccelerator, it messes with	the ReflectionClass->getDocComments() calls
     ini_set('eaccelerator.enable', 0);
     // Bind the breadcrumb
     $this->template->bind('breadcrumb', $this->breadcrumb);
     // Add the breadcrumb
     $this->breadcrumb = array();
     $this->breadcrumb['userguide'] = 'User Guide';
     if ($this->package = URI::instance()->segment(3)) {
         $this->breadcrumb['userguide/guide/' . $this->package] = ucfirst($this->package);
     }
 }
Ejemplo n.º 3
0
 public function action_docs()
 {
     $module = $this->request->param('module');
     $page = $this->request->param('page');
     // Trim trailing slash
     $page = rtrim($page, '/');
     // If no module provided in the url, show the user guide index page, which lists the modules.
     if (!$module) {
         return $this->index();
     }
     // If this module's userguide pages are disabled, show the error page
     if (!Kohana::$config->load('userguide.modules.' . $module . '.enabled')) {
         return $this->error(__('That module doesn\'t exist, or has userguide pages disabled.'));
     }
     // Prevent "guide/module" and "guide/module/index" from having duplicate content
     if ($page == 'index') {
         return $this->error(__('Userguide page not found'));
     }
     // If a module is set, but no page was provided in the url, show the index page
     if (!$page) {
         $page = 'index';
     }
     // Find the markdown file for this page
     $file = $this->file($module . '/' . $page);
     // If it's not found, show the error page
     if (!$file) {
         return $this->error(__('Userguide page not found'));
     }
     // Namespace the markdown parser
     Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/' . $module . '/';
     Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/' . $module . '/';
     // Set the page title
     $this->template->title = $page == 'index' ? Kohana::$config->load('userguide.modules.' . $module . '.name') : $this->title($page);
     // Parse the page contents into the template
     Kodoc_Markdown::$show_toc = true;
     $this->template->content = Markdown(file_get_contents($file));
     Kodoc_Markdown::$show_toc = false;
     // Attach this module's menu to the template
     $this->template->menu = View::factory('userguide/doc/menu')->set('menu', Markdown($this->_get_all_menu_markdown()));
     // Bind the copyright
     $this->template->copyright = Kohana::$config->load('userguide.modules.' . $module . '.copyright');
     // Add the breadcrumb trail
     $this->breadcrumbs->add(__('User Guide'), $this->guide->uri())->add(Kohana::$config->load('userguide.modules.' . $module . '.name'), $this->guide->uri(array('module' => $module)));
 }
Ejemplo n.º 4
0
 public function action_api()
 {
     // Reset the base URL for links with new routes
     Kodoc_Markdown::$base_url = URL::site($this->api->uri()) . '/';
     // Get the class from the request
     $class = $this->request->param('class');
     if (!$class) {
         // Redirect to Jelly class to ensure menu is open
         $this->request->redirect($this->api->uri(array('class' => 'Jelly')));
     }
     // 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 = self::api_menu();
     // Bind the breadcrumb
     $this->template->bind('breadcrumb', $breadcrumb);
     // Add the breadcrumb
     $breadcrumb = array();
     $breadcrumb['/'] = __('Jelly Home');
     $breadcrumb[$this->guide->uri(array('page' => NULL))] = __('User Guide');
     $breadcrumb[$this->request->route->uri()] = __('API Reference');
     $breadcrumb[] = $this->template->title;
 }
Ejemplo n.º 5
0
 public function action_docs()
 {
     $module = $this->request->param('module');
     $page = $this->request->param('page');
     // Trim trailing slash
     $page = rtrim($page, '/');
     // If no module provided in the url, show the user guide index page, which lists the modules.
     if (!$module) {
         return $this->index();
     }
     // If this module's userguide pages are disabled, show the error page
     if (!Kohana::$config->load('userguide.modules.' . $module . '.enabled')) {
         return $this->error('That module doesn\'t exist, or has userguide pages disabled.');
     }
     // Prevent "guide/module" and "guide/module/index" from having duplicate content
     if ($page == 'index') {
         return $this->error('Userguide page not found');
     }
     // If a module is set, but no page was provided in the url, show the index page
     if (!$page) {
         $page = 'index';
     }
     // Find the markdown file for this page
     $file = $this->file($module . '/' . $page);
     // If it's not found, show the error page
     if (!$file) {
         return $this->error('Userguide page not found');
     }
     // Namespace the markdown parser
     Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/' . $module . '/';
     Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/' . $module . '/';
     // Set the page title
     $this->template->title = $page == 'index' ? Kohana::$config->load('userguide.modules.' . $module . '.name') : $this->title($page);
     // Parse the page contents into the template
     Kodoc_Markdown::$show_toc = TRUE;
     $this->template->content = Kodoc_Markdown::markdown(file_get_contents($file));
     Kodoc_Markdown::$show_toc = FALSE;
     // Attach this module's menu to the template
     $this->template->menu = Kodoc_Markdown::markdown($this->_get_all_menu_markdown());
     // Bind the breadcrumb
     $this->template->bind('breadcrumb', $breadcrumb);
     // Bind the copyright
     $this->template->copyright = Kohana::$config->load('userguide.modules.' . $module . '.copyright');
     // Add the breadcrumb trail
     $breadcrumb = array();
     $breadcrumb[$this->guide->uri()] = 'User Guide';
     $breadcrumb[$this->guide->uri(array('module' => $module))] = Kohana::$config->load('userguide.modules.' . $module . '.name');
     // TODO try and get parent category names (from menu).  Regex magic or javascript dom stuff perhaps?
     // Only add the current page title to breadcrumbs if it isn't the index, otherwise we get repeats.
     if ($page != 'index') {
         $breadcrumb[] = $this->template->title;
     }
 }