routes.php 1.65 KB
Newer Older
Dayle Rees committed
1 2
<?php

Taylor Otwell committed
3 4 5
/**
 * Load the Markdown library.
 */
Taylor Otwell committed
6 7
require_once __DIR__.'/libraries/markdown.php';

Taylor Otwell committed
8
/**
9 10 11 12 13 14 15 16 17 18
 * Get the root path for the documentation Markdown.
 *
 * @return string
 */
function doc_root()
{
	return path('sys').'documentation/';
}

/**
Taylor Otwell committed
19 20 21 22 23 24 25
 * Get the parsed Markdown contents of a given page.
 *
 * @param  string  $page
 * @return string
 */
function document($page)
{
26
	return Markdown(file_get_contents(doc_root().$page.'.md'));
Taylor Otwell committed
27 28 29 30 31 32 33 34 35 36
}

/**
 * Determine if a documentation page exists.
 *
 * @param  string  $page
 * @return bool
 */
function document_exists($page)
{
37
	return file_exists(doc_root().$page.'.md');
Taylor Otwell committed
38 39 40 41 42
}

/**
 * Attach the sidebar to the documentatoin template.
 */
Dayle Rees committed
43 44
View::composer('docs::template', function($view)
{
Taylor Otwell committed
45
	$view->with('sidebar', document('contents'));
Dayle Rees committed
46 47
});

Taylor Otwell committed
48 49 50 51 52
/**
 * Handle the documentation homepage.
 *
 * This page contains the "introduction" to Laravel.
 */
Dayle Rees committed
53 54
Route::get('(:bundle)', function()
{
Taylor Otwell committed
55
	return View::make('docs::page')->with('content', document('home'));
Dayle Rees committed
56 57
});

Taylor Otwell committed
58 59 60 61 62 63 64 65
/**
 * Handle documentation routes for sections and pages.
 *
 * @param  string  $section
 * @param  string  $page
 * @return mixed
 */
Route::get('(:bundle)/(:any)/(:any?)', function($section, $page = null)
Taylor Otwell committed
66
{
Taylor Otwell committed
67
	$file = rtrim(implode('/', func_get_args()), '/');
Taylor Otwell committed
68

Taylor Otwell committed
69 70 71 72
	// If no page was specified, but a "home" page exists for the section,
	// we'll set the file to the home page so that the proper page is
	// display back out to the client for the requested doc page.
	if (is_null($page) and document_exists($file.'/home'))
Taylor Otwell committed
73
	{
Taylor Otwell committed
74
		$file .= '/home';
Taylor Otwell committed
75
	}
Taylor Otwell committed
76 77

	if (document_exists($file))
Taylor Otwell committed
78
	{
Taylor Otwell committed
79
		return View::make('docs::page')->with('content', document($file));
Taylor Otwell committed
80 81 82 83 84
	}
	else
	{
		return Response::error('404');
	}
Taylor Otwell committed
85
});