Change configuration format

This commit is contained in:
Stéphane Goetz 2015-07-19 16:36:34 +02:00
parent f757e88040
commit c00dfac001
12 changed files with 94 additions and 68 deletions

View File

@ -3,24 +3,29 @@
"tagline": "The Easiest Way To Document Your Project",
"author": "Justin Walsh",
"image": "app.png",
"theme": "daux-blue",
"clean_urls": true,
"toggle_code": true,
"breadcrumbs": true,
"breadcrumb_separator": "Chevrons",
"date_modified": true,
"float": true,
"repo": "justinwalsh/daux.io",
"ignore": {
"files": ["Work_In_Progress.md"],
"folders": ["99_Not_Ready"]
},
"twitter": ["justin_walsh", "todaymade"],
"google_analytics": "UA-12653604-10",
"links": {
"Download": "https://github.com/justinwalsh/daux.io/archive/master.zip",
"GitHub Repo": "https://github.com/justinwalsh/daux.io",
"Help/Support/Bugs": "https://github.com/justinwalsh/daux.io/issues",
"Made by Todaymade": "http://todaymade.com"
"live": {
"clean_urls": true
},
"html": {
"theme": "daux-blue",
"breadcrumbs": true,
"breadcrumb_separator": "Chevrons",
"toggle_code": true,
"date_modified": true,
"float": true,
"repo": "justinwalsh/daux.io",
"twitter": ["justin_walsh", "todaymade"],
"google_analytics": "UA-12653604-10",
"links": {
"Download": "https://github.com/justinwalsh/daux.io/archive/master.zip",
"GitHub Repo": "https://github.com/justinwalsh/daux.io",
"Help/Support/Bugs": "https://github.com/justinwalsh/daux.io/issues",
"Made by Todaymade": "http://todaymade.com"
}
}
}

View File

@ -1,31 +1,42 @@
{
"docs_directory": "docs",
"valid_markdown_extensions": ["md", "markdown"],
"valid_content_extensions": ["md", "markdown"],
"title": "My Project",
"tagline": "My Stylish Documentation",
"author": "I, Me & Myself",
"image": "",
"repo": "",
"twitter": [],
"links": {
},
"languages": {},
"theme": "daux-blue",
"ignore": {
"files": [],
"folders": []
},
"breadcrumbs": false,
"clean_urls": false,
"toggle_code": false,
"date_modified": false,
"float": false,
"timezone": "America/Los_Angeles",
"google_analytics": false,
"piwik_analytics": false,
"piwik_analytics_id": "0"
"live": {
"clean_urls": false
},
"html": {
"theme": "daux-blue",
"breadcrumbs": false,
"toggle_code": false,
"date_modified": false,
"float": false,
"repo": "",
"twitter": [],
"links": {
},
"google_analytics": false,
"piwik_analytics": false,
"piwik_analytics_id": "0"
},
"confluence": {
"prefix": ""
}
}

View File

@ -13,11 +13,27 @@ class Config extends ArrayObject
public function merge($newValues, $override = true)
{
foreach ($newValues as $key => $value) {
if ($override === false && array_key_exists($key, $this)) {
// If the key doesn't exist yet,
// we can simply set it.
if (!array_key_exists($key, $this)) {
$this[$key] = $value;
continue;
}
$this[$key] = $value;
// We already know this value exists
// so if we're in conservative mode
// we can skip this key
if ($override === false) {
continue;
}
// Merge the values only if
// both values are arrays
if (is_array($this[$key]) && is_array($value)) {
$this[$key] = array_replace_recursive($this[$key], $value);
} else {
$this[$key] = $value;
}
}
}

View File

@ -9,9 +9,6 @@ class Daux
const STATIC_MODE = 'DAUX_STATIC';
const LIVE_MODE = 'DAUX_LIVE';
/** @var string[] */
public static $VALID_MARKDOWN_EXTENSIONS;
/** @var string */
public $local_base;
@ -85,7 +82,7 @@ class Daux
{
$default_config = [
'docs_directory' => 'docs',
'valid_markdown_extensions' => ['md', 'markdown']
'valid_content_extensions' => ['md', 'markdown']
];
$global_config_file = $this->local_base . DS . 'global.json';
@ -104,8 +101,6 @@ class Daux
throw new Exception('The Docs directory does not exist. Check the path again : ' . $this->docs_path);
}
static::$VALID_MARKDOWN_EXTENSIONS = $default_config['valid_markdown_extensions'];
$this->options = new Config();
$this->options->merge($default_config);
}
@ -173,7 +168,6 @@ class Daux
'multilanguage' => !empty($this->options['languages']),
//Paths and tree
'theme-name' => $this->options['theme'],
'mode' => $this->mode,
'local_base' => $this->local_base,
'docs_path' => $this->docs_path,

View File

@ -7,7 +7,7 @@ class DauxHelper
public static function rebaseConfiguration(Config $config, $base_url)
{
// Avoid changing the url if it is already correct
if ($config['base_url'] == $base_url && !empty($config['theme']) && !is_string($config['theme'])) {
if ($config['base_url'] == $base_url && !empty($config['theme'])) {
return;
}
@ -24,8 +24,8 @@ class DauxHelper
*/
public static function getTheme($params, $current_url)
{
$theme_folder = $params['local_base'] . DS . 'resources' . DS . 'themes' . DS . $params['theme-name'];
$theme_url = $params['base_url'] . "resources/themes/" . $params['theme-name'] . '/';
$theme_folder = $params['local_base'] . DS . 'resources' . DS . 'themes' . DS . $params['html']['theme'];
$theme_url = $params['base_url'] . "resources/themes/" . $params['html']['theme'] . '/';
$theme = array();
if (is_file($theme_folder . DS . "config.json")) {
@ -37,7 +37,7 @@ class DauxHelper
//Default parameters for theme
$theme += [
'name' => $params['theme-name'],
'name' => $params['html']['theme'],
'css' => [],
'js' => [],
'fonts' => [],

View File

@ -73,12 +73,12 @@ class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage
'markdown' => $this->content,
'request' => $params['request'],
'content' => $this->convertPage($this->content),
'breadcrumbs' => $params['breadcrumbs']
'breadcrumbs' => $params['html']['breadcrumbs']
];
if ($page['breadcrumbs']) {
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params['multilanguage']);
$page['breadcrumb_separator'] = $params['breadcrumb_separator'];
$page['breadcrumb_separator'] = $params['html']['breadcrumb_separator'];
}
$template = new Template($params['templates'], $params['theme']['templates']);

View File

@ -77,7 +77,7 @@ class Server
DauxHelper::rebaseConfiguration($params, '//' . $this->base_url);
$params['base_page'] = '//' . $this->base_url;
if (!$this->daux->options['clean_urls']) {
if (!$this->daux->options['live']['clean_urls']) {
$params['base_page'] .= 'index.php/';
}

View File

@ -58,7 +58,9 @@ class Builder
{
$name = DauxHelper::pathinfo($path)['filename'];
if (!in_array(pathinfo($path, PATHINFO_EXTENSION), Daux::$VALID_MARKDOWN_EXTENSIONS)) {
$config = $parent->getConfig();
if (!in_array(pathinfo($path, PATHINFO_EXTENSION), $config['valid_content_extensions'])) {
$entry = new Raw($parent, static::getUriFromFilename(static::getFilename($path)), $path, filemtime($path));
$entry->setTitle(static::getTitleFromFilename($name));
$entry->setName($name);
@ -66,8 +68,6 @@ class Builder
return $entry;
}
$config = $parent->getConfig();
$uri = static::getUriFromFilename($name);
if ($config['mode'] === Daux::STATIC_MODE) {
$uri .= '.html';

View File

@ -1,6 +1,6 @@
<?php $this->layout('theme::layout/05_page') ?>
<article>
<?php if ($params['date_modified']) { ?>
<?php if ($params['html']['date_modified']) { ?>
<div class="page-header sub-header clearfix">
<h1><?php
if ($page['breadcrumbs']) echo $this->get_breadcrumb_title($page, $base_page);

View File

@ -4,8 +4,8 @@
<?php $this->insert('theme::partials/navbar_content', ['params' => $params]); ?>
</div>
</div>
<?php if ($params['repo']) { ?>
<a href="https://github.com/<?php echo $params['repo']; ?>" target="_blank" id="github-ribbon" class="hidden-print"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<?php if ($params['html']['repo']) { ?>
<a href="https://github.com/<?php echo $params['html']['repo']; ?>" target="_blank" id="github-ribbon" class="hidden-print"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<?php } ?>
<div class="homepage-hero well container-fluid">
@ -28,7 +28,7 @@
<div class="row">
<div class="text-center col-sm-12">
<?php
if ($params['repo']) echo '<a href="https://github.com/' . $params['repo'] . '" class="btn btn-secondary btn-hero">View On GitHub</a>';
if ($params['html']['repo']) echo '<a href="https://github.com/' . $params['html']['repo'] . '" class="btn btn-secondary btn-hero">View On GitHub</a>';
foreach ($page['entry_page'] as $key => $node) echo '<a href="' . $node . '" class="btn btn-primary btn-hero">' . $key . '</a>';
?>
</div>
@ -50,17 +50,17 @@
<div class="container">
<div class="row">
<div class="col-sm-5 col-sm-offset-1">
<?php if (!empty($params['links'])) { ?>
<?php if (!empty($params['html']['links'])) { ?>
<ul class="footer-nav">
<?php foreach ($params['links'] as $name => $url) echo '<li><a href="' . $url . '" target="_blank">' . $name . '</a></li>'; ?>
<?php foreach ($params['html']['links'] as $name => $url) echo '<li><a href="' . $url . '" target="_blank">' . $name . '</a></li>'; ?>
</ul>
<?php } ?>
</div>
<div class="col-sm-5">
<div class="pull-right">
<?php
if (!empty($params['twitter'])) {
foreach($params['twitter'] as $handle) {
if (!empty($params['html']['twitter'])) {
foreach($params['html']['twitter'] as $handle) {
?>
<div class="twitter">
<iframe allowtransparency="true" frameborder="0" scrolling="no" style="width:162px; height:20px;" src="https://platform.twitter.com/widgets/follow_button.html?screen_name=<?php echo $handle;?>&amp;show_count=false"></iframe>

View File

@ -26,11 +26,11 @@
<body>
<?= $this->section('content'); ?>
<?php if ($params['google_analytics']) {
$this->insert('theme::partials/google_analytics', ['analytics' => $params['google_analytics'], 'host' => array_key_exists('host', $params)? $params['host'] : '']);
<?php if ($params['html']['google_analytics']) {
$this->insert('theme::partials/google_analytics', ['analytics' => $params['html']['google_analytics'], 'host' => array_key_exists('host', $params)? $params['host'] : '']);
} ?>
<?php if ($params['piwik_analytics']) {
$this->insert('theme::partials/piwik_analytics', ['url' => $params['piwik_analytics'], 'id' => $params['piwik_analytics_id']]);
<?php if ($params['html']['piwik_analytics']) {
$this->insert('theme::partials/piwik_analytics', ['url' => $params['html']['piwik_analytics'], 'id' => $params['html']['piwik_analytics_id']]);
} ?>

View File

@ -1,7 +1,7 @@
<?php $this->layout('theme::layout/00_layout') ?>
<?php if ($params['repo']) { ?>
<a href="https://github.com/<?php echo $params['repo']; ?>" target="_blank" id="github-ribbon" class="hidden-print"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<?php if ($params['html']['repo']) { ?>
<a href="https://github.com/<?php echo $params['html']['repo']; ?>" target="_blank" id="github-ribbon" class="hidden-print"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<?php } ?>
<div class="container-fluid fluid-height wrapper">
<div class="navbar navbar-fixed-top hidden-print">
@ -26,15 +26,15 @@
else echo $this->get_navigation($tree, '', isset($params['request'])? $params['request'] : '', $base_page, $params['mode']);
?>
<?php if (!empty($params['links']) || !empty($params['twitter']) || $params['toggle_code']) { ?>
<?php if (!empty($params['html']['links']) || !empty($params['html']['twitter']) || $params['html']['toggle_code']) { ?>
<div class="well well-sidebar">
<!-- Links -->
<?php foreach ($params['links'] as $name => $url) echo '<a href="' . $url . '" target="_blank">' . $name . '</a><br>'; ?>
<?php if ($params['toggle_code']) echo '<a href="#" id="toggleCodeBlockBtn" onclick="toggleCodeBlocks();">Show Code Blocks Inline</a><br>'; ?>
<?php foreach ($params['html']['links'] as $name => $url) echo '<a href="' . $url . '" target="_blank">' . $name . '</a><br>'; ?>
<?php if ($params['html']['toggle_code']) echo '<a href="#" id="toggleCodeBlockBtn" onclick="toggleCodeBlocks();">Show Code Blocks Inline</a><br>'; ?>
<!-- Twitter -->
<?php foreach ($params['twitter'] as $handle) { ?>
<?php foreach ($params['html']['twitter'] as $handle) { ?>
<div class="twitter">
<hr/>
<iframe allowtransparency="true" frameborder="0" scrolling="no" style="width:162px; height:20px;" src="https://platform.twitter.com/widgets/follow_button.html?screen_name=<?php echo $handle;?>&amp;show_count=false"></iframe>
@ -44,7 +44,7 @@
<?php } ?>
</div>
</div>
<div class="right-column <?php echo ($params['float']?'float-view':''); ?> content-area col-sm-9">
<div class="right-column <?php echo ($params['html']['float']?'float-view':''); ?> content-area col-sm-9">
<div class="content-page">
<?= $this->section('content'); ?>
</div>