routes.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Load the Markdown library.
  4. */
  5. require_once __DIR__.'/libraries/markdown.php';
  6. /**
  7. * Get the root path for the documentation Markdown.
  8. *
  9. * @return string
  10. */
  11. function doc_root()
  12. {
  13. return path('sys').'documentation/';
  14. }
  15. /**
  16. * Get the parsed Markdown contents of a given page.
  17. *
  18. * @param string $page
  19. * @return string
  20. */
  21. function document($page)
  22. {
  23. return Markdown(file_get_contents(doc_root().$page.'.md'));
  24. }
  25. /**
  26. * Determine if a documentation page exists.
  27. *
  28. * @param string $page
  29. * @return bool
  30. */
  31. function document_exists($page)
  32. {
  33. return file_exists(doc_root().$page.'.md');
  34. }
  35. /**
  36. * Attach the sidebar to the documentation template.
  37. */
  38. View::composer('docs::template', function($view)
  39. {
  40. $view->with('sidebar', document('contents'));
  41. });
  42. /**
  43. * Handle the documentation homepage.
  44. *
  45. * This page contains the "introduction" to Laravel.
  46. */
  47. Route::get('(:bundle)', function()
  48. {
  49. return View::make('docs::page')->with('content', document('home'));
  50. });
  51. /**
  52. * Handle documentation routes for sections and pages.
  53. *
  54. * @param string $section
  55. * @param string $page
  56. * @return mixed
  57. */
  58. Route::get('(:bundle)/(:any)/(:any?)', function($section, $page = null)
  59. {
  60. $file = rtrim(implode('/', func_get_args()), '/');
  61. // If no page was specified, but a "home" page exists for the section,
  62. // we'll set the file to the home page so that the proper page is
  63. // displayed back out to the client for the requested doc page.
  64. if (is_null($page) and document_exists($file.'/home'))
  65. {
  66. $file .= '/home';
  67. }
  68. if (document_exists($file))
  69. {
  70. return View::make('docs::page')->with('content', document($file));
  71. }
  72. else
  73. {
  74. return Response::error('404');
  75. }
  76. });