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", "tagline": "The Easiest Way To Document Your Project",
"author": "Justin Walsh", "author": "Justin Walsh",
"image": "app.png", "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": { "ignore": {
"files": ["Work_In_Progress.md"], "files": ["Work_In_Progress.md"],
"folders": ["99_Not_Ready"] "folders": ["99_Not_Ready"]
}, },
"twitter": ["justin_walsh", "todaymade"], "live": {
"google_analytics": "UA-12653604-10", "clean_urls": true
"links": { },
"Download": "https://github.com/justinwalsh/daux.io/archive/master.zip", "html": {
"GitHub Repo": "https://github.com/justinwalsh/daux.io", "theme": "daux-blue",
"Help/Support/Bugs": "https://github.com/justinwalsh/daux.io/issues", "breadcrumbs": true,
"Made by Todaymade": "http://todaymade.com" "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", "docs_directory": "docs",
"valid_markdown_extensions": ["md", "markdown"], "valid_content_extensions": ["md", "markdown"],
"title": "My Project", "title": "My Project",
"tagline": "My Stylish Documentation", "tagline": "My Stylish Documentation",
"author": "I, Me & Myself", "author": "I, Me & Myself",
"image": "", "image": "",
"repo": "",
"twitter": [],
"links": {
},
"languages": {}, "languages": {},
"theme": "daux-blue",
"ignore": { "ignore": {
"files": [], "files": [],
"folders": [] "folders": []
}, },
"breadcrumbs": false,
"clean_urls": false,
"toggle_code": false,
"date_modified": false,
"float": false,
"timezone": "America/Los_Angeles", "timezone": "America/Los_Angeles",
"google_analytics": false, "live": {
"piwik_analytics": false, "clean_urls": false
"piwik_analytics_id": "0" },
"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) public function merge($newValues, $override = true)
{ {
foreach ($newValues as $key => $value) { 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; 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 STATIC_MODE = 'DAUX_STATIC';
const LIVE_MODE = 'DAUX_LIVE'; const LIVE_MODE = 'DAUX_LIVE';
/** @var string[] */
public static $VALID_MARKDOWN_EXTENSIONS;
/** @var string */ /** @var string */
public $local_base; public $local_base;
@ -85,7 +82,7 @@ class Daux
{ {
$default_config = [ $default_config = [
'docs_directory' => 'docs', 'docs_directory' => 'docs',
'valid_markdown_extensions' => ['md', 'markdown'] 'valid_content_extensions' => ['md', 'markdown']
]; ];
$global_config_file = $this->local_base . DS . 'global.json'; $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); 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 = new Config();
$this->options->merge($default_config); $this->options->merge($default_config);
} }
@ -173,7 +168,6 @@ class Daux
'multilanguage' => !empty($this->options['languages']), 'multilanguage' => !empty($this->options['languages']),
//Paths and tree //Paths and tree
'theme-name' => $this->options['theme'],
'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,

View File

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

View File

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

View File

@ -77,7 +77,7 @@ class Server
DauxHelper::rebaseConfiguration($params, '//' . $this->base_url); DauxHelper::rebaseConfiguration($params, '//' . $this->base_url);
$params['base_page'] = '//' . $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/'; $params['base_page'] .= 'index.php/';
} }

View File

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

View File

@ -1,6 +1,6 @@
<?php $this->layout('theme::layout/05_page') ?> <?php $this->layout('theme::layout/05_page') ?>
<article> <article>
<?php if ($params['date_modified']) { ?> <?php if ($params['html']['date_modified']) { ?>
<div class="page-header sub-header clearfix"> <div class="page-header sub-header clearfix">
<h1><?php <h1><?php
if ($page['breadcrumbs']) echo $this->get_breadcrumb_title($page, $base_page); 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]); ?> <?php $this->insert('theme::partials/navbar_content', ['params' => $params]); ?>
</div> </div>
</div> </div>
<?php if ($params['repo']) { ?> <?php if ($params['html']['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> <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 } ?> <?php } ?>
<div class="homepage-hero well container-fluid"> <div class="homepage-hero well container-fluid">
@ -28,7 +28,7 @@
<div class="row"> <div class="row">
<div class="text-center col-sm-12"> <div class="text-center col-sm-12">
<?php <?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>'; foreach ($page['entry_page'] as $key => $node) echo '<a href="' . $node . '" class="btn btn-primary btn-hero">' . $key . '</a>';
?> ?>
</div> </div>
@ -50,17 +50,17 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-sm-5 col-sm-offset-1"> <div class="col-sm-5 col-sm-offset-1">
<?php if (!empty($params['links'])) { ?> <?php if (!empty($params['html']['links'])) { ?>
<ul class="footer-nav"> <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> </ul>
<?php } ?> <?php } ?>
</div> </div>
<div class="col-sm-5"> <div class="col-sm-5">
<div class="pull-right"> <div class="pull-right">
<?php <?php
if (!empty($params['twitter'])) { if (!empty($params['html']['twitter'])) {
foreach($params['twitter'] as $handle) { foreach($params['html']['twitter'] as $handle) {
?> ?>
<div class="twitter"> <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> <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> <body>
<?= $this->section('content'); ?> <?= $this->section('content'); ?>
<?php if ($params['google_analytics']) { <?php if ($params['html']['google_analytics']) {
$this->insert('theme::partials/google_analytics', ['analytics' => $params['google_analytics'], 'host' => array_key_exists('host', $params)? $params['host'] : '']); $this->insert('theme::partials/google_analytics', ['analytics' => $params['html']['google_analytics'], 'host' => array_key_exists('host', $params)? $params['host'] : '']);
} ?> } ?>
<?php if ($params['piwik_analytics']) { <?php if ($params['html']['piwik_analytics']) {
$this->insert('theme::partials/piwik_analytics', ['url' => $params['piwik_analytics'], 'id' => $params['piwik_analytics_id']]); $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 $this->layout('theme::layout/00_layout') ?>
<?php if ($params['repo']) { ?> <?php if ($params['html']['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> <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 } ?> <?php } ?>
<div class="container-fluid fluid-height wrapper"> <div class="container-fluid fluid-height wrapper">
<div class="navbar navbar-fixed-top hidden-print"> <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']); 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"> <div class="well well-sidebar">
<!-- Links --> <!-- Links -->
<?php foreach ($params['links'] as $name => $url) echo '<a href="' . $url . '" target="_blank">' . $name . '</a><br>'; ?> <?php foreach ($params['html']['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 if ($params['html']['toggle_code']) echo '<a href="#" id="toggleCodeBlockBtn" onclick="toggleCodeBlocks();">Show Code Blocks Inline</a><br>'; ?>
<!-- Twitter --> <!-- Twitter -->
<?php foreach ($params['twitter'] as $handle) { ?> <?php foreach ($params['html']['twitter'] as $handle) { ?>
<div class="twitter"> <div class="twitter">
<hr/> <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> <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 } ?> <?php } ?>
</div> </div>
</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"> <div class="content-page">
<?= $this->section('content'); ?> <?= $this->section('content'); ?>
</div> </div>