Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Choosing a better naming for the funtonality for pre-setting NS attri…
Browse files Browse the repository at this point in the history
…butes.
  • Loading branch information
nikolaposa committed Dec 5, 2014
1 parent 88e1fe0 commit daddb10
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
27 changes: 14 additions & 13 deletions src/Helper/HtmlTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ class HtmlTag extends AbstractHtmlElement
protected $attributes = array();

/**
* Whether to add appropriate attributes in accordance with currently set DOCTYPE.
* Whether to pre-set appropriate attributes in accordance
* with the currently set DOCTYPE.
*
* @var bool
*/
protected $addDoctypeAttributes = false;
protected $useNamespaces = false;

/**
* @var bool
*/
private $doctypeAttribsAdded = false;
private $handledNamespaces = false;

/**
* Retrieve object instance; optionally add attributes.
Expand Down Expand Up @@ -87,21 +88,21 @@ public function getAttributes()
}

/**
* @param bool $addDoctypeAttributes
* @param bool $useNamespaces
* @return self
*/
public function setAddDoctypeAttributes($addDoctypeAttributes)
public function setUseNamespaces($useNamespaces)
{
$this->addDoctypeAttributes = (bool) $addDoctypeAttributes;
$this->useNamespaces = (bool) $useNamespaces;
return $this;
}

/**
* @return bool
*/
public function getAddDoctypeAttributes()
public function getUseNamespaces()
{
return $this->addDoctypeAttributes;
return $this->useNamespaces;
}

/**
Expand All @@ -111,14 +112,14 @@ public function getAddDoctypeAttributes()
*/
public function openTag()
{
$this->handleDoctypeAttributes();
$this->handleNamespaceAttributes();

return sprintf('<html%s>', $this->htmlAttribs($this->attributes));
}

protected function handleDoctypeAttributes()
protected function handleNamespaceAttributes()
{
if ($this->addDoctypeAttributes && !$this->doctypeAttribsAdded) {
if ($this->useNamespaces && !$this->handledNamespaces) {
if (method_exists($this->view, 'plugin')) {
$doctypeAttributes = array();

Expand All @@ -131,7 +132,7 @@ protected function handleDoctypeAttributes()
}
}

$this->doctypeAttribsAdded = true;
$this->handledNamespaces = true;
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/Helper/HtmlTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,21 @@ public function testRenderingCloseTag()
$this->assertEquals('</html>', $this->helper->closeTag());
}

public function testDoctypeAttributesSetter()
public function testUseNamespacesSetter()
{
$this->helper->setAddDoctypeAttributes(true);
$this->assertTrue($this->helper->getAddDoctypeAttributes());
$this->helper->setUseNamespaces(true);
$this->assertTrue($this->helper->getUseNamespaces());
}

public function testAppropriateDoctypeAttributesArePresetIfFlagIsOn()
public function testAppropriateNamespaceAttributesAreSetIfFlagIsOn()
{
$this->view->plugin('doctype')->setDoctype('xhtml');

$attribs = array(
'prefix' => 'og: http://ogp.me/ns#',
);

$this->helper->setAddDoctypeAttributes(true)->setAttributes($attribs);
$this->helper->setUseNamespaces(true)->setAttributes($attribs);

$tag = $this->helper->openTag();

Expand Down

0 comments on commit daddb10

Please sign in to comment.