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