Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add config for multiple naming schemes
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
Showing
10 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$conf['namestructure'] = 'default'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
$meta['namestructure'] = [ | ||
'multichoice', | ||
'_choices' => [ | ||
'default', | ||
'separatedCompletely', | ||
'YearMonthSeperatedNS', | ||
'YearNS', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters