Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ignoring a doctype definition #17

Merged
merged 1 commit into from
May 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/Goetas/Twital/SourceAdapter/HTML5Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ private static function fixNss(\DOMElement $element, $namespaces = array())
public function dump(Template $template)
{
$metadata = $template->getMetadata();
$dom = $template->getDocument();

if (! $metadata['doctype']) {
return HTML5::saveHTML($template->getDocument()->childNodes);
}

return HTML5::saveHTML($template->getDocument()->childNodes);
return HTML5::saveHTML($metadata['fragment'] ? $dom->childNodes : $dom);
}

/**
Expand All @@ -83,7 +80,7 @@ protected function collectMetadata(\DOMDocument $dom, $source)
$metadata = array();

$metadata['doctype'] = !! $dom->doctype;
$metadata['fragment'] = !! strpos(rtrim($source), '<!DOCTYPE html>') === 0;
$metadata['fragment'] = strpos(rtrim($source), '<!DOCTYPE html>') !== 0;

return $metadata;
}
Expand Down
14 changes: 1 addition & 13 deletions src/Goetas/Twital/SourceAdapter/XHTMLAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,7 @@ class XHTMLAdapter extends XMLAdapter
*/
public function dump(Template $template)
{
$metedata = $template->getMetadata();
$dom = $template->getDocument();

if ($metedata['xmldeclaration']) {
$source = $dom->saveXML();
} else {
$source = '';
foreach ($dom->childNodes as $node) {
$source .= $dom->saveXML($node);
}
}

return $this->replaceShortTags($source);
return $this->replaceShortTags(parent::dump($template));
}

protected function replaceShortTags($str)
Expand Down
2 changes: 1 addition & 1 deletion src/Goetas/Twital/SourceAdapter/XMLAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function collectMetadata(\DOMDocument $dom, $source)
$metadata = array();

$metadata['xmldeclaration'] = strpos(rtrim($source), '<?xml ') === 0;
$metadata['doctype'] = ! ! $dom->doctype;
$metadata['doctype'] = !! $dom->doctype;

return $metadata;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Goetas/Twital/Tests/Html5CoreNodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getDataFormTemplates()
} else {
$expectedFile = substr($file, 0, -4).".twig";
}
$expected = trim(file_get_contents($expectedFile));
$expected = file_get_contents($expectedFile);

$data[] = array(
$source,
Expand Down
3 changes: 3 additions & 0 deletions tests/Goetas/Twital/Tests/templates/doctype-01.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<html><body>foo</body>
</html>
1 change: 1 addition & 0 deletions tests/Goetas/Twital/Tests/templates/doctype-01.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><body>foo</body></html>
2 changes: 2 additions & 0 deletions tests/Goetas/Twital/Tests/templates/doctype-01.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<html><body>foo</body></html>