Completed
Push — master ( 531a74...d84102 )
by Josh
22:12
created

Configurator::setUp()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 0
dl 0
loc 18
ccs 15
cts 15
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2017 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\PipeTables;
9
10
use s9e\TextFormatter\Configurator\Items\AttributeFilters\ChoiceFilter;
11
use s9e\TextFormatter\Plugins\ConfiguratorBase;
12
13
class Configurator extends ConfiguratorBase
14
{
15
	/**
16
	* {@inheritdoc}
17
	*/
18
	protected $quickMatch = '|';
19
20
	/**
21
	* Create the tags used by this plugin
22
	*
23
	* @return void
24
	*/
25 6
	protected function setUp()
26
	{
27
		$tags = [
28 6
			'TABLE' => ['template' => '<table><xsl:apply-templates/></table>'],
29 6
			'TBODY' => ['template' => '<tbody><xsl:apply-templates/></tbody>'],
30 6
			'TD'    => $this->generateCellTagConfig('td'),
31 6
			'TH'    => $this->generateCellTagConfig('th'),
32 6
			'THEAD' => ['template' => '<thead><xsl:apply-templates/></thead>'],
33 6
			'TR'    => ['template' => '<tr><xsl:apply-templates/></tr>']
34 6
		];
35 6
		foreach ($tags as $tagName => $tagConfig)
36
		{
37 6
			if (!isset($this->configurator->tags[$tagName]))
38 6
			{
39 5
				$this->configurator->tags->add($tagName, $tagConfig);
40 5
			}
41 6
		}
42 6
	}
43
44
	/**
45
	* Generate the tag config for give cell element
46
	*
47
	* @param  string $elName Element's name, either "td" or "th"
48
	* @return array          Tag config
49
	*/
50 6
	protected function generateCellTagConfig($elName)
51
	{
52 6
		$alignFilter = new ChoiceFilter(['left', 'center', 'right', 'justify'], true);
53
54
		return	[
55
			'attributes' => [
56
				'align' => [
57 6
					'filterChain' => ['strtolower', $alignFilter],
58
					'required' => false
59 6
				]
60 6
			],
61 6
			'rules' => ['createParagraphs' => false],
62
			'template' =>
63 6
				'<' . $elName . '>
64
					<xsl:if test="@align">
65
						<xsl:attribute name="style">text-align:<xsl:value-of select="@align"/></xsl:attribute>
66
					</xsl:if>
67
					<xsl:apply-templates/>
68 6
				</' . $elName . '>'
69 6
		];
70
	}
71
72
	/**
73
	* {@inheritdoc}
74
	*/
75 4
	public function asConfig()
76
	{
77
		return [
78 4
			'overwriteEscapes'  => isset($this->configurator->Escaper),
79 4
			'overwriteMarkdown' => isset($this->configurator->Litedown)
80 4
		];
81
	}
82
}