Ticket #162 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] render :xml :template support

Reported by: narna..@gmail.com Assigned to: narna..@gmail.com
Priority: trivial Milestone: 0.3.x
Component: Controlling Keywords:
Cc:

Description

Currently, when you call Controller#render(:xml=>true), it will ignore the :template option and use the default assumption that you want to use rxml, xerb or builder to generate it. Using another template engine is not possible unless you change the merb source.

For my project I needed to generate simple xml output (with correct headers and such) and since I already use haml to generate xhtml, I figured I could use it for xml as well. When I render it as just a xhtml view, I get the xml I want, but the header is an xhtml header instead of a xml header.

To set the proper header, I need to render it as :xml, but this is hardcoded to accept only the three template engines mentioned above. Just adding haml as a fourth engine would only work until someone thinks of yet another way to generate xml, so a more flexible approach would be more useful.

I made some small modifications to the Merb::RenderMixin#render? source that allows you to override the default behaviour by specifying a :template option. The :template option behaves just like it normally would when you specify a :template for rendering (x)html.

The patch works for me, so I updated the documentation and added a spec to test it.

Attachments

haml_xml.diff (2.7 kB) - added by narna..@gmail.com on 09/04/07 03:09:45.
Patch that adds :template support to render :xml. Complete with specs and docs.

Change History

09/04/07 03:09:45 changed by narna..@gmail.com

  • attachment haml_xml.diff added.

Patch that adds :template support to render :xml. Complete with specs and docs.

09/04/07 14:43:17 changed by e.@brainspl.at

  • status changed from new to closed.
  • resolution set to fixed.

(In [509]) add better support for rendering xml templates, closes #162 thanks narna..@gmail.com