# encoding: utf-8 require 'tempfile' class Nanoc::Filters::XSLTest < Nanoc::TestCase SAMPLE_XSL = <<-EOS <xsl:value-of select="report/title"/>

EOS SAMPLE_XML_IN = <<-EOS My Report EOS SAMPLE_XML_OUT = <<-EOS My Report

My Report

EOS SAMPLE_XSL_WITH_PARAMS = <<-EOS <xsl:value-of select="report/title"/>

EOS SAMPLE_XML_IN_WITH_PARAMS = <<-EOS My Report EOS SAMPLE_XML_OUT_WITH_PARAMS = <<-EOS My Report

bar

EOS SAMPLE_XSL_WITH_OMIT_XML_DECL = <<-EOS <xsl:value-of select="report/title"/>

EOS SAMPLE_XML_IN_WITH_OMIT_XML_DECL = <<-EOS My Report EOS SAMPLE_XML_OUT_WITH_OMIT_XML_DECL = <<-EOS My Report

My Report

EOS def test_filter_as_layout if_have 'nokogiri' do # Create our data objects item = Nanoc::Item.new(SAMPLE_XML_IN, { }, '/content/') layout = Nanoc::Layout.new(SAMPLE_XSL, { }, '/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, result end end def test_filter_with_params if_have 'nokogiri' do # Create our data objects item = Nanoc::Item.new(SAMPLE_XML_IN_WITH_PARAMS, { }, '/content/') layout = Nanoc::Layout.new(SAMPLE_XSL_WITH_PARAMS, { }, '/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, :foo => 'bar') assert_equal SAMPLE_XML_OUT_WITH_PARAMS, result 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