如何以编程方式覆盖 Ruport 数据表的格式化程序?
我在 Rails 应用程序中有一个非常简单的 Ruport 设置,其中 Ruport 控制器传递一个 Report::Data::Table
实例:
class Reporter < Ruport::Controller
stage :headline, :data, :footer
required_option :report
def setup
report_klass = options.report.report_model
report_klass ||= Report
self.data = report_klass.send(:report_table_by_sql, options.report.query)
end
end
Data::Table
实例当要求渲染时,存储在 data 中的数据使用 Ruport::Data::Table 作为其委托控制器,因此当我稍后调用
output << data.to_html
How can I Tell data 将其渲染方法委托给记者类,所以我所有的钩子覆盖都可以存在在一个地方?
I have a pretty straight-forward Ruport setup in my Rails app, where the Ruport controller is passed a Report::Data::Table
instance:
class Reporter < Ruport::Controller
stage :headline, :data, :footer
required_option :report
def setup
report_klass = options.report.report_model
report_klass ||= Report
self.data = report_klass.send(:report_table_by_sql, options.report.query)
end
end
The Data::Table
instance that is stored in data uses Ruport::Data::Table
as its delegated controller when asked to render, so that's what gets called when I later call
output << data.to_html
How can I tell data to delegate its rendering methods to the Reporter class, so all my hook overrides can live in one place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ruport 格式化程序被设计为封装在继承自 Formatter 的单独类中。
我相信类似的东西会实现你想要的:
Ruport formatters are designed to be encapsulated in a separate class that inherits from Formatter.
I believe something similar to this will achieve what you want:
Ruport 的 API 文档 明确表示您可以注册单个
Formatter
后代具有多个Controller
,因此,如果您想要一个实现所有挂钩的格式化程序,您可以简单地说:Ruport's API documentation makes it clear that you can register a single
Formatter
descendant with multipleControllers
, so if you want to have a single formatter that implements all the hooks, you can simply say as much: