Ruby Ruport实践—Ruport::Formatter应用扩展
Ruport目前自带支持PDF,HTML,CSV,TXT格式输出,如果想打印.xml,.bat报表怎么办?
本例将以XML格式为例,实现Ruport::Formatter的另一种自定义应用。
Ruport的应用参考: Ruby Ruport实践—简单报表系统
注:其他格式的报表只需要修改renders对应的内容(如希望保存为.bat格式,将renders :xml改为renders :bat),模板输出内容均用
"output<<"方法进行输出即可
一、在ReportOutputController中添加xml格式
class ReportXml < Ruport::Formatter
renders :xml, :for => ReportOutputController
build :data_sheet do
eval(options[:outputContent])
end
end
二、report_templates中定义为如下内容的模板
output<<"<products>"
data.each do |d|
output<<"<product>"
output<<"<title>#{d.title}</title><type>#{d.description}</type><price>#{d.price}</price>"
output<<"</product>"
end
output<<"</products>"
注:为了测试方便,可将 "eval(options[:outputContent])"直接替换成模板内容
演示效果:
相关文档:
http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
Understanding Ruby Blocks, Procs and Lambdas
Blocks, Procs and lambdas (referred to as closures
in Computer Science) are one of the most powerful aspects of Ruby, and
also one of the most misunderstood. This ......
Prepare
1. Download 'OCI 1.x.x.rb' (it's VERY important - execution MUST be *.rb)
2. Download 'oci8lib.so'
Install
1. Copy 'OCI8.rb' to .../ruby/lib/ruby/site_ruby/1.8/DBD/OCI8
2. Copy 'oci8.rb' to .../ruby/lib/ruby/site_ruby/1.8
3. Copy 'oci8lib.so' to .../ruby/lib/ruby/site_ruby/1.8/i386-msv ......
%{String} 用于创建一个使用双引号括起来的字符串
%Q{String} 用于创建一个使用双引号括起来的字符串
%Q!Some String of “Characters”! <==> ” Some String of \”Characters\” “
%q{String} 用于创建一个使用单引号括起来的字符串
%q!Som ......
1、安装ubuntu
一路next,记住安装英文版。待安装完毕后,首先选择“软件源”,系统--系统管理-软件源,国内一般选择的是:http://ubuntu.cn99.com/ubuntu;接着安装中文包,选择软件源就是为了下载软件的速度更快,安装完成后重启ubuntu,重启后会提示是否改变某些文件夹名称,选择“否”,防止系统对 ......
Installing Ruby from source is my preferred method, although in Ubuntu Feisty you can supposedly install it with apt-get install ruby
now. Here’s the essential packages needed to get a source build working right though and the process I just went through:
sudo apt-get install build-essentia ......