Completed
Push — master ( 06658f...bda0c4 )
by Josh
21:51
created

Configurator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 24
cts 28
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 18 3
A generateCellTagConfig() 0 21 1
A asConfig() 0 7 1
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2016 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 1
	protected function setUp()
26
	{
27
		$tags = [
28 1
			'TABLE' => ['template' => '<table><xsl:apply-templates/></table>'],
29 1
			'TBODY' => ['template' => '<tbody><xsl:apply-templates/></tbody>'],
30 1
			'TD'    => $this->generateCellTagConfig('td'),
31 1
			'TH'    => $this->generateCellTagConfig('th'),
32 1
			'THEAD' => ['template' => '<thead><xsl:apply-templates/></thead>'],
33 1
			'TR'    => ['template' => '<tr><xsl:apply-templates/></tr>']
34 1
		];
35 1
		foreach ($tags as $tagName => $tagConfig)
36
		{
37 1
			if (!isset($this->configurator->tags[$tagName]))
38 1
			{
39 1
				$this->configurator->tags->add($tagName, $tagConfig);
40 1
			}
41 1
		}
42 1
	}
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 1
	protected function generateCellTagConfig($elName)
51
	{
52 1
		$alignFilter = new ChoiceFilter(['left', 'center', 'right', 'justify'], true);
53
54
		return	[
55
			'attributes' => [
56
				'align' => [
57 1
					'filterChain' => ['strtolower', $alignFilter],
58
					'required' => false
59 1
				]
60 1
			],
61 1
			'rules' => ['createParagraphs' => false],
62
			'template' =>
63 1
				'<' . $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 1
				</' . $elName . '>'
69 1
		];
70
	}
71
72
	/**
73
	* {@inheritdoc}
74
	*/
75
	public function asConfig()
76
	{
77
		return [
78
			'overwriteEscapes'  => isset($this->configurator->Escaper),
79
			'overwriteMarkdown' => isset($this->configurator->Litedown)
80
		];
81
	}
82
}