routes.php 1.5 KB

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