New templating system
This commit is contained in:
parent
de1214cbab
commit
52b679b33f
@ -22,10 +22,10 @@ module.exports = function (grunt) {
|
|||||||
report: 'min'
|
report: 'min'
|
||||||
},
|
},
|
||||||
files: {
|
files: {
|
||||||
"templates/default/themes/daux-blue/css/theme.min.css": "templates/default/themes/daux-blue/less/theme.less",
|
"resources/themes/daux-blue/css/theme.min.css": "resources/themes/daux-blue/less/theme.less",
|
||||||
"templates/default/themes/daux-green/css/theme.min.css": "templates/default/themes/daux-green/less/theme.less",
|
"resources/themes/daux-green/css/theme.min.css": "resources/themes/daux-green/less/theme.less",
|
||||||
"templates/default/themes/daux-navy/css/theme.min.css": "templates/default/themes/daux-navy/less/theme.less",
|
"resources/themes/daux-navy/css/theme.min.css": "resources/themes/daux-navy/less/theme.less",
|
||||||
"templates/default/themes/daux-red/css/theme.min.css": "templates/default/themes/daux-red/less/theme.less"
|
"resources/themes/daux-red/css/theme.min.css": "resources/themes/daux-red/less/theme.less"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4",
|
"php": ">=5.4",
|
||||||
"erusev/parsedown": "~1.0"
|
"erusev/parsedown": "~1.0",
|
||||||
|
"league/plates": "~3.1"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {"Todaymade\\Daux\\": "libs/"}
|
"psr-4": {"Todaymade\\Daux\\": "libs/"}
|
||||||
|
73
composer.lock
generated
73
composer.lock
generated
@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"_readme": [
|
"_readme": [
|
||||||
"This file locks the dependencies of your project to a known state",
|
"This file locks the dependencies of your project to a known state",
|
||||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "21bea6f01fcb0695632cbacb5a3988a1",
|
"hash": "183de90aad5bcf722f046eb01453cdc0",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "erusev/parsedown",
|
"name": "erusev/parsedown",
|
||||||
@ -43,22 +44,68 @@
|
|||||||
"parser"
|
"parser"
|
||||||
],
|
],
|
||||||
"time": "2014-05-14 10:14:49"
|
"time": "2014-05-14 10:14:49"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "league/plates",
|
||||||
|
"version": "3.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/thephpleague/plates.git",
|
||||||
|
"reference": "c39d8fbcbeb07a0948d5e1cf8d78c6e1ef3e81a8"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/thephpleague/plates/zipball/c39d8fbcbeb07a0948d5e1cf8d78c6e1ef3e81a8",
|
||||||
|
"reference": "c39d8fbcbeb07a0948d5e1cf8d78c6e1ef3e81a8",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mikey179/vfsstream": "~1.4.0",
|
||||||
|
"phpunit/phpunit": "~4.0",
|
||||||
|
"squizlabs/php_codesniffer": "~1.5"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.0-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"League\\Plates\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jonathan Reinink",
|
||||||
|
"email": "jonathan@reinink.ca",
|
||||||
|
"role": "Developer"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"description": "Plates, the native PHP template system that's fast, easy to use and easy to extend.",
|
||||||
|
"homepage": "http://platesphp.com",
|
||||||
|
"keywords": [
|
||||||
|
"league",
|
||||||
|
"package",
|
||||||
|
"templates",
|
||||||
|
"templating",
|
||||||
|
"views"
|
||||||
],
|
],
|
||||||
"aliases": [
|
"time": "2014-10-21 12:06:12"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": [
|
"stability-flags": [],
|
||||||
|
"prefer-stable": false,
|
||||||
],
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": ">=5.3"
|
"php": ">=5.4"
|
||||||
},
|
},
|
||||||
"platform-dev": [
|
"platform-dev": []
|
||||||
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
26
default.json
26
default.json
@ -3,25 +3,27 @@
|
|||||||
"tagline": "My Stylish Documentation",
|
"tagline": "My Stylish Documentation",
|
||||||
"author": "I, Me & Myself",
|
"author": "I, Me & Myself",
|
||||||
"image": "",
|
"image": "",
|
||||||
|
"repo": "",
|
||||||
|
"twitter": [],
|
||||||
|
"links": {
|
||||||
|
},
|
||||||
|
|
||||||
|
"languages": {},
|
||||||
"theme": "daux-blue",
|
"theme": "daux-blue",
|
||||||
|
"ignore": {
|
||||||
|
"files": [],
|
||||||
|
"folders": []
|
||||||
|
},
|
||||||
|
|
||||||
"breadcrumbs": false,
|
"breadcrumbs": false,
|
||||||
"template": "default",
|
|
||||||
"clean_urls": false,
|
"clean_urls": false,
|
||||||
"toggle_code": false,
|
"toggle_code": false,
|
||||||
"date_modified": false,
|
"date_modified": false,
|
||||||
"float": false,
|
"float": false,
|
||||||
"file_editor": false,
|
"file_editor": false,
|
||||||
"repo": "",
|
|
||||||
"twitter": [],
|
|
||||||
"google_analytics": "",
|
|
||||||
"timezone": "America/Los_Angeles",
|
"timezone": "America/Los_Angeles",
|
||||||
|
|
||||||
|
"google_analytics": false,
|
||||||
"piwik_analytics": false,
|
"piwik_analytics": false,
|
||||||
"piwik_analytics_id": "0",
|
"piwik_analytics_id": "0"
|
||||||
"languages": {},
|
|
||||||
"ignore": {
|
|
||||||
"files": [],
|
|
||||||
"folders": []
|
|
||||||
},
|
|
||||||
"links": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -111,36 +111,15 @@ class Daux
|
|||||||
|
|
||||||
public function getParams()
|
public function getParams()
|
||||||
{
|
{
|
||||||
$params = array(
|
$params = $this->options += array(
|
||||||
//Informations
|
|
||||||
'tagline' => $this->options['tagline'],
|
|
||||||
'title' => $this->options['title'],
|
|
||||||
'author' => $this->options['author'],
|
|
||||||
'image' => $this->options['image'],
|
|
||||||
'repo' => $this->options['repo'],
|
|
||||||
'links' => $this->options['links'],
|
|
||||||
'twitter' => $this->options['twitter'],
|
|
||||||
|
|
||||||
//Features
|
//Features
|
||||||
'google_analytics' => ($g = $this->options['google_analytics']) ?
|
|
||||||
DauxHelper::googleAnalytics($g, $this->host) : '',
|
|
||||||
'piwik_analytics' => ($p = $this->options['piwik_analytics']) ?
|
|
||||||
DauxHelper::piwikAnalytics($p, $this->options['piwik_analytics_id']) : '',
|
|
||||||
'toggle_code' => $this->options['toggle_code'],
|
|
||||||
'float' => $this->options['float'],
|
|
||||||
'date_modified' => $this->options['date_modified'],
|
|
||||||
'file_editor' => false,
|
|
||||||
'breadcrumbs' => $this->options['breadcrumbs'],
|
|
||||||
'breadcrumb_separator' => $this->options['breadcrumb_separator'],
|
|
||||||
'multilanguage' => !empty($this->options['languages']),
|
'multilanguage' => !empty($this->options['languages']),
|
||||||
'languages' => $this->options['languages'],
|
|
||||||
|
|
||||||
|
|
||||||
//Paths and tree
|
//Paths and tree
|
||||||
'mode' => $this->mode,
|
'mode' => $this->mode,
|
||||||
'local_base' => $this->local_base,
|
'local_base' => $this->local_base,
|
||||||
'docs_path' => $this->docs_path,
|
'docs_path' => $this->docs_path,
|
||||||
'template' => $this->options['template'],
|
'templates' => $this->local_base . DS . 'templates',
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($this->tree) {
|
if ($this->tree) {
|
||||||
@ -172,10 +151,10 @@ class Daux
|
|||||||
}
|
}
|
||||||
|
|
||||||
$params['theme'] = DauxHelper::getTheme(
|
$params['theme'] = DauxHelper::getTheme(
|
||||||
$this->local_base . DS . 'templates' . DS . $this->options['template'] . DS . 'themes' . DS . $this->options['theme'],
|
$this->local_base . DS . 'resources' . DS . 'themes' . DS . $this->options['theme'],
|
||||||
$params['base_url'],
|
$params['base_url'],
|
||||||
$this->local_base,
|
$this->local_base,
|
||||||
$params['base_url'] . "templates/" . $params['template'] . "/themes/" . $this->options['theme'] . '/'
|
$params['base_url'] . "resources/themes/" . $this->options['theme'] . '/'
|
||||||
);
|
);
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
|
@ -47,15 +47,13 @@ class DauxHelper
|
|||||||
'require-jquery' => false,
|
'require-jquery' => false,
|
||||||
'bootstrap-js' => false,
|
'bootstrap-js' => false,
|
||||||
'favicon' => '<base_url>resources/img/favicon.png',
|
'favicon' => '<base_url>resources/img/favicon.png',
|
||||||
'template' => $local_base . DS . 'templates' . DS . 'default/default.php',
|
'templates' => $theme_folder . DS . 'templates',
|
||||||
'error-template' => $local_base . DS . 'templates' . DS . 'default/error.php',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$substitutions = ['<local_base>' => $local_base, '<base_url>' => $base_url, '<theme_url>' => $theme_url];
|
$substitutions = ['<local_base>' => $local_base, '<base_url>' => $base_url, '<theme_url>' => $theme_url];
|
||||||
|
|
||||||
// Substitute some placeholders
|
// Substitute some placeholders
|
||||||
$theme['template'] = strtr($theme['template'], $substitutions);
|
$theme['templates'] = strtr($theme['templates'], $substitutions);
|
||||||
$theme['error-template'] = strtr($theme['error-template'], $substitutions);
|
|
||||||
$theme['favicon'] = utf8_encode(strtr($theme['favicon'], $substitutions));
|
$theme['favicon'] = utf8_encode(strtr($theme['favicon'], $substitutions));
|
||||||
|
|
||||||
foreach ($theme['css'] as $key => $css) {
|
foreach ($theme['css'] as $key => $css) {
|
||||||
@ -73,43 +71,6 @@ class DauxHelper
|
|||||||
return $theme;
|
return $theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function googleAnalytics($analytics, $host)
|
|
||||||
{
|
|
||||||
$ga = <<<EOT
|
|
||||||
<script>
|
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
||||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
||||||
EOT;
|
|
||||||
$ga .= "ga('create', '" . $analytics . "', '" . $host . "');";
|
|
||||||
$ga .= "ga('send', 'pageview');";
|
|
||||||
$ga .= '</script>';
|
|
||||||
return $ga;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function piwikAnalytics($analytics_url, $analytics_id)
|
|
||||||
{
|
|
||||||
$pa = <<<EOT
|
|
||||||
<script type="text/javascript">
|
|
||||||
var _paq = _paq || [];
|
|
||||||
_paq.push(["trackPageView"]);
|
|
||||||
_paq.push(["enableLinkTracking"]);
|
|
||||||
(function() {
|
|
||||||
EOT;
|
|
||||||
$pa .= 'var u=(("https:" == document.location.protocol) ? "https" : "http") + "://' . $analytics_url . '/";';
|
|
||||||
$pa .= '_paq.push(["setTrackerUrl", u+"piwik.php"]);';
|
|
||||||
$pa .= '_paq.push(["setSiteId", ' . $analytics_id . ']);';
|
|
||||||
$pa .= <<<EOT
|
|
||||||
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0];
|
|
||||||
g.type="text/javascript";
|
|
||||||
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
EOT;
|
|
||||||
return $pa;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function pathinfo($path)
|
public static function pathinfo($path)
|
||||||
{
|
{
|
||||||
preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $m);
|
preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $m);
|
||||||
|
@ -10,18 +10,6 @@ class Helper
|
|||||||
|
|
||||||
@mkdir($path . DS . 'resources');
|
@mkdir($path . DS . 'resources');
|
||||||
static::copyRecursive($local_base . DS . 'resources', $path . DS . 'resources');
|
static::copyRecursive($local_base . DS . 'resources', $path . DS . 'resources');
|
||||||
@mkdir($path . DS . 'js');
|
|
||||||
static::copyRecursive($local_base . DS . 'js', $path . DS . 'js');
|
|
||||||
|
|
||||||
//added and changed these in order to fetch the theme files and put them in the right place
|
|
||||||
@mkdir($path . DS . 'templates');
|
|
||||||
@mkdir($path . DS . 'templates' . DS . 'default');
|
|
||||||
@mkdir($path . DS . 'templates' . DS . 'default' . DS . 'themes');
|
|
||||||
|
|
||||||
static::copyRecursive(
|
|
||||||
$local_base . DS . 'templates' . DS . 'default' . DS . 'themes',
|
|
||||||
$path . DS . 'templates' . DS . 'default' . DS . 'themes'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function rmdir($dir)
|
private static function rmdir($dir)
|
||||||
|
@ -9,7 +9,6 @@ class MarkdownPage extends SimplePage
|
|||||||
private $language;
|
private $language;
|
||||||
private $homepage;
|
private $homepage;
|
||||||
private $breadcrumb_trail;
|
private $breadcrumb_trail;
|
||||||
private static $template;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -51,10 +50,6 @@ class MarkdownPage extends SimplePage
|
|||||||
$language_dir = current($file->getParents());
|
$language_dir = current($file->getParents());
|
||||||
$this->language = $language_dir->name;
|
$this->language = $language_dir->name;
|
||||||
}
|
}
|
||||||
if (is_null(static::$template)) {
|
|
||||||
include_once($params['theme']['template']);
|
|
||||||
static::$template = new Template();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildBreadcrumbTrail($parents, $multilanguage)
|
private function buildBreadcrumbTrail($parents, $multilanguage)
|
||||||
@ -89,20 +84,18 @@ class MarkdownPage extends SimplePage
|
|||||||
if ($params['request'] === $params['index_key']) {
|
if ($params['request'] === $params['index_key']) {
|
||||||
if ($params['multilanguage']) {
|
if ($params['multilanguage']) {
|
||||||
foreach ($params['languages'] as $key => $name) {
|
foreach ($params['languages'] as $key => $name) {
|
||||||
$entry_page[utf8_encode($name)] = utf8_encode($params['base_page'] . $params['entry_page'][$key]->getUrl());
|
$entry_page[$name] = $params['base_page'] . $params['entry_page'][$key]->getUrl();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$entry_page['View Documentation'] = utf8_encode($params['base_page'] . $params['entry_page']->getUri());
|
$entry_page['View Documentation'] = $params['base_page'] . $params['entry_page']->getUri();
|
||||||
}
|
}
|
||||||
} elseif ($params['file_uri'] === 'index') {
|
} elseif ($params['file_uri'] === 'index') {
|
||||||
$entry_page[utf8_encode($params['entry_page']->title)] = utf8_encode($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['entry_page'] = $entry_page;
|
||||||
$page['homepage'] = $this->homepage;
|
$page['homepage'] = $this->homepage;
|
||||||
$page['title'] = $this->file->getTitle();
|
$page['title'] = $this->file->getTitle();
|
||||||
$page['tagline'] = $params['tagline'];
|
|
||||||
$page['author'] = $params['author'];
|
|
||||||
$page['filename'] = $this->file->getName();
|
$page['filename'] = $this->file->getName();
|
||||||
if ($page['breadcrumbs'] = $params['breadcrumbs']) {
|
if ($page['breadcrumbs'] = $params['breadcrumbs']) {
|
||||||
$page['breadcrumb_trail'] = $this->breadcrumb_trail;
|
$page['breadcrumb_trail'] = $this->breadcrumb_trail;
|
||||||
@ -110,17 +103,13 @@ class MarkdownPage extends SimplePage
|
|||||||
}
|
}
|
||||||
$page['language'] = $this->language;
|
$page['language'] = $this->language;
|
||||||
$page['path'] = $this->file->getPath();
|
$page['path'] = $this->file->getPath();
|
||||||
$page['request'] = utf8_encode($params['request']);
|
|
||||||
$page['theme'] = $params['theme'];
|
|
||||||
$page['modified_time'] = filemtime($this->file->getPath());
|
$page['modified_time'] = filemtime($this->file->getPath());
|
||||||
$page['markdown'] = $this->content;
|
$page['markdown'] = $this->content;
|
||||||
$page['file_editor'] = $params['file_editor'];
|
|
||||||
$page['google_analytics'] = $params['google_analytics'];
|
|
||||||
$page['piwik_analytics'] = $params['piwik_analytics'];
|
|
||||||
|
|
||||||
$Parsedown = new \Parsedown();
|
$Parsedown = new \Parsedown();
|
||||||
$page['content'] = $Parsedown->text($this->content);
|
$page['content'] = $Parsedown->text($this->content);
|
||||||
|
|
||||||
return static::$template->get_content($page, $params);
|
$template = new Template($params['templates'], $params['theme']['templates']);
|
||||||
|
return $template->render($this->homepage? 'home' : 'content', ['page' => $page, 'params' => $params]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ class ErrorPage extends SimplePage
|
|||||||
const FATAL_ERROR_TYPE = 'FATAL_ERROR';
|
const FATAL_ERROR_TYPE = 'FATAL_ERROR';
|
||||||
|
|
||||||
private $params;
|
private $params;
|
||||||
private static $template;
|
|
||||||
|
|
||||||
public function __construct($title, $content, $params)
|
public function __construct($title, $content, $params)
|
||||||
{
|
{
|
||||||
@ -26,9 +25,6 @@ class ErrorPage extends SimplePage
|
|||||||
|
|
||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
include_once($this->params['theme']['error-template']);
|
|
||||||
static::$template = new Template();
|
|
||||||
|
|
||||||
if (is_null($this->html)) {
|
if (is_null($this->html)) {
|
||||||
$this->html = $this->generatePage();
|
$this->html = $this->generatePage();
|
||||||
}
|
}
|
||||||
@ -40,11 +36,9 @@ class ErrorPage extends SimplePage
|
|||||||
{
|
{
|
||||||
$params = $this->params;
|
$params = $this->params;
|
||||||
$page['title'] = $this->title;
|
$page['title'] = $this->title;
|
||||||
$page['theme'] = $params['theme'];
|
|
||||||
$page['content'] = $this->content;
|
$page['content'] = $this->content;
|
||||||
$page['google_analytics'] = $params['google_analytics'];
|
|
||||||
$page['piwik_analytics'] = $params['piwik_analytics'];
|
|
||||||
|
|
||||||
return static::$template->get_content($page, $params);
|
$template = new Template($params['templates'], $params['theme']['templates']);
|
||||||
|
return $template->render('error', ['page' => $page, 'params' => $params]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
117
libs/Template.php
Normal file
117
libs/Template.php
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
<?php namespace Todaymade\Daux;
|
||||||
|
|
||||||
|
use League\Plates\Engine;
|
||||||
|
|
||||||
|
class Template
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $engine;
|
||||||
|
|
||||||
|
public function __construct($base, $theme)
|
||||||
|
{
|
||||||
|
// Create new Plates instance
|
||||||
|
$this->engine = new Engine($base);
|
||||||
|
if (!is_dir($theme)) {
|
||||||
|
$theme = $base;
|
||||||
|
}
|
||||||
|
$this->engine->addFolder('theme', $theme, true);
|
||||||
|
|
||||||
|
$this->registerFunctions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render($name, array $data = array())
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->engine->addData([
|
||||||
|
'index' => utf8_encode($data['params']['base_page'] . $data['params']['index']->value),
|
||||||
|
'base_url' => $data['params']['base_url'],
|
||||||
|
'base_page' => $data['params']['base_page'],
|
||||||
|
'page' => $data['page'],
|
||||||
|
'params' => $data['params'],
|
||||||
|
//'homepage' => $data['params']['homepage'],
|
||||||
|
//'project_title' => utf8_encode($data['params']['title']),
|
||||||
|
'tree' => $data['params']['tree'],
|
||||||
|
//'entry_page' => $data['page']['entry_page'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->engine->render($name, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerFunctions()
|
||||||
|
{
|
||||||
|
$this->engine->registerFunction('get_navigation', function($tree, $path, $current_url, $base_page, $mode) {
|
||||||
|
$nav = '<ul class="nav nav-list">';
|
||||||
|
$nav .= $this->buildNavigation($tree, $path, $current_url, $base_page, $mode);
|
||||||
|
$nav .= '</ul>';
|
||||||
|
return $nav;
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->engine->registerFunction('get_breadcrumb_title', function($page, $base_page) {
|
||||||
|
$title = '';
|
||||||
|
$breadcrumb_trail = $page['breadcrumb_trail'];
|
||||||
|
$separator = $this->getSeparator($page['breadcrumb_separator']);
|
||||||
|
foreach ($breadcrumb_trail as $key => $value) {
|
||||||
|
$title .= '<a href="' . $base_page . $value . '">' . $key . '</a>' . $separator;
|
||||||
|
}
|
||||||
|
if ($page['filename'] === 'index' || $page['filename'] === '_index') {
|
||||||
|
if ($page['title'] != '') {
|
||||||
|
$title = substr($title, 0, -1 * strlen($separator));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$title .= '<a href="' . $base_page . $page['request'] . '">' . $page['title'] . '</a>';
|
||||||
|
}
|
||||||
|
return $title;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildNavigation($tree, $path, $current_url, $base_page, $mode)
|
||||||
|
{
|
||||||
|
$nav = '';
|
||||||
|
foreach ($tree->value as $node) {
|
||||||
|
$url = $node->getUri();
|
||||||
|
if ($node instanceof \Todaymade\Daux\Tree\Content) {
|
||||||
|
if ($node->value === 'index') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$nav .= '<li';
|
||||||
|
$link = ($path === '') ? $url : $path . '/' . $url;
|
||||||
|
if ($current_url === $link) {
|
||||||
|
$nav .= ' class="active"';
|
||||||
|
}
|
||||||
|
$nav .= '><a href="' . $base_page . $link . '">' . $node->getTitle() . '</a></li>';
|
||||||
|
}
|
||||||
|
if ($node instanceof \Todaymade\Daux\Tree\Directory) {
|
||||||
|
$nav .= '<li';
|
||||||
|
$link = ($path === '') ? $url : $path . '/' . $url;
|
||||||
|
if (strpos($current_url, $link) === 0) {
|
||||||
|
$nav .= ' class="open"';
|
||||||
|
}
|
||||||
|
$nav .= ">";
|
||||||
|
if ($mode === \TodayMade\Daux\Daux::STATIC_MODE) {
|
||||||
|
$link .= "/index.html";
|
||||||
|
}
|
||||||
|
if ($node->getIndexPage()) {
|
||||||
|
$nav .= '<a href="' . $base_page . $link . '" class="folder">' .
|
||||||
|
$node->getTitle() . '</a>';
|
||||||
|
} else {
|
||||||
|
$nav .= '<a href="#" class="aj-nav folder">' . $node->getTitle() . '</a>';
|
||||||
|
}
|
||||||
|
$nav .= '<ul class="nav nav-list">';
|
||||||
|
$new_path = ($path === '') ? $url : $path . '/' . $url;
|
||||||
|
$nav .= $this->buildNavigation($node, $new_path, $current_url, $base_page, $mode);
|
||||||
|
$nav .= '</ul></li>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $nav;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSeparator($separator)
|
||||||
|
{
|
||||||
|
switch ($separator) {
|
||||||
|
case 'Chevrons':
|
||||||
|
return ' <i class="glyphicon glyphicon-chevron-right"></i> ';
|
||||||
|
default:
|
||||||
|
return $separator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user