I am trying to render a plain XML output within a Roar::Decorator. For some reason it is not possible to get unescaped output.
I have this class:
class GetShopProductsRequest < OpenStruct
def data_filter
xml_s = []
xml_s << "<Filter>"
xml_s << " <FilterName>#{self.filter_name}</FilterName>"
xml_s << " <FilterValues>"
xml_s << " <FilterValue>#{self.filter_value}</FilterValue>"
xml_s << " </FilterValues>"
xml_s << "</Filter>"
xml_s.join("\n")
end
end
and the following representer:
class GetShopProductsRequestRepresenter < RequestRepresenter
property :data_filter, as: :DataFilter
end
which inherits from Roar::Decorator
and includes Roar::XML
However, when I create my representer instance with
GetShopProductsRequestRepresenter.new(GetShopProductsRequest.new(:filter_value => 123, :filter_name => "test"))
and create the XML Output .to_xml
the output is
<DataFilter><Filter>
<FilterName>bla</FilterName>
<FilterValues>
<FilterValue>test</FilterValue>
</FilterValues>
</Filter></DataFilter>
I tried to use html_safe
at serveral spots in the code but nothing changed the result.
I would suggest using something like https://github.com/jimweirich/builder
This allows you to do: