Skip to content

Commit

Permalink
✨ Add config for multiple naming schemes
Browse files Browse the repository at this point in the history
This adds the naming schemes from #1
29b2c89  but in a cleaner way with an
additional option for year:year-month-day. It is compatible to the
 naming scheme of #1 .
  • Loading branch information
micgro42 committed Aug 27, 2018
1 parent 062dafa commit fbfa374
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 2 deletions.
72 changes: 72 additions & 0 deletions _test/pagenameStrategy.test.php
@@ -0,0 +1,72 @@
<?php

namespace dokuwiki\plugin\yearbox\test;

use dokuwiki\plugin\yearbox\services\pageNameStrategies\PageNameStrategy;

/**
* Tests from syntax to html for the yearbox plugin
*
* @group plugin_yearbox
* @group plugins
*/
class pagenameStrategy_plugin_yearbox_test extends \DokuWikiTest {


public function dataProvider()
{
return [
[
'',
'',
'day',
':2018-03:day-2018-03-08',
'Test default configutation',
],
[
'separatedCompletely',
'bar',
null,
'bar:2018:03:08',
'test completely separated namespaces'
],
[
'YearMonthSeperatedNS',
'',
'',
':2018:03:2018-03-08',
'have year and month as separate ns, but keep the pageid the iso-date',
],
[
'YearNS',
'appreciation',
'',
'appreciation:2018:2018-03-08',
'have a year namespace and the iso-date as pade id'
],
];

}

/**
* @dataProvider dataProvider
*
* @param string $strategyName
* @param string $baseNS
* @param string $name
* @param string $expectedPageId
* @param $msg
*/
public function test_pagenameStrategy($strategyName, $baseNS, $name, $expectedPageId, $msg)
{
$year = 2018;
$month = '03';
$day = '08';

$strategy = PageNameStrategy::getPagenameStategy($strategyName);

$actual_id = $strategy->getPageId($baseNS, $year, $month, $day, $name);

$this->assertSame($expectedPageId, $actual_id, $msg);
}
}
3 changes: 3 additions & 0 deletions conf/default.php
@@ -0,0 +1,3 @@
<?php

$conf['namestructure'] = 'default';
11 changes: 11 additions & 0 deletions conf/metadata.php
@@ -0,0 +1,11 @@
<?php

$meta['namestructure'] = [
'multichoice',
'_choices' => [
'default',
'separatedCompletely',
'YearMonthSeperatedNS',
'YearNS',
],
];
7 changes: 7 additions & 0 deletions lang/en/settings.php
@@ -0,0 +1,7 @@
<?php

$lang['namestructure'] = 'The naming scheme used for creating new entries and finding the entries to display.';
$lang['namestructure_o_default'] = '<root> : year-month : <name>-year-month-day';
$lang['namestructure_o_YearMonthSeperatedNS'] = '<root> : year : month : <name>-year-month-day';
$lang['namestructure_o_separatedCompletely'] = '<root> : year : month : day';
$lang['namestructure_o_YearNS'] = '<root> : year : <name>-year-month-day';
14 changes: 14 additions & 0 deletions services/pageNameStrategies/CompletelySeparated.php
@@ -0,0 +1,14 @@
<?php


namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;


class CompletelySeparated extends PageNameStrategy
{

public function getPageId($baseNS, $year, $month, $day, $name)
{
return "$baseNS:$year:$month:$day";
}
}
25 changes: 25 additions & 0 deletions services/pageNameStrategies/PageNameStrategy.php
@@ -0,0 +1,25 @@
<?php

namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;

abstract class PageNameStrategy
{

public static function getPagenameStategy($namingStructure)
{
switch ($namingStructure) {
case 'separatedCompletely':
case 2:
return new CompletelySeparated();
case 'YearMonthSeperatedNS':
case 1:
return new YearMonthSeperatedNS();
case 'YearNS':
return new YearNS();
default:
return new YearMonthCombinedNS();
}
}

abstract public function getPageId($baseNS, $year, $month, $day, $name);
}
15 changes: 15 additions & 0 deletions services/pageNameStrategies/YearMonthCombinedNS.php
@@ -0,0 +1,15 @@
<?php


namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;


class YearMonthCombinedNS extends PageNameStrategy
{

public function getPageId($baseNS, $year, $month, $day, $name)
{
$pagename = ($name ? "$name-" : '') . "$year-$month-$day";
return "$baseNS:$year-$month:$pagename";
}
}
15 changes: 15 additions & 0 deletions services/pageNameStrategies/YearMonthSeperatedNS.php
@@ -0,0 +1,15 @@
<?php


namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;


class YearMonthSeperatedNS extends PageNameStrategy
{

public function getPageId($baseNS, $year, $month, $day, $name)
{
$pagename = ($name ? "$name-" : '') . "$year-$month-$day";
return "$baseNS:$year:$month:$pagename";
}
}
15 changes: 15 additions & 0 deletions services/pageNameStrategies/YearNS.php
@@ -0,0 +1,15 @@
<?php


namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;


class YearNS extends PageNameStrategy
{

public function getPageId($baseNS, $year, $month, $day, $name)
{
$pagename = ($name ? "$name-" : '') . "$year-$month-$day";
return "$baseNS:$year:$pagename";
}
}
6 changes: 4 additions & 2 deletions syntax.php
Expand Up @@ -8,6 +8,8 @@
*
*/

use dokuwiki\plugin\yearbox\services\pageNameStrategies\PageNameStrategy;

/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
Expand Down Expand Up @@ -245,8 +247,8 @@ public function getDayHTML($cur_day, $mth_num, $today, $year_num, $weekday_num,
$day_css = ($is_weekend) ? ' class="wkend"' : '';
$day_fmt = sprintf("%02d", $cur_day);
$month_fmt = sprintf("%02d", $mth_num);
$id = $opt['ns'] . ':' . $year_num . '-' . $month_fmt . ':' . $opt['name'] . '-' .
$year_num . '-' . $month_fmt . '-' . $day_fmt;
$pagenameService = PageNameStrategy::getPagenameStategy($this->getConf('namestructure'));
$id = $pagenameService->getPageId($opt['ns'], $year_num, $month_fmt, $day_fmt, $opt['name']);
$current = mktime(0, 0, 0, $month_fmt, $day_fmt, $year_num);
if ($current == $today) {
$day_css = ' class="today"';
Expand Down

0 comments on commit fbfa374

Please sign in to comment.