Completed
Branch 2.5/TaskLists (9a2343)
by Josh
03:17
created

Configurator::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php declare(strict_types=1);
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2020 The s9e authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\TaskLists;
9
10
use s9e\TextFormatter\Configurator\Items\Tag;
11
use s9e\TextFormatter\Plugins\ConfiguratorBase;
12
13
class Configurator extends ConfiguratorBase
14
{
15
	/**
16
	* {@inheritdoc}
17
	*/
18
	public function asConfig()
19
	{
20
		return;
21
	}
22
23 1
	protected function setUp(): void
24
	{
25 1
		if (!isset($this->configurator->tags['LI']))
26
		{
27 1
			$this->configurator->Litedown;
28
		}
29
30 1
		$this->createTaskTag();
31 1
		$this->configureListItemTag($this->configurator->tags['LI']);
32
	}
33
34 1
	protected function configureListItemTag(Tag $tag): void
35
	{
36 1
		$tag->filterChain->append(Helper::class . '::filterListItem')
37 1
			->resetParameters()
38 1
			->addParameterByName('parser')
39 1
			->addParameterByName('tag')
40 1
			->addParameterByName('text')
41 1
			->setJS(file_get_contents(__DIR__ . '/filterListItem.js'));
42
43 1
		$attribute = $tag->attributes->add('task_id');
44 1
		$attribute->required = false;
45 1
		$attribute->filterChain->append('#identifier');
46
47 1
		$tag->template = preg_replace(
48 1
			'(<li[^>]*+>(?!<xsl:if test="@task_id">)\\K)',
49 1
			'<xsl:if test="@task_id">
50
				<xsl:attribute name="data-task-id">
51
					<xsl:value-of select="@task_id"/>
52
				</xsl:attribute>
53
			</xsl:if>',
54 1
			$tag->template
1 ignored issue
show
introduced by
The property template is declared write-only in s9e\TextFormatter\Configurator\Items\Tag.
Loading history...
55
		);
56
	}
57
58 1
	protected function createTaskTag(): void
59
	{
60 1
		$tag = $this->configurator->tags->add('TASK');
61 1
		$tag->attributes->add('id')->filterChain->append('#identifier');
62 1
		$tag->attributes->add('state')->required = false;
63 1
		$tag->template = '<input data-task-id="{@id}" type="checkbox">
64
			<xsl:if test="@state"><xsl:attribute name="checked"/></xsl:if>
65
			<xsl:if test="not($TASKLISTS_EDITABLE)"><xsl:attribute name="disabled"/></xsl:if>
66
		</input>';
67
	}
68
}