template changes.

This commit is contained in:
Taylor Otwell
2012-04-03 09:17:18 -05:00
parent 2af6059457
commit 5d3cc6beb0
6 changed files with 85 additions and 99 deletions

View File

@@ -1,38 +1,75 @@
<?php
/**
* Load the Markdown library.
*/
require_once __DIR__.'/libraries/markdown.php';
/**
* Get the parsed Markdown contents of a given page.
*
* @param string $page
* @return string
*/
function document($page)
{
return Markdown(file_get_contents(path('storage').'documentation/'.$page.'.md'));
}
/**
* Determine if a documentation page exists.
*
* @param string $page
* @return bool
*/
function document_exists($page)
{
return file_exists(path('storage').'documentation/'.$page.'.md');
}
/**
* Attach the sidebar to the documentatoin template.
*/
View::composer('docs::template', function($view)
{
Asset::add('stylesheet', 'laravel/css/style.css');
Asset::add('modernizr', 'laravel/js/modernizr-2.5.3.min.js');
Asset::container('footer')->add('prettify', 'laravel/js/prettify.js');
$view->with('sidebar', Markdown(file_get_contents(path('storage').'documentation/contents.md')));
$view->with('sidebar', document('contents'));
});
/**
* Handle the documentation homepage.
*
* This page contains the "introduction" to Laravel.
*/
Route::get('(:bundle)', function()
{
return View::make('docs::home');
return View::make('docs::page')->with('content', document('home'));
});
Route::get('docs/(:any)/(:any?)', function($section, $page = null)
/**
* Handle documentation routes for sections and pages.
*
* @param string $section
* @param string $page
* @return mixed
*/
Route::get('(:bundle)/(:any)/(:any?)', function($section, $page = null)
{
$root = path('storage').'documentation/';
$file = rtrim(implode('/', func_get_args()), '/');
$file = rtrim(implode('/', array($section, $page)), '/').'.md';
if (file_exists($path = $root.$file))
// 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'))
{
$content = Markdown(file_get_contents($path));
$file .= '/home';
}
elseif (file_exists($path = $root.$section.'/home.md'))
if (document_exists($file))
{
$content = Markdown(file_get_contents($path));
return View::make('docs::page')->with('content', document($file));
}
else
{
return Response::error('404');
}
return View::make('docs::page')->with('content', $content);
});