Generator API が使いにくい問題の解決策として、クラスベースの実装方法を考える。 なお、クラスベースでの利用は Generator の当初の設計思想に含まれているが、現状ではいろいろ足りていない。
注意: 下記コードは、実装の提案のためのものであり、実際に動作するものではない。
| # coding: utf-8 | |
| class VisitorPassController < ApplicationController | |
| def create_pass | |
| visitor = Visitor.find(params[:id]) | |
| report = ThinReports::Report.new layout: File.join(Rails.root, 'app', 'reports', 'visitor_pass.tlf') | |
| report.start_new_page do |page| | |
| # jpg_filepath method will return the path of JPEG file. | |
| # e.g. "Rails.root/photos/visitor_001.jpg" | |
| page.item(:photo).src(visitor.jpg_filepath) |
| # coding: utf-8 | |
| require 'rubygems' | |
| require 'thinreports' | |
| require 'open-uri' | |
| def open_chart(*params) | |
| open('http://chart.googleapis.com/chart?' + URI.encode(params.join('&'))) | |
| end |
| # coding: utf-8 | |
| require 'rubygems' | |
| require 'thinreports' | |
| # Prepare sample data. | |
| data = [] | |
| my_info = { | |
| my_name: 'Matsukei Co., Ltd.', |
| class Membership < RedmineBase | |
| attr_accessor :id, :project_id, :user_id, :role_ids | |
| def project=(attrs = {}) | |
| self.project_id = attrs[:id] | |
| end | |
| def project | |
| if self.project_id | |
| return Project.all.find do |project| |