Ruby ruport practice-ruport: formatter application extension

Source: Internet
Author: User

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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.