thinreportsでテーブルオブジェクトのpage_footerにあるテキストブロックに値を直接埋め込む
環境
thinreports (0.7.7)
ぃみゎかんなぃ。。。。 もぅマヂ無理。。
アイテム一覧を作る必要があったので、
thinreportsエディターからテーブルオブジェクトを配置して、ページフッターにrubyで加工した文字を表示しようとすると、
下記みたいな謎っぽいコードが必要みたい。チュートリアルに出てきたので割りとガチっぽい。
# Generate reports. report = ThinReports::Report.create do |r| # Setting the layout for 'estimate.tlf' r.use_layout 'estimate.tlf' do |config| # Setting the :details list. config.list(:details) do use_stores :price => 0, :total_price => 0 # Dispatch at list-page-footer insertion. events.on :page_footer_insert do |e| # Set subtotal price. e.section.item(:price).value(e.store.price) # Initialize subtotal price to 0. e.store.price = 0 # ここあたり end # Dispatch at list-footer insertion. events.on :footer_insert do |e| # Set total price. e.section.item(:price).value(e.store.total_price) end end end ...
直接埋め込む
フッターに値を埋め込みたいだけなのでthinreportのオブジェクトを辿って、
テーブルオブジェクト内に設定されているなテキストブロックに直接値を入れた。
report.internal.default_layout.config. manager.format.shapes[:product_list]. # product_list => テーブルオブジェクトid instance_eval{@config}["sections"][:page_footer]. instance_eval{@shapes[:total]}.instance_eval{@config}["value"] = 'hoge' # total => テキストブロックid
もっと簡単にアクセスできなものなのだろうか...。
いつかソース読んでちゃんと攻略したいです。
以上。