Currently, ruport supports output in PDF, HTML, CSV, and TXT formats. What if you want to print. xml and. Bat reports?
This example uses the XML format as an example to implement another custom application of ruport: formatter.
Ruport application reference: Ruby ruport practice-simple report system
Note: For reports in other formats, you only need to modify the content corresponding to renders (for example, you want to save it as. BAT and change renders: XML to renders: BAT ).
The "output <" method can be output.
1. Add XML format to reportoutputcontroller
Class reportxml <ruport: formatter <br/> renders: XML,: For => reportoutputcontroller <br/> build: data_sheet DO <br/> eval (options [: outputcontent]) <br/> end
2. Templates defined in report_templates as the following content
Output <"<Products>" <br/> data. each do | d | <br/> output <"<product>" <br/> output <"<title >#{ D. title} </title> <type >#{ D. description} </type> <price >#{ D. price} </price> "<br/> output <" </product> "<br/> end <br/> output <" </Products>"
Note: For testing convenience, you can directly Replace "eval (options [: outputcontent])" with the template content.
Demo effect: