Various cleanups

This commit is contained in:
Stéphane Goetz 2015-04-27 11:57:44 +02:00
parent 976db8925d
commit 36c663ac41
5 changed files with 21 additions and 53 deletions

View File

@ -4,7 +4,6 @@
"author": "Justin Walsh", "author": "Justin Walsh",
"image": "app.png", "image": "app.png",
"theme": "daux-blue", "theme": "daux-blue",
"template": "default",
"clean_urls": true, "clean_urls": true,
"toggle_code": true, "toggle_code": true,
"breadcrumbs": true, "breadcrumbs": true,

View File

@ -2,30 +2,6 @@
class DauxHelper class DauxHelper
{ {
public static function getBreadcrumbFromRequest($request, $separator = 'Chevrons', $multilanguage = false)
{
if ($multilanguage) {
$request = substr($request, strpos($request, '/') + 1);
}
$request = str_replace('_', ' ', $request);
switch ($separator) {
case 'Chevrons':
$request = str_replace('/', ' <i class="glyphicon glyphicon-chevron-right"></i> ', $request);
return $request;
case 'Colons':
$request = str_replace('/', ': ', $request);
return $request;
case 'Spaces':
$request = str_replace('/', ' ', $request);
return $request;
default:
$request = str_replace('/', $separator, $request);
return $request;
}
return $request;
}
public static function getTheme($theme_name, $base_url, $local_base, $current_url) public static function getTheme($theme_name, $base_url, $local_base, $current_url)
{ {
$theme_folder = $local_base . DS . 'resources' . DS . 'themes' . DS . $theme_name; $theme_folder = $local_base . DS . 'resources' . DS . 'themes' . DS . $theme_name;

View File

@ -8,7 +8,6 @@ class MarkdownPage extends SimplePage
private $params; private $params;
private $language; private $language;
private $homepage; private $homepage;
private $breadcrumb_trail;
public function __construct() public function __construct()
{ {
@ -33,17 +32,13 @@ class MarkdownPage extends SimplePage
$minimum_parent_dir_size = ($params['multilanguage']) ? 2 : 1; $minimum_parent_dir_size = ($params['multilanguage']) ? 2 : 1;
if (count($file->getParents()) >= $minimum_parent_dir_size) { if (count($file->getParents()) >= $minimum_parent_dir_size) {
$parents = $file->getParents(); $parents = $file->getParents();
$parent = end($parents); $this->title = end($parents)->getTitle();
$this->title = $parent->getTitle();
} else { } else {
$this->homepage = ($this->file->getName() === '_index'); $this->homepage = ($this->file->getName() === '_index');
$this->title = $params['title']; $this->title = $params['title'];
} }
} }
if ($params['breadcrumbs']) {
$this->breadcrumb_trail = $this->buildBreadcrumbTrail($file->getParents(), $params['multilanguage']);
}
$this->language = ''; $this->language = '';
if ($params['multilanguage'] && count($file->getParents())) { if ($params['multilanguage'] && count($file->getParents())) {
reset($file->getParents()); reset($file->getParents());
@ -52,7 +47,7 @@ class MarkdownPage extends SimplePage
} }
} }
private function buildBreadcrumbTrail($parents, $multilanguage) private function getBreadcrumbTrail($parents, $multilanguage)
{ {
if ($multilanguage && !empty($parents)) { if ($multilanguage && !empty($parents)) {
$parents = array_splice($parents, 1); $parents = array_splice($parents, 1);
@ -93,22 +88,24 @@ class MarkdownPage extends SimplePage
$entry_page[$params['entry_page']->title] = $params['base_page'] . $params['entry_page']->getUrl(); $entry_page[$params['entry_page']->title] = $params['base_page'] . $params['entry_page']->getUrl();
} }
$page['entry_page'] = $entry_page; $page = [
$page['homepage'] = $this->homepage; 'entry_page' => $entry_page,
$page['title'] = $this->file->getTitle(); 'homepage' => $this->homepage,
$page['filename'] = $this->file->getName(); 'title' => $this->file->getTitle(),
if ($page['breadcrumbs'] = $params['breadcrumbs']) { 'filename' => $this->file->getName(),
$page['breadcrumb_trail'] = $this->breadcrumb_trail; 'language' => $this->language,
'path' => $this->file->getPath(),
'modified_time' => filemtime($this->file->getPath()),
'markdown' => $this->content,
'request' => $params['request'],
'content' => (new \Parsedown())->text($this->content),
'breadcrumbs' => $params['breadcrumbs']
];
if ($page['breadcrumbs']) {
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params['multilanguage']);
$page['breadcrumb_separator'] = $params['breadcrumb_separator']; $page['breadcrumb_separator'] = $params['breadcrumb_separator'];
} }
$page['language'] = $this->language;
$page['path'] = $this->file->getPath();
$page['modified_time'] = filemtime($this->file->getPath());
$page['markdown'] = $this->content;
$page['request'] = $params['request'];
$Parsedown = new \Parsedown();
$page['content'] = $Parsedown->text($this->content);
$template = new Template($params['templates'], $params['theme']['templates']); $template = new Template($params['templates'], $params['theme']['templates']);
return $template->render($this->homepage? 'home' : 'content', ['page' => $page, 'params' => $params]); return $template->render($this->homepage? 'home' : 'content', ['page' => $page, 'params' => $params]);

View File

@ -4,7 +4,6 @@ use League\Plates\Engine;
class Template class Template
{ {
protected $engine; protected $engine;
public function __construct($base, $theme) public function __construct($base, $theme)
@ -61,7 +60,6 @@ class Template
{ {
$nav = ""; $nav = "";
foreach ($entries as $entry) { foreach ($entries as $entry) {
if (array_key_exists('children', $entry)) { if (array_key_exists('children', $entry)) {
if (array_key_exists('href', $entry)) { if (array_key_exists('href', $entry)) {
$link = '<a href="' . $entry['href'] . '" class="folder">' . $entry['title'] . '</a>'; $link = '<a href="' . $entry['href'] . '" class="folder">' . $entry['title'] . '</a>';
@ -106,7 +104,7 @@ class Template
'class' => (strpos($current_url, $link) === 0)? 'open' : '', 'class' => (strpos($current_url, $link) === 0)? 'open' : '',
]; ];
if ($mode === \TodayMade\Daux\Daux::STATIC_MODE) { if ($mode === Daux::STATIC_MODE) {
$link .= "/index.html"; $link .= "/index.html";
} }

View File

@ -24,8 +24,6 @@
<![endif]--> <![endif]-->
</head> </head>
<body> <body>
<?= $this->section('content'); ?> <?= $this->section('content'); ?>
<?php if ($params['google_analytics']) { <?php if ($params['google_analytics']) {