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

Honor "omit-xml-declaration" in XSL stylesheets - issue #403 #404

Merged
merged 1 commit into from Mar 22, 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
2 changes: 1 addition & 1 deletion lib/nanoc/filters/xsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run(content, params = {})
xml = ::Nokogiri::XML(assigns[:content])
xsl = ::Nokogiri::XSLT(assigns[:layout].raw_content)

xsl.transform(xml, ::Nokogiri::XSLT.quote_params(params)).to_s
xsl.apply_to(xml, ::Nokogiri::XSLT.quote_params(params))
end

end
Expand Down
60 changes: 60 additions & 0 deletions test/filters/test_xsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,42 @@ class Nanoc::Filters::XSLTest < Nanoc::TestCase
<h1>bar</h1>
</body>
</html>
EOS

SAMPLE_XSL_WITH_OMIT_XML_DECL = <<-EOS
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"
omit-xml-declaration="yes"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="report/title"/></title>
</head>
<body>
<h1><xsl:value-of select="report/title"/></h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
EOS

SAMPLE_XML_IN_WITH_OMIT_XML_DECL = <<-EOS
<?xml version="1.0" encoding="utf-8"?>
<report>
<title>My Report</title>
</report>
EOS

SAMPLE_XML_OUT_WITH_OMIT_XML_DECL = <<-EOS
<html>
<head>
<title>My Report</title>
</head>
<body>
<h1>My Report</h1>
</body>
</html>
EOS

def test_filter_as_layout
Expand Down Expand Up @@ -125,4 +161,28 @@ def test_filter_with_params
end
end

def test_filter_with_omit_xml_decl
if_have 'nokogiri' do
# Create our data objects
item = Nanoc::Item.new(SAMPLE_XML_IN_WITH_OMIT_XML_DECL,
{ },
'/content/')
layout = Nanoc::Layout.new(SAMPLE_XSL_WITH_OMIT_XML_DECL,
{ },
'/layout/')

# Create an instance of the filter
assigns = {
:item => item,
:layout => layout,
:content => item.raw_content
}
filter = ::Nanoc::Filters::XSL.new(assigns)

# Run the filter and validate the results
result = filter.setup_and_run(layout.raw_content)
assert_equal SAMPLE_XML_OUT_WITH_OMIT_XML_DECL, result
end
end

end