Files
spa-api/bundles/docs/routes.php

85 lines
1.7 KiB
PHP
Raw Normal View History

2012-04-01 22:45:19 +01:00
<?php
2012-04-03 09:17:18 -05:00
/**
* Load the Markdown library.
*/
2012-04-02 11:02:09 -05:00
require_once __DIR__.'/libraries/markdown.php';
/**
* Get the root path for the documentation Markdown.
*
* @return string
*/
function doc_root()
{
return path('sys').'documentation/';
}
2012-04-03 09:17:18 -05:00
/**
* Get the parsed Markdown contents of a given page.
*
* @param string $page
* @return string
*/
function document($page)
{
return Markdown(file_get_contents(doc_root().$page.'.md'));
2012-04-03 09:17:18 -05:00
}
/**
* Determine if a documentation page exists.
*
* @param string $page
* @return bool
*/
function document_exists($page)
{
return file_exists(doc_root().$page.'.md');
2012-04-03 09:17:18 -05:00
}
/**
* Attach the sidebar to the documentatoin template.
*/
2012-04-01 22:45:19 +01:00
View::composer('docs::template', function($view)
{
2012-04-03 09:17:18 -05:00
$view->with('sidebar', document('contents'));
2012-04-01 22:45:19 +01:00
});
2012-04-03 09:17:18 -05:00
/**
* Handle the documentation homepage.
*
* This page contains the "introduction" to Laravel.
*/
2012-04-01 22:45:19 +01:00
Route::get('(:bundle)', function()
{
2012-04-03 09:17:18 -05:00
return View::make('docs::page')->with('content', document('home'));
2012-04-01 22:45:19 +01:00
});
2012-04-03 09:17:18 -05:00
/**
* Handle documentation routes for sections and pages.
*
* @param string $section
* @param string $page
* @return mixed
*/
Route::get('(:bundle)/(:any)/(:any?)', function($section, $page = null)
2012-04-02 11:02:09 -05:00
{
2012-04-03 09:17:18 -05:00
$file = rtrim(implode('/', func_get_args()), '/');
2012-04-02 11:02:09 -05:00
2012-04-03 09:17:18 -05:00
// 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'))
2012-04-02 11:19:15 -05:00
{
2012-04-03 09:17:18 -05:00
$file .= '/home';
2012-04-02 11:19:15 -05:00
}
2012-04-03 09:17:18 -05:00
if (document_exists($file))
2012-04-02 11:19:15 -05:00
{
2012-04-03 09:17:18 -05:00
return View::make('docs::page')->with('content', document($file));
2012-04-02 11:19:15 -05:00
}
else
{
return Response::error('404');
}
2012-04-02 11:02:09 -05:00
});