Create a "daux" binary
Refactored Daux a bit to allow generating documentation from working directory
This commit is contained in:
parent
4f5bc217e7
commit
3375f8ff2b
77
bin/daux
Executable file
77
bin/daux
Executable file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
|
||||
Daux.io
|
||||
==================
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
This is a tool for auto-generating documentation based on markdown files
|
||||
located in the /docs folder of the project. To see all of the available
|
||||
options and to read more about how to use the generator, visit:
|
||||
|
||||
http://daux.io
|
||||
|
||||
|
||||
Author
|
||||
------
|
||||
Justin Walsh (Todaymade): justin@todaymade.com, @justin_walsh
|
||||
Garrett Moon (Todaymade): garrett@todaymade.com, @garrett_moon
|
||||
|
||||
|
||||
Feedback & Suggestions
|
||||
----
|
||||
|
||||
To give us feedback or to suggest an idea, please create an request on the the
|
||||
GitHub issue tracker:
|
||||
|
||||
https://github.com/justinwalsh/daux.io/issues
|
||||
|
||||
Bugs
|
||||
----
|
||||
|
||||
To file bug reports please create an issue using the github issue tracker:
|
||||
|
||||
https://github.com/justinwalsh/daux.io/issues
|
||||
|
||||
|
||||
Copyright and License
|
||||
---------------------
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
This software is provided by the copyright holders and contributors "as
|
||||
is" and any express or implied warranties, including, but not limited
|
||||
to, the implied warranties of merchantability and fitness for a
|
||||
particular purpose are disclaimed. In no event shall the copyright owner
|
||||
or contributors be liable for any direct, indirect, incidental, special,
|
||||
exemplary, or consequential damages (including, but not limited to,
|
||||
procurement of substitute goods or services; loss of use, data, or
|
||||
profits; or business interruption) however caused and on any theory of
|
||||
liability, whether in contract, strict liability, or tort (including
|
||||
negligence or otherwise) arising in any way out of the use of this
|
||||
software, even if advised of the possibility of such damage.
|
||||
|
||||
*/
|
||||
|
||||
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
||||
require_once(__DIR__ . '/../vendor/autoload.php');
|
||||
} elseif (file_exists(__DIR__ . '/../daux.phar')) {
|
||||
define('PHAR_DIR', __DIR__ . '/..');
|
||||
require_once("phar://" . __DIR__ . "/../daux.phar/vendor/autoload.php");
|
||||
} else {
|
||||
throw new Exception("Impossible to load Daux, missing vendor/ or daux.phar");
|
||||
}
|
||||
|
||||
$application = new \Todaymade\Daux\Console\Application();
|
||||
$application->run();
|
@ -11,6 +11,7 @@
|
||||
"homepage": "http://todaymade.com/"
|
||||
}
|
||||
],
|
||||
"bin": ["bin/daux"],
|
||||
"require": {
|
||||
"php": ">=5.5",
|
||||
"league/plates": "~3.1",
|
||||
|
@ -57,4 +57,20 @@ class Config extends ArrayObject
|
||||
{
|
||||
$this['current_page'] = $entry;
|
||||
}
|
||||
|
||||
public function getDocumentationDirectory() {
|
||||
return $this['docs_directory'];
|
||||
}
|
||||
|
||||
public function setDocumentationDirectory($documentationPath) {
|
||||
$this['docs_directory'] = $documentationPath;
|
||||
}
|
||||
|
||||
public function getThemesDirectory() {
|
||||
return $this['themes_directory'];
|
||||
}
|
||||
|
||||
public function isMultilanguage() {
|
||||
return array_key_exists('languages', $this) && !empty($this['languages']);
|
||||
}
|
||||
}
|
||||
|
@ -51,13 +51,9 @@ class Generate extends SymfonyCommand
|
||||
|
||||
// Set the source directory
|
||||
if ($input->getOption('source')) {
|
||||
$daux->getParams()['docs_directory'] = $input->getOption('source');
|
||||
$daux->getParams()->setDocumentationDirectory($input->getOption('source'));
|
||||
}
|
||||
|
||||
$daux->setDocumentationPath($daux->getParams()['docs_directory']);
|
||||
|
||||
$daux->setThemesPath($daux->getParams()['themes_directory']);
|
||||
|
||||
$daux->initializeConfiguration($input->getOption('configuration'));
|
||||
|
||||
if ($input->getOption('delete')) {
|
||||
|
@ -29,12 +29,6 @@ class Daux
|
||||
*/
|
||||
protected $validExtensions;
|
||||
|
||||
/** @var string */
|
||||
private $docs_path;
|
||||
|
||||
/** @var string */
|
||||
private $themes_path;
|
||||
|
||||
/** @var Processor */
|
||||
protected $processor;
|
||||
|
||||
@ -79,14 +73,20 @@ class Daux
|
||||
*/
|
||||
public function initializeConfiguration($override_file = 'config.json')
|
||||
{
|
||||
// Validate and set theme path
|
||||
$this->getParams()->setDocumentationDirectory($docs_path = $this->normalizeDocumentationPath());
|
||||
|
||||
// Read documentation overrides
|
||||
$this->loadConfiguration($this->docs_path . DIRECTORY_SEPARATOR . 'config.json');
|
||||
$this->loadConfiguration($docs_path . DIRECTORY_SEPARATOR . 'config.json');
|
||||
|
||||
// Read command line overrides
|
||||
if (!is_null($override_file)) {
|
||||
$this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . $override_file);
|
||||
}
|
||||
|
||||
// Validate and set theme path
|
||||
$this->options['themes_path'] = $this->normalizeThemePath($this->getParams()->getThemesDirectory());
|
||||
|
||||
// Set a valid default timezone
|
||||
if (isset($this->options['timezone'])) {
|
||||
date_default_timezone_set($this->options['timezone']);
|
||||
@ -95,28 +95,27 @@ class Daux
|
||||
}
|
||||
}
|
||||
|
||||
public function setThemesPath($path)
|
||||
{
|
||||
$this->themes_path = $path;
|
||||
if (!is_dir($this->themes_path) &&
|
||||
!is_dir($this->themes_path = $this->local_base . DIRECTORY_SEPARATOR . $this->themes_path)
|
||||
) {
|
||||
throw new Exception('The Themes directory does not exist. Check the path again : ' . $this->themes_path);
|
||||
public function normalizeThemePath($path) {
|
||||
if (is_dir($path)) {
|
||||
return $path;
|
||||
}
|
||||
$this->options['themes_path'] = $this->themes_path;
|
||||
$this->options['templates'] = 'templates';
|
||||
|
||||
$newPath = $this->local_base . DIRECTORY_SEPARATOR . $path;
|
||||
if (is_dir($newPath)) {
|
||||
return $newPath;
|
||||
}
|
||||
|
||||
throw new Exception('The Themes directory does not exist. Check the path again : ' . $path);
|
||||
}
|
||||
|
||||
public function setDocumentationPath($path)
|
||||
public function normalizeDocumentationPath()
|
||||
{
|
||||
$this->docs_path = $path;
|
||||
if (!is_dir($this->docs_path) &&
|
||||
!is_dir($this->docs_path = $this->local_base . DIRECTORY_SEPARATOR . $this->docs_path)
|
||||
) {
|
||||
throw new Exception('The Docs directory does not exist. Check the path again : ' . $this->docs_path);
|
||||
$path = $this->getParams()->getDocumentationDirectory();
|
||||
if (is_dir($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$this->options['docs_path'] = $this->docs_path;
|
||||
throw new Exception('The Docs directory does not exist. Check the path again : ' . $path);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,6 +131,15 @@ class Daux
|
||||
$this->options->merge([
|
||||
'docs_directory' => 'docs',
|
||||
'valid_content_extensions' => ['md', 'markdown'],
|
||||
|
||||
//Paths and tree
|
||||
'mode' => $this->mode,
|
||||
'local_base' => $this->local_base,
|
||||
'templates' => 'templates',
|
||||
|
||||
'index_key' => 'index.html',
|
||||
'base_page' => '',
|
||||
'base_url' => '',
|
||||
]);
|
||||
|
||||
// Load the global configuration
|
||||
@ -167,7 +175,7 @@ class Daux
|
||||
{
|
||||
$this->options['valid_content_extensions'] = $this->getContentExtensions();
|
||||
|
||||
$this->tree = new Root($this->getParams(), $this->docs_path);
|
||||
$this->tree = new Root($this->getParams());
|
||||
Builder::build($this->tree, $this->options['ignore']);
|
||||
|
||||
if (!empty($this->options['languages'])) {
|
||||
@ -218,30 +226,10 @@ class Daux
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
if (!$this->merged_defaults) {
|
||||
$default = [
|
||||
//Features
|
||||
'multilanguage' => !empty($this->options['languages']),
|
||||
|
||||
//Paths and tree
|
||||
'mode' => $this->mode,
|
||||
'local_base' => $this->local_base,
|
||||
'docs_path' => $this->docs_path,
|
||||
'themes_path' => $this->themes_path,
|
||||
'templates' => 'templates',
|
||||
];
|
||||
$this->options->conservativeMerge($default);
|
||||
|
||||
$this->options['index_key'] = 'index.html';
|
||||
$this->options['base_page'] = $this->options['base_url'] = '';
|
||||
|
||||
$this->merged_defaults = true;
|
||||
}
|
||||
|
||||
if ($this->tree && !$this->merged_tree) {
|
||||
$this->options['tree'] = $this->tree;
|
||||
$this->options['index'] = $this->tree->getIndexPage() ?: $this->tree->getFirstPage();
|
||||
if ($this->options['multilanguage']) {
|
||||
if ($this->options->isMultilanguage()) {
|
||||
foreach ($this->options['languages'] as $key => $name) {
|
||||
$this->options['entry_page'][$key] = $this->tree->getEntries()[$key]->getFirstPage();
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class DauxHelper
|
||||
self::resolveVariant($params);
|
||||
|
||||
$theme_folder = $params['themes_path'] . DIRECTORY_SEPARATOR . $params['html']['theme'];
|
||||
$theme_url = $params['base_url'] . $params['themes_directory'] . '/' . $params['html']['theme'] . '/';
|
||||
$theme_url = $params['base_url'] . $params->getThemesDirectory() . '/' . $params['html']['theme'] . '/';
|
||||
|
||||
$theme = [];
|
||||
if (is_file($theme_folder . DIRECTORY_SEPARATOR . 'config.json')) {
|
||||
|
@ -17,7 +17,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->params['multilanguage']) {
|
||||
if ($this->params->isMultilanguage()) {
|
||||
return $this->file->getParent()->getParent() instanceof Root;
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
$this->homepage = $this->isHomepage();
|
||||
|
||||
$this->language = '';
|
||||
if ($this->params['multilanguage'] && count($this->file->getParents())) {
|
||||
if ($this->params->isMultilanguage() && count($this->file->getParents())) {
|
||||
$language_dir = $this->file->getParents()[0];
|
||||
$this->language = $language_dir->getName();
|
||||
}
|
||||
@ -63,7 +63,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
|
||||
$entry_page = [];
|
||||
if ($this->homepage) {
|
||||
if ($params['multilanguage']) {
|
||||
if ($params->isMultilanguage()) {
|
||||
foreach ($params['languages'] as $key => $name) {
|
||||
$entry_page[$name] = $params['base_page'] . $params['entry_page'][$key]->getUrl();
|
||||
}
|
||||
@ -89,7 +89,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
];
|
||||
|
||||
if ($page['breadcrumbs']) {
|
||||
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params['multilanguage']);
|
||||
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params->isMultilanguage());
|
||||
$page['breadcrumb_separator'] = $params['html']['breadcrumb_separator'];
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,14 @@ class Template
|
||||
*/
|
||||
public function __construct($base, $theme)
|
||||
{
|
||||
// Use templates from the phar archive if the templates dir doesn't exist.
|
||||
// Use internal templates or the ones in the phar
|
||||
// archive if no templates dir exists in the working directory
|
||||
if (!is_dir($base)) {
|
||||
$base = 'phar://daux.phar/templates';
|
||||
if (is_dir(__DIR__ . '/../../../templates')) {
|
||||
$base = __DIR__ . '/../../../templates';
|
||||
} else {
|
||||
$base = 'phar://daux.phar/templates';
|
||||
}
|
||||
}
|
||||
|
||||
// Create new Plates instance
|
||||
|
@ -22,8 +22,6 @@ class Server
|
||||
public static function serve()
|
||||
{
|
||||
$daux = new Daux(Daux::LIVE_MODE);
|
||||
$daux->setThemesPath($daux->getParams()['themes_directory']);
|
||||
$daux->setDocumentationPath($daux->getParams()['docs_directory']);
|
||||
$daux->initializeConfiguration();
|
||||
|
||||
$class = $daux->getProcessorClass();
|
||||
|
@ -9,15 +9,13 @@ class Root extends Directory
|
||||
|
||||
/**
|
||||
* The root doesn't have a parent
|
||||
*
|
||||
* @param string $uri
|
||||
*/
|
||||
public function __construct(Config $config, $uri)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->setConfig($config);
|
||||
|
||||
$this->setUri($uri);
|
||||
$this->path = $uri;
|
||||
$this->setUri($config->getDocumentationDirectory());
|
||||
$this->path = $config->getDocumentationDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,11 +22,12 @@ class LinkRendererTest extends \PHPUnit_Framework_TestCase
|
||||
];
|
||||
$root = vfsStream::setup('root', null, $structure);
|
||||
|
||||
$config->setDocumentationDirectory($root->url());
|
||||
$config['valid_content_extensions'] = ['md'];
|
||||
$config['mode'] = Daux::STATIC_MODE;
|
||||
$config['index_key'] = 'index.html';
|
||||
|
||||
$tree = new Root($config, $root->url());
|
||||
$tree = new Root($config);
|
||||
Builder::build($tree, []);
|
||||
|
||||
return $tree;
|
||||
|
@ -29,11 +29,12 @@ class BuilderIntegrationTest extends \PHPUnit_Framework_TestCase
|
||||
public function testCreateHierarchy()
|
||||
{
|
||||
$config = new Config();
|
||||
$config->setDocumentationDirectory($this->root->url());
|
||||
$config['valid_content_extensions'] = ['md'];
|
||||
$config['mode'] = Daux::STATIC_MODE;
|
||||
$config['index_key'] = 'index.html';
|
||||
|
||||
$tree = new Root($config, $this->root->url());
|
||||
$tree = new Root($config);
|
||||
Builder::build($tree, []);
|
||||
|
||||
$this->assertCount(2, $tree);
|
||||
|
@ -39,7 +39,9 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetOrCreateDirNew()
|
||||
{
|
||||
$root = new Root(new Config(), '');
|
||||
$config = new Config;
|
||||
$config->setDocumentationDirectory('');
|
||||
$root = new Root($config);
|
||||
|
||||
|
||||
$dir = Builder::getOrCreateDir($root, 'directory');
|
||||
@ -51,7 +53,9 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetOrCreateDirExisting()
|
||||
{
|
||||
$root = new Root(new Config(), '');
|
||||
$config = new Config;
|
||||
$config->setDocumentationDirectory('');
|
||||
$root = new Root($config);
|
||||
$directory = new Directory($root, 'directory');
|
||||
$directory->setTitle('directory');
|
||||
|
||||
@ -66,11 +70,12 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
public function getStaticRoot()
|
||||
{
|
||||
$config = new Config();
|
||||
$config->setDocumentationDirectory('');
|
||||
$config['mode'] = Daux::STATIC_MODE;
|
||||
$config['index_key'] = 'index.html';
|
||||
$config['valid_content_extensions'] = ['md'];
|
||||
|
||||
return new Root($config, '');
|
||||
return new Root($config);
|
||||
}
|
||||
|
||||
public function testGetOrCreatePage()
|
||||
|
@ -6,7 +6,10 @@ class ContentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function createContent($content)
|
||||
{
|
||||
$dir = new Directory(new Root(new Config, ''), '');
|
||||
$config = new Config;
|
||||
$config->setDocumentationDirectory('');
|
||||
|
||||
$dir = new Directory(new Root($config), '');
|
||||
$obj = new Content($dir, '');
|
||||
$obj->setContent($content);
|
||||
|
||||
|
@ -28,7 +28,11 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSort($list, $expected)
|
||||
{
|
||||
shuffle($list);
|
||||
$directory = new Directory(new Root(new Config(), ''), 'dir');
|
||||
|
||||
$config = new Config;
|
||||
$config->setDocumentationDirectory('');
|
||||
|
||||
$directory = new Directory(new Root($config), 'dir');
|
||||
|
||||
foreach ($list as $value) {
|
||||
$entry = new Content($directory, $value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user