This commit is contained in:
Stéphane Goetz 2020-04-22 21:55:53 +02:00
parent 684267b47c
commit 9c13185620
55 changed files with 353 additions and 218 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ static
/vendor
/build
.phpunit.result.cache
.php_cs.cache
/prettier.config.js
/.eslintrc.js

14
.php_cs Normal file
View File

@ -0,0 +1,14 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
;
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder)
;

View File

@ -46,6 +46,8 @@
"mikey179/vfsstream": "^1.6"
},
"scripts": {
"test": "build/phpunit"
"test": "build/phpunit",
"lint": "build/php-cs-fixer fix --config=.php_cs --dry-run -v",
"lint:fix": "build/php-cs-fixer fix --config=.php_cs"
}
}

View File

@ -5,7 +5,7 @@ use Todaymade\Daux\Daux;
class Cache
{
static $printed = false;
public static $printed = false;
public static function getDirectory(): string
{
@ -109,7 +109,6 @@ class Cache
} else {
unlink($dir . "/" . $object);
}
}
}
rmdir($dir);

View File

@ -8,91 +8,113 @@ use Todaymade\Daux\Format\Confluence\Config as ConfluenceConfig;
class Config extends BaseConfig
{
public function getTitle() {
public function getTitle()
{
return $this->getValue('title');
}
public function hasAuthor(): bool {
public function hasAuthor(): bool
{
return $this->hasValue('author');
}
public function getAuthor() {
public function getAuthor()
{
return $this->getValue('author');
}
public function hasTagline(): bool {
public function hasTagline(): bool
{
return $this->hasValue('tagline');
}
public function getTagline() {
public function getTagline()
{
return $this->getValue('tagline');
}
public function getCurrentPage() {
public function getCurrentPage()
{
return $this->getValue('current_page');
}
public function setCurrentPage(Content $entry) {
public function setCurrentPage(Content $entry)
{
$this->setValue('current_page', $entry);
}
public function getDocumentationDirectory() {
public function getDocumentationDirectory()
{
return $this->getValue('docs_directory');
}
public function getThemesDirectory() {
public function getThemesDirectory()
{
return $this->getValue('themes_directory');
}
public function getThemesPath() {
public function getThemesPath()
{
return $this->getValue('themes_path');
}
public function getFormat() {
public function getFormat()
{
return $this->getValue('format');
}
public function hasTimezone(): bool {
public function hasTimezone(): bool
{
return isset($this['timezone']);
}
public function getTimezone() {
public function getTimezone()
{
return $this->getValue('timezone');
}
public function getTree() {
public function getTree()
{
return $this->getValue('tree');
}
public function setTree($tree) {
public function setTree($tree)
{
$this->setValue('tree', $tree);
}
public function isMultilanguage(): bool {
public function isMultilanguage(): bool
{
return $this->hasValue('languages') && !empty($this->getValue('languages'));
}
public function getLanguages(): array {
public function getLanguages(): array
{
return $this->getValue('languages');
}
public function getLanguage(): string {
public function getLanguage(): string
{
return $this->getValue('language');
}
public function getMode() {
public function getMode()
{
return $this->getValue('mode');
}
public function isLive() {
public function isLive()
{
return $this->getValue('mode') == Daux::LIVE_MODE;
}
public function isStatic() {
public function isStatic()
{
return $this->getValue('mode') == Daux::STATIC_MODE;
}
public function shouldInheritIndex() {
public function shouldInheritIndex()
{
// As the global configuration is always present, we
// need to test for the existence of the legacy value
// first. Then use the current value.
@ -103,35 +125,43 @@ class Config extends BaseConfig
return $this['html']['inherit_index'];
}
public function getIndexKey() {
public function getIndexKey()
{
return $this->getValue('mode') == Daux::STATIC_MODE ? 'index.html' : 'index';
}
public function getProcessor() {
public function getProcessor()
{
return $this->getValue('processor');
}
public function getConfluenceConfiguration(): ConfluenceConfig {
public function getConfluenceConfiguration(): ConfluenceConfig
{
return new ConfluenceConfig($this->hasValue('confluence') ? $this->getValue('confluence') : []);
}
public function getHTML(): HTMLConfig {
public function getHTML(): HTMLConfig
{
return new HTMLConfig($this->hasValue('html') ? $this->getValue('html') : []);
}
public function getTheme(): ?Theme {
public function getTheme(): ?Theme
{
return $this->hasValue('theme') ? new Theme($this->getValue('theme')) : null;
}
public function getValidContentExtensions() {
public function getValidContentExtensions()
{
return $this->getValue('valid_content_extensions');
}
public function setValidContentExtensions(array $value) {
public function setValidContentExtensions(array $value)
{
$this->setValue('valid_content_extensions', $value);
}
public function canCache() {
public function canCache()
{
if ($this->hasValue('cache')) {
return $this->getValue('cache');
}
@ -139,7 +169,8 @@ class Config extends BaseConfig
return false;
}
public function getCacheKey() {
public function getCacheKey()
{
$cloned = [];
foreach ($this as $key => $value) {
$cloned[$key] = ($value instanceof Entry) ? $value->dump() : $value;
@ -148,40 +179,48 @@ class Config extends BaseConfig
return sha1(json_encode($cloned));
}
public function hasTranslationKey($language, $key): bool {
public function hasTranslationKey($language, $key): bool
{
return array_key_exists($language, $this['strings']) && array_key_exists($key, $this['strings'][$language]);
}
public function getTranslationKey($language, $key) {
public function getTranslationKey($language, $key)
{
return $this['strings'][$language][$key];
}
public function hasImage(): bool {
public function hasImage(): bool
{
return $this->hasValue('image');
}
public function getImage() {
public function getImage()
{
return $this->getValue('image');
}
public function setImage($value) {
public function setImage($value)
{
$this->setValue('image', $value);
}
public function getLocalBase() {
public function getLocalBase()
{
return $this->getValue('local_base');
}
public function getTemplates() {
public function getTemplates()
{
return $this->getValue('templates');
}
public function getBaseUrl() {
public function getBaseUrl()
{
return $this->getValue('base_url');
}
public function getBasePage() {
public function getBasePage()
{
if ($this->isLive()) {
$value = '//' . $this->getBaseUrl();
if (!$this['live']['clean_urls']) {
@ -193,59 +232,73 @@ class Config extends BaseConfig
return $this->getBaseUrl();
}
public function hasEntryPage(): bool {
public function hasEntryPage(): bool
{
return $this->hasValue('entry_page') && !empty($this->getValue('entry_page'));
}
public function getEntryPage() {
public function getEntryPage()
{
return $this->getValue('entry_page');
}
public function setEntryPage($value) {
public function setEntryPage($value)
{
$this->setValue('entry_page', $value);
}
public function hasRequest(): bool {
public function hasRequest(): bool
{
return $this->hasValue('request') && !empty($this->getValue('request'));
}
public function getRequest() {
public function getRequest()
{
return $this->getValue('request');
}
public function setRequest($value) {
public function setRequest($value)
{
$this->setValue('request', $value);
}
public function getIndex() {
public function getIndex()
{
return $this->getValue('index');
}
public function setIndex($value) {
public function setIndex($value)
{
$this->setValue('index', $value);
}
public function hasProcessorInstance() {
public function hasProcessorInstance()
{
return $this->hasValue('processor_instance');
}
public function getProcessorInstance() {
public function getProcessorInstance()
{
return $this->getValue('processor_instance');
}
public function setProcessorInstance($value) {
public function setProcessorInstance($value)
{
$this->setValue('processor_instance', $value);
}
public function getIgnore() {
public function getIgnore()
{
return $this->getValue('ignore');
}
public function hasHost() {
public function hasHost()
{
return $this->hasValue('host');
}
public function getHost() {
public function getHost()
{
return $this->getValue('host');
}
}

View File

@ -7,28 +7,33 @@ class ConfigBuilder
private $configuration_override_file = null;
private function __construct(string $mode) {
private function __construct(string $mode)
{
$this->config = new Config();
$this->config['mode'] = $mode;
$this->config['local_base'] = dirname(__DIR__);
}
public static function fromFile($file): Config {
public static function fromFile($file): Config
{
return unserialize(file_get_contents($file));
}
public static function withMode($mode = Daux::STATIC_MODE): ConfigBuilder {
public static function withMode($mode = Daux::STATIC_MODE): ConfigBuilder
{
$builder = new ConfigBuilder($mode);
$builder->loadBaseConfiguration();
return $builder;
}
public function with(array $values): ConfigBuilder {
public function with(array $values): ConfigBuilder
{
$this->config->merge($values);
return $this;
}
private function setValue(&$array, $key, $value) {
private function setValue(&$array, $key, $value)
{
if (is_null($key)) {
return $array = $value;
}
@ -44,65 +49,77 @@ class ConfigBuilder
return $array;
}
public function withValues(array $values): ConfigBuilder {
public function withValues(array $values): ConfigBuilder
{
foreach ($values as $value) {
$this->setValue($this->config, $value[0], $value[1]);
}
return $this;
}
public function withDocumentationDirectory($dir): ConfigBuilder {
public function withDocumentationDirectory($dir): ConfigBuilder
{
$this->config['docs_directory'] = $dir;
return $this;
}
public function withValidContentExtensions(array $value): ConfigBuilder {
public function withValidContentExtensions(array $value): ConfigBuilder
{
$this->config['valid_content_extensions'] = $value;
return $this;
}
public function withThemesPath($themePath): ConfigBuilder {
public function withThemesPath($themePath): ConfigBuilder
{
$this->config['themes_path'] = $themePath;
return $this;
}
public function withThemesDirectory($directory): ConfigBuilder {
public function withThemesDirectory($directory): ConfigBuilder
{
$this->config['themes_directory'] = $directory;
return $this;
}
public function withCache(bool $value): ConfigBuilder {
public function withCache(bool $value): ConfigBuilder
{
$this->config['cache'] = $value;
return $this;
}
public function withFormat($format): ConfigBuilder {
public function withFormat($format): ConfigBuilder
{
$this->config['format'] = $format;
return $this;
}
public function withConfigurationOverride($file): ConfigBuilder {
public function withConfigurationOverride($file): ConfigBuilder
{
$this->configuration_override_file = $file;
return $this;
}
public function withProcessor($value): ConfigBuilder {
public function withProcessor($value): ConfigBuilder
{
$this->config['processor'] = $value;
return $this;
}
public function withConfluenceDelete($value): ConfigBuilder {
public function withConfluenceDelete($value): ConfigBuilder
{
$this->config['confluence']['delete'] = $value;
return $this;
}
public function build(): Config {
public function build(): Config
{
$this->initializeConfiguration();
return $this->config;
}
private function resolveThemeVariant() {
private function resolveThemeVariant()
{
$theme = $this->config->getHTML()->getTheme();
$themesPath = $this->config->getThemesPath() . DIRECTORY_SEPARATOR;
@ -131,7 +148,8 @@ class ConfigBuilder
* @param string $override_file
* @throws Exception
*/
private function initializeConfiguration() {
private function initializeConfiguration()
{
// Validate and set theme path
$docs_path = $this->normalizeDocumentationPath($this->config->getDocumentationDirectory());
$this->config['docs_directory'] = $docs_path;
@ -163,10 +181,11 @@ class ConfigBuilder
// Text search would be too slow on live server
if ($this->config->isLive()) {
$this->config['html']['search'] = false;
}
}
}
private function normalizeThemePath($path) {
private function normalizeThemePath($path)
{
$validPath = $this->findLocation($path, $this->config->getLocalBase(), 'dir');
if (!$validPath) {
@ -176,7 +195,8 @@ class ConfigBuilder
return $validPath;
}
private function normalizeDocumentationPath($path) {
private function normalizeDocumentationPath($path)
{
$validPath = $this->findLocation($path, $this->config->getLocalBase(), 'dir');
if (!$validPath) {
@ -191,7 +211,8 @@ class ConfigBuilder
*
* @throws Exception
*/
private function loadBaseConfiguration() {
private function loadBaseConfiguration()
{
// Set the default configuration
$this->config->merge([
'docs_directory' => 'docs',
@ -212,7 +233,8 @@ class ConfigBuilder
* @param bool $optional
* @throws Exception
*/
private function loadConfiguration($config_file, $optional = true) {
private function loadConfiguration($config_file, $optional = true)
{
if (!file_exists($config_file)) {
if ($optional) {
return;
@ -235,7 +257,8 @@ class ConfigBuilder
* @return string|null the path to a file to load for configuration overrides
* @throws Exception
*/
private function getConfigurationOverride($path) {
private function getConfigurationOverride($path)
{
$validPath = $this->findLocation($path, $this->config->getLocalBase(), 'file');
if ($validPath === null) {
@ -255,7 +278,8 @@ class ConfigBuilder
* @param string $type
* @return false|null|string
*/
private function findLocation($path, $basedir, $type) {
private function findLocation($path, $basedir, $type)
{
// If Path is explicitly null, it's useless to go further
if ($path === null) {
return null;
@ -280,4 +304,4 @@ class ConfigBuilder
return false;
}
}
}

View File

@ -9,7 +9,7 @@ use Todaymade\Daux\Daux;
class DauxCommand extends SymfonyCommand
{
protected function configure()
protected function configure()
{
$this
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
@ -46,7 +46,7 @@ class DauxCommand extends SymfonyCommand
if ($input->hasOption('value')) {
$values = array_map(
function($value) {
function ($value) {
return array_map("trim", explode('=', $value));
},
$input->getOption('value')

View File

@ -5,7 +5,8 @@ use Todaymade\Daux\Daux;
trait RunAction
{
protected function getLength($content) {
protected function getLength($content)
{
return function_exists('mb_strlen') ? mb_strlen($content) : strlen($content);
}
@ -19,7 +20,7 @@ trait RunAction
$padding = $width - $this->getLength($title) - 10;
try {
$response = $closure(function($content) use (&$padding, $verbose) {
$response = $closure(function ($content) use (&$padding, $verbose) {
$padding -= $this->getLength($content);
Daux::write($content, $verbose);
});

View File

@ -49,7 +49,7 @@ class Serve extends DauxCommand
return 1;
}
$path = stream_get_meta_data($file)['uri'];
$path = stream_get_meta_data($file)['uri'];
fwrite($file, serialize($daux->getConfig()));
chdir(__DIR__ . '/../../');

View File

@ -19,11 +19,13 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType
$this->config = $config;
}
protected function createConverter() {
protected function createConverter()
{
return new CommonMarkConverter(['daux' => $this->config]);
}
protected function getConverter() {
protected function getConverter()
{
if (!$this->converter) {
$this->converter = $this->createConverter();
}
@ -67,7 +69,7 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType
if ($can_cache) {
Cache::put($cacheKey, $payload);
}
}
return $payload;
}

View File

@ -4,8 +4,6 @@ use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\ContentTypes\ContentTypeHandler;
use Todaymade\Daux\Tree\Builder;
use Todaymade\Daux\Tree\Content;
use Todaymade\Daux\Tree\Directory;
use Todaymade\Daux\Tree\Root;
class Daux
@ -40,7 +38,7 @@ class Daux
{
Daux::$output = $output;
$this->config = $config;
}
@ -161,7 +159,8 @@ class Daux
return $class;
}
protected function findAlternatives($input, $words) {
protected function findAlternatives($input, $words)
{
$alternatives = [];
foreach ($words as $word) {
@ -246,7 +245,8 @@ class Daux
return $this->validExtensions = $this->getContentTypeHandler()->getContentExtensions();
}
public static function getOutput() {
public static function getOutput()
{
if (!Daux::$output) {
Daux::$output = new NullOutput();
}
@ -261,7 +261,8 @@ class Daux
* @param bool $newline Whether to add a newline
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
*/
public static function write($messages, $newline = false, $options = 0) {
public static function write($messages, $newline = false, $options = 0)
{
Daux::getOutput()->write($messages, $newline, $options);
}
@ -271,11 +272,13 @@ class Daux
* @param string|array $messages The message as an array of lines of a single string
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
*/
public static function writeln($messages, $options = 0) {
public static function writeln($messages, $options = 0)
{
Daux::getOutput()->write($messages, true, $options);
}
public static function getVerbosity() {
public static function getVerbosity()
{
return Daux::getOutput()->getVerbosity();
}
}

View File

@ -237,7 +237,7 @@ class DauxHelper
// Convert all dashes into underscores
$title = preg_replace('![' . preg_quote('-') . ']+!u', $separator, $title);
// Remove all characters that are not valid in a URL:
// Remove all characters that are not valid in a URL:
// $-_.+!*'(), separator, letters, numbers, or whitespace.
$title = preg_replace('![^-' . preg_quote($separator) . '\!\'\(\),\.\+\*\$\pL\pN\s]+!u', '', $title);
@ -316,7 +316,8 @@ class DauxHelper
return '' !== $parts['root'];
}
public static function getAbsolutePath($path) {
public static function getAbsolutePath($path)
{
if (DauxHelper::isAbsolutePath($path)) {
return $path;
}
@ -324,7 +325,8 @@ class DauxHelper
return getcwd() . '/' . $path;
}
public static function is($path, $type) {
public static function is($path, $type)
{
return ($type == 'dir') ? is_dir($path) : file_exists($path);
}

View File

@ -25,7 +25,7 @@ class EmbedImages
{
return preg_replace_callback(
"/<img\\s+[^>]*src=['\"]([^\"]*)['\"][^>]*>/",
function($matches) use ($file, $callback) {
function ($matches) use ($file, $callback) {
if ($result = $this->findImage($matches[1], $matches[0], $file, $callback)) {
return $result;
}

View File

@ -232,7 +232,6 @@ class Api
$prepared = [];
foreach ($filtered as $index => $line) {
$number = $start + 1 + $index;
$gutter = substr(' ' . (' ' . $number), -$maxWidth) . ' | ';
@ -318,7 +317,6 @@ class Api
// If the attachment is already uploaded,
// the update URL is different
if (count($result['results'])) {
if ($this->getFileSize($attachment) == $result['results'][0]['extensions']['fileSize']) {
$write(" ( An attachment of the same size already exists, skipping. )");
return;

View File

@ -4,7 +4,8 @@ use Todaymade\Daux\BaseConfig;
class Config extends BaseConfig
{
public function shouldAutoDeleteOrphanedPages() {
public function shouldAutoDeleteOrphanedPages()
{
if ($this->hasValue('delete')) {
return $this->getValue('delete');
}
@ -12,55 +13,68 @@ class Config extends BaseConfig
return false;
}
public function getUpdateThreshold() {
public function getUpdateThreshold()
{
return $this->hasValue('update_threshold') ? $this->getValue('update_threshold') : 2;
}
public function getPrefix() {
public function getPrefix()
{
return $this->getValue('prefix');
}
public function getBaseUrl() {
public function getBaseUrl()
{
return $this->getValue('base_url');
}
public function getUser() {
public function getUser()
{
return $this->getValue('user');
}
public function getPassword() {
public function getPassword()
{
return $this->getValue('pass');
}
public function getSpaceId() {
public function getSpaceId()
{
return $this->getValue('space_id');
}
public function hasAncestorId() {
public function hasAncestorId()
{
return $this->hasValue('ancestor_id');
}
public function getAncestorId() {
public function getAncestorId()
{
return $this->getValue('ancestor_id');
}
public function setAncestorId($value) {
public function setAncestorId($value)
{
$this->setValue('ancestor_id', $value);
}
public function hasRootId() {
public function hasRootId()
{
return $this->hasValue('root_id');
}
public function getRootId() {
public function getRootId()
{
return $this->getValue('root_id');
}
public function hasHeader() {
public function hasHeader()
{
return $this->hasValue('header');
}
public function getHeader() {
public function getHeader()
{
return $this->getValue('header');
}
}

View File

@ -19,13 +19,13 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
->embed(
$content,
$this->file,
function($src, array $attributes, Entry $file) {
function ($src, array $attributes, Entry $file) {
//Add the attachment for later upload
if ($file instanceof Raw) {
$filename = basename($file->getPath());
$this->attachments[$filename] = ['filename' => $filename, 'file' => $file];
} else if ($file instanceof ComputedRaw) {
} elseif ($file instanceof ComputedRaw) {
$filename = $file->getUri();
$this->attachments[$filename] = ['filename' => $filename, 'content' => $file->getContent()];
} else {

View File

@ -5,7 +5,6 @@ use League\CommonMark\HtmlElement;
abstract class CodeRenderer implements BlockRendererInterface
{
public function escapeCDATA($content)
{
return str_replace("]]>", "]]]]><![CDATA[>", $content);

View File

@ -1,10 +1,9 @@
<?php namespace Todaymade\Daux\Format\Confluence\ContentTypes\Markdown;
use Todaymade\Daux\Config;
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
{
protected function createConverter() {
protected function createConverter()
{
return new CommonMarkConverter(['daux' => $this->config]);
}
}

View File

@ -20,7 +20,8 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
*/
protected $parent;
public function __construct() {
public function __construct()
{
$this->parent = new \League\CommonMark\Inline\Renderer\ImageRenderer();
}

View File

@ -80,7 +80,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
$tree = $this->runAction(
'Generating Tree ...',
$width,
function() use ($config) {
function () use ($config) {
$tree = $this->generateRecursive($this->daux->tree, $config);
$tree['title'] = $this->prefix . $config->getTitle();

View File

@ -54,7 +54,7 @@ class Publisher
$this->run(
'Getting already published pages...',
function() use (&$published) {
function () use (&$published) {
if ($published != null) {
$published['children'] = $this->client->getList($published['id'], true);
}
@ -63,7 +63,7 @@ class Publisher
$published = $this->run(
"Create placeholder pages...",
function() use ($tree, $published) {
function () use ($tree, $published) {
return $this->createRecursive($this->confluence->getAncestorId(), $tree, $published);
}
);
@ -142,7 +142,7 @@ class Publisher
protected function createRecursive($parent_id, $entry, $published)
{
$callback = function($parent_id, $entry, $published) {
$callback = function ($parent_id, $entry, $published) {
// nothing to do if the ID already exists
if (array_key_exists('id', $published)) {
return $published;
@ -163,7 +163,7 @@ class Publisher
protected function updateRecursive($parent_id, $entry, $published)
{
$callback = function($parent_id, $entry, $published) {
$callback = function ($parent_id, $entry, $published) {
if (array_key_exists('id', $published) && array_key_exists('page', $entry)) {
$this->updatePage($parent_id, $entry, $published);
}
@ -181,7 +181,7 @@ class Publisher
$this->run(
'- ' . PublisherUtilities::niceTitle($entry['file']->getUrl()),
function() use ($entry, $published, $parent_id, $updateThreshold) {
function () use ($entry, $published, $parent_id, $updateThreshold) {
$generated_content = $entry['page']->getContent();
if (PublisherUtilities::shouldUpdate($entry['page'], $generated_content, $published, $updateThreshold)) {
$this->client->updatePage(
@ -199,7 +199,7 @@ class Publisher
foreach ($entry['page']->attachments as $attachment) {
$this->run(
" With attachment: $attachment[filename]",
function($write) use ($published, $attachment) {
function ($write) use ($published, $attachment) {
$this->client->uploadAttachment($published['id'], $attachment, $write);
}
);

View File

@ -60,7 +60,8 @@ class PublisherDelete
}
}
protected function doDelete() {
protected function doDelete()
{
$this->output->writeLn('Deleting obsolete pages...');
foreach ($this->deletable as $id => $title) {
$this->output->writeLn("- $title");
@ -68,7 +69,8 @@ class PublisherDelete
}
}
protected function displayDeletable() {
protected function displayDeletable()
{
$this->output->writeLn('Listing obsolete pages...');
$this->output->writeLn("> The following pages will not be deleted, but just listed for information.");
$this->output->writeLn("> If you want to delete these pages, you need to set the --delete flag on the command.");

View File

@ -34,7 +34,8 @@ class Config extends BaseConfig
return null;
}
public function hasSearch() {
public function hasSearch()
{
return $this->hasValue('search') && $this->getValue('search');
}

View File

@ -30,7 +30,8 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
return $this->file->getParent() instanceof Root;
}
private function isLanding(): bool {
private function isLanding(): bool
{
return $this->config->getHTML()->hasLandingPage() && $this->homepage;
}

View File

@ -1,10 +1,9 @@
<?php namespace Todaymade\Daux\Format\HTML\ContentTypes\Markdown;
use Todaymade\Daux\Config;
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
{
protected function createConverter() {
protected function createConverter()
{
return new CommonMarkConverter(['daux' => $this->config]);
}
}

View File

@ -15,7 +15,8 @@ class FencedCodeRenderer implements BlockRendererInterface
*/
private $hl;
public function __construct() {
public function __construct()
{
$this->hl = new Highlighter();
}

View File

@ -35,7 +35,7 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
}
/**
* Relative URLs can be done using either the folder with
* Relative URLs can be done using either the folder with
* number prefix or the final name (with prefix stripped).
* This ensures that we always use the final name when generating.
* @throws LinkNotFoundException
@ -70,7 +70,7 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
* @param ElementRendererInterface $htmlRenderer
*
* @return HtmlElement
*
*
* @throws LinkNotFoundException
*/
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)

View File

@ -72,7 +72,8 @@ class Processor
}
}
protected function getUniqueId(Document $document, $proposed) {
protected function getUniqueId(Document $document, $proposed)
{
if ($proposed == "page_") {
$proposed = "page_section_" . (count($document->heading_ids) + 1);
}

View File

@ -60,7 +60,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
$this->runAction(
'Copying Static assets ...',
$width,
function() use ($destination, $config) {
function () use ($destination, $config) {
$this->ensureEmptyDestination($destination);
$this->copyThemes($destination, $config->getThemesPath());
@ -170,7 +170,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
$this->runAction(
'- ' . $node->getUrl(),
$width,
function() use ($node, $output_dir, $key, $config, $index_pages) {
function () use ($node, $output_dir, $key, $config, $index_pages) {
if ($node instanceof Raw) {
copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key);

View File

@ -2,7 +2,8 @@
use Todaymade\Daux\GeneratorHelper;
trait HTMLUtils {
trait HTMLUtils
{
public function ensureEmptyDestination($destination)
{
if (is_dir($destination)) {
@ -26,4 +27,4 @@ trait HTMLUtils {
$destination . DIRECTORY_SEPARATOR . 'themes'
);
}
}
}

View File

@ -78,13 +78,13 @@ class Template
protected function registerFunctions($engine)
{
$engine->registerFunction('get_navigation', function($tree, $path, $current_url, $base_page, $mode) {
$engine->registerFunction('get_navigation', function ($tree, $path, $current_url, $base_page, $mode) {
$nav = $this->buildNavigation($tree, $path, $current_url, $base_page, $mode);
return $this->renderNavigation($nav);
});
$engine->registerFunction('translate', function($key) {
$engine->registerFunction('translate', function ($key) {
$language = $this->config->getLanguage();
if (isset($this->engine->getData('page')['page'])) {
@ -105,7 +105,7 @@ class Template
return "Unknown key $key";
});
$engine->registerFunction('get_breadcrumb_title', function($page, $base_page) {
$engine->registerFunction('get_breadcrumb_title', function ($page, $base_page) {
$title = '';
$breadcrumb_trail = $page['breadcrumb_trail'];
$separator = $this->getSeparator($page['breadcrumb_separator']);

View File

@ -4,23 +4,28 @@ use Todaymade\Daux\BaseConfig;
class Theme extends BaseConfig
{
public function getFonts() {
public function getFonts()
{
return $this->getValue('fonts');
}
public function getCSS() {
public function getCSS()
{
return $this->getValue('css');
}
public function getJS() {
public function getJS()
{
return $this->getValue('js');
}
public function getFavicon() {
public function getFavicon()
{
return $this->getValue('favicon');
}
public function getTemplates() {
public function getTemplates()
{
return $this->getValue('templates');
}
}

View File

@ -17,7 +17,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
->embed(
$content,
$this->file,
function($src, array $attributes, Raw $file) {
function ($src, array $attributes, Raw $file) {
// TODO :: ignore absolute paths
$content = base64_encode(file_get_contents($file->getPath()));
$attr = '';

View File

@ -1,10 +1,9 @@
<?php namespace Todaymade\Daux\Format\HTMLFile\ContentTypes\Markdown;
use Todaymade\Daux\Config;
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
{
protected function createConverter() {
protected function createConverter()
{
return new CommonMarkConverter(['daux' => $this->config]);
}
}

View File

@ -64,4 +64,4 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
return $element;
}
}
}

View File

@ -55,7 +55,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
$this->runAction(
'Cleaning destination folder ...',
$width,
function() use ($destination) {
function () use ($destination) {
$this->ensureEmptyDestination($destination);
}
);
@ -73,7 +73,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
$this->runAction(
'Generating ' . $current->getTitle(),
$width,
function() use ($book, $current, $config) {
function () use ($book, $current, $config) {
$contentType = $this->daux->getContentTypeHandler()->getType($current);
$content = ContentPage::fromFile($current, $config, $contentType);
$content->templateRenderer = $this->templateRenderer;

View File

@ -4,7 +4,8 @@ use IntlDateFormatter;
class FormatDate
{
public static function format($config, $date) {
public static function format($config, $date)
{
$locale = $config->getLanguage();
$datetype = IntlDateFormatter::LONG;
$timetype = IntlDateFormatter::SHORT;
@ -19,4 +20,4 @@ class FormatDate
return $formatter->format($date);
}
}
}

View File

@ -77,7 +77,8 @@ class Server
* @param string $postfix
* @return string
*/
private function getTemporaryFile($postfix) {
private function getTemporaryFile($postfix)
{
$sysFileName = tempnam(sys_get_temp_dir(), 'daux');
if ($sysFileName === false) {
throw new \RuntimeException("Could not create temporary file");
@ -99,7 +100,8 @@ class Server
* @param Page $page
* @return Response
*/
public function createResponse(Page $page) {
public function createResponse(Page $page)
{
// Add a custom MimeType guesser in case the default ones are not available
// This makes sure that at least CSS and JS work fine.
$mimeTypes = MimeTypes::getDefault();

View File

@ -218,7 +218,8 @@ class Builder
*
* @param Directory $current
*/
public static function sortTree(Directory $current) {
public static function sortTree(Directory $current)
{
$current->sort();
foreach ($current->getEntries() as $entry) {
if ($entry instanceof Directory) {
@ -251,5 +252,4 @@ class Builder
return $prev;
}
}

View File

@ -24,7 +24,7 @@ class Content extends ContentAbstract
{
if ($this->manuallySetContent) {
$content = $this->content;
} else if (!$this->getPath()) {
} elseif (!$this->getPath()) {
throw new RuntimeException("Empty content");
} else {
$content = file_get_contents($this->getPath());

View File

@ -95,7 +95,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
private function sortBucket($bucket, $final)
{
uasort($bucket, function(Entry $a, Entry $b) {
uasort($bucket, function (Entry $a, Entry $b) {
return strcasecmp($a->getName(), $b->getName());
});
@ -136,7 +136,8 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
return $this->parent->getConfig();
}
public function getLocalIndexPage() {
public function getLocalIndexPage()
{
$index_key = $this->getConfig()->getIndexKey();
if (isset($this->children[$index_key])) {

View File

@ -190,7 +190,8 @@ abstract class Entry
];
}
public function isHotPath(Entry $node = null) {
public function isHotPath(Entry $node = null)
{
return $this->parent->isHotPath($node ?: $this);
}
}

View File

@ -37,7 +37,8 @@ class Root extends Directory
$this->config = $config;
}
public function isHotPath(Entry $node = null): bool {
public function isHotPath(Entry $node = null): bool
{
if ($node == null) {
return true;
}
@ -59,7 +60,8 @@ class Root extends Directory
return false;
}
public function setActiveNode(Entry $node) {
public function setActiveNode(Entry $node)
{
$this->activeNode = $node;
}
}

View File

@ -1,6 +1,7 @@
<?php
function loadApp() {
function loadApp()
{
// Loaded as a dependency
if (file_exists(__DIR__ . '/../../../autoload.php')) {
return require_once __DIR__ . '/../../../autoload.php';

View File

@ -7,3 +7,7 @@ fi
echo "-- Install phpunit"
curl -sSLo build/phpunit https://phar.phpunit.de/phpunit-8.phar
chmod +x build/phpunit
echo "-- Install php-cs-fixer"
curl -sSLo build/php-cs-fixer https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.3/php-cs-fixer.phar
chmod +x build/php-cs-fixer

View File

@ -26,21 +26,18 @@
<?php
$hasPrevNext = (!empty($page['prev']) || !empty($page['next']));
if ($hasPrevNext && $config->getHTML()->showPreviousNextLinks()) {
?>
?>
<nav>
<ul class="Pager">
<?php if (!empty($page['prev'])) {
?><li class=Pager--prev><a href="<?= $base_url . $page['prev']->getUrl() ?>"><?= $this->translate("Link_previous") ?></a></li><?php
} ?>
?><li class=Pager--prev><a href="<?= $base_url . $page['prev']->getUrl() ?>"><?= $this->translate("Link_previous") ?></a></li><?php
} ?>
<?php if (!empty($page['next'])) {
?><li class=Pager--next><a href="<?= $base_url . $page['next']->getUrl() ?>"><?= $this->translate("Link_next") ?></a></li><?php
} ?>
?><li class=Pager--next><a href="<?= $base_url . $page['next']->getUrl() ?>"><?= $this->translate("Link_next") ?></a></li><?php
} ?>
</ul>
</nav>
<?php
} ?>
} ?>
</article>

View File

@ -53,8 +53,8 @@
<?php if ($config->getHTML()->hasLinks()) { ?>
<ul class="HomepageFooter__links">
<?php foreach ($config->getHTML()->getLinks() as $name => $url) {
echo '<li><a href="' . $url . '" target="_blank">' . $name . '</a></li>';
} ?>
echo '<li><a href="' . $url . '" target="_blank">' . $name . '</a></li>';
} ?>
</ul>
<?php } ?>

View File

@ -34,13 +34,13 @@
<!-- Font -->
<?php foreach ($config->getTheme()->getFonts() as $font) {
echo "<link href='$font' rel='stylesheet' type='text/css'>";
} ?>
echo "<link href='$font' rel='stylesheet' type='text/css'>";
} ?>
<!-- CSS -->
<?php foreach ($config->getTheme()->getCSS() as $css) {
echo "<link href='$css' rel='stylesheet' type='text/css'>";
} ?>
echo "<link href='$css' rel='stylesheet' type='text/css'>";
} ?>
<?php if ($config->getHTML()->hasSearch()) { ?>
<!-- Search -->

View File

@ -1,4 +1,4 @@
<?php
<?php
if (!isset($config)) {
$config = $params;
}

View File

@ -1,4 +1,4 @@
<?php
<?php
if (!isset($config)) {
$config = $params;
}

View File

@ -1,4 +1,4 @@
<?php
<?php
if (!isset($config)) {
$config = $params;
}

View File

@ -1,5 +1,4 @@
<?php
namespace Todaymade\Daux\ContentTypes\Markdown;
<?php namespace Todaymade\Daux\ContentTypes\Markdown;
use org\bovigo\vfs\vfsStream;
use Todaymade\Daux\Config;
@ -13,7 +12,6 @@ class LinkRendererTest extends TestCase
{
protected function getTree(Config $config)
{
}
public function providerRenderLink()

View File

@ -6,7 +6,8 @@ use PHPUnit\Framework\TestCase;
class ConfigTest extends TestCase
{
function testHTMLConfigCreation() {
public function testHTMLConfigCreation()
{
$config = new MainConfig(['html' => ['edit_on' => 'test']]);
$this->assertInstanceOf(Config::class, $config->getHTML());

View File

@ -1,39 +1,44 @@
<?php
namespace Todaymade\Daux\Format\HTML\Test;
<?php namespace Todaymade\Daux\Format\HTML\Test;
use Todaymade\Daux\Config as MainConfig;
use \Todaymade\Daux\Format\HTML\ContentTypes\Markdown\CommonMarkConverter;
use PHPUnit\Framework\TestCase;
class Engine {
function render($template, $data) {
class Engine
{
public function render($template, $data)
{
return $data['content'];
}
}
class Template {
function getEngine() {
class Template
{
public function getEngine()
{
return new Engine;
}
}
class TableOfContentsTest extends TestCase
{
function getConfig() {
public function getConfig()
{
$config = new MainConfig;
$config->templateRenderer = new Template;
return ['daux' => $config];
}
function testNoTOCByDefault() {
public function testNoTOCByDefault()
{
$converter = new CommonMarkConverter($this->getConfig());
$this->assertEquals("<h1 id=\"page_Test\">Test</h1>\n", $converter->convertToHtml('# Test'));
}
function testTOCToken() {
public function testTOCToken()
{
$converter = new CommonMarkConverter($this->getConfig());
$source = "[TOC]\n# Title";
@ -50,7 +55,8 @@ EXPECTED;
$this->assertEquals($expected, $converter->convertToHtml($source));
}
function testUnicodeTOC() {
public function testUnicodeTOC()
{
$converter = new CommonMarkConverter($this->getConfig());
$source = "[TOC]\n# 基础操作\n# 操作基础";
@ -71,7 +77,8 @@ EXPECTED;
$this->assertEquals($expected, $converter->convertToHtml($source));
}
function testDuplicatedTOC() {
public function testDuplicatedTOC()
{
$converter = new CommonMarkConverter($this->getConfig());
$source = "[TOC]\n# Test\n# Test";
@ -92,7 +99,8 @@ EXPECTED;
$this->assertEquals($expected, $converter->convertToHtml($source));
}
function testEscapedTOC() {
public function testEscapedTOC()
{
$converter = new CommonMarkConverter($this->getConfig());
$source = "[TOC]\n# TEST : Test";

View File

@ -4,16 +4,14 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\HttpFoundation\Request;
use Todaymade\Daux\Format\HTML\RawPage;
use Todaymade\Daux\Config;
use Todaymade\Daux\ConfigBuilder;
use Todaymade\Daux\Daux;
use Todaymade\Daux\Server\Server;
use org\bovigo\vfs\vfsStream;
class ServerTest extends TestCase
{
function testCreateResponse() {
public function testCreateResponse()
{
$structure = [
'index.md' => 'first page',
'Page.md' => 'another page',
@ -39,4 +37,3 @@ class ServerTest extends TestCase
$this->assertEquals("text/css", $response->headers->get('Content-Type'));
}
}