├── .gitignore ├── .travis.yml ├── Gemfile ├── LICENSE ├── README.md ├── gemfiles ├── Gemfile-rails.3.0.x ├── Gemfile-rails.3.1.x ├── Gemfile-rails.3.2.x ├── Gemfile-rails.4.0.x ├── Gemfile-rails.4.1.x ├── Gemfile-rails.4.2.x ├── Gemfile-rails.5.0.x ├── Gemfile-rails.5.1.x ├── Gemfile-rails.5.2.x └── Gemfile-rails.6.0.x ├── lib ├── thinreports-rails.rb └── thinreports-rails │ ├── railtie.rb │ ├── template_handler.rb │ └── version.rb ├── test ├── test_app │ ├── app │ │ └── views │ │ │ ├── orders │ │ │ ├── _header.pdf.thinreports │ │ │ ├── _other_header.pdf.thinreports │ │ │ ├── index.pdf.thinreports │ │ │ ├── index.tlf │ │ │ ├── no_set_layout.pdf.thinreports │ │ │ ├── no_set_layout.tlf │ │ │ ├── no_tlf.pdf.thinreports │ │ │ └── other_tlf_path.pdf.thinreports │ │ │ └── reports │ │ │ └── other.tlf │ └── test_app.rb └── thinreports-rails_test.rb └── thinreports-rails.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/log 17 | test/version_tmp 18 | tmp 19 | log 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | 3 | script: ruby test/thinreports-rails_test.rb 4 | 5 | sudo: false 6 | 7 | rvm: 8 | - 2.4.1 9 | - 2.3.1 10 | - 2.2.4 11 | - 2.1 12 | 13 | gemfile: 14 | - gemfiles/Gemfile-rails.3.0.x 15 | - gemfiles/Gemfile-rails.3.1.x 16 | - gemfiles/Gemfile-rails.3.2.x 17 | - gemfiles/Gemfile-rails.4.0.x 18 | - gemfiles/Gemfile-rails.4.1.x 19 | - gemfiles/Gemfile-rails.4.2.x 20 | - gemfiles/Gemfile-rails.5.0.x 21 | - gemfiles/Gemfile-rails.5.1.x 22 | - gemfiles/Gemfile-rails.5.2.x 23 | 24 | matrix: 25 | include: 26 | - rvm: 2.5.6 27 | gemfile: gemfiles/Gemfile-rails.6.0.x 28 | - rvm: 2.6.4 29 | gemfile: gemfiles/Gemfile-rails.6.0.x 30 | exclude: 31 | - rvm: 2.1 32 | gemfile: gemfiles/Gemfile-rails.5.0.x 33 | - rvm: 2.1 34 | gemfile: gemfiles/Gemfile-rails.5.1.x 35 | - rvm: 2.1 36 | gemfile: gemfiles/Gemfile-rails.5.2.x 37 | - rvm: 2.4.1 38 | gemfile: gemfiles/Gemfile-rails.3.0.x 39 | - rvm: 2.4.1 40 | gemfile: gemfiles/Gemfile-rails.3.1.x 41 | - rvm: 2.4.1 42 | gemfile: gemfiles/Gemfile-rails.3.2.x 43 | - rvm: 2.4.1 44 | gemfile: gemfiles/Gemfile-rails.4.0.x 45 | - rvm: 2.4.1 46 | gemfile: gemfiles/Gemfile-rails.4.1.x 47 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in thinreports-rails.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Takeshi Shinoda 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ThinreportsRails 2 | ThinreportsRails is constructed by Rails Template Handler [ThinReports](http://www.thinreports.org/ "ThinReposts") the PDF. 3 | 4 | [![Build Status](https://travis-ci.org/takeshinoda/thinreports-rails.svg?branch=master)](https://travis-ci.org/takeshinoda/thinreports-rails) 5 | 6 | Oldname: thinreports-handler 7 | 8 | 9 | ## Supported versions 10 | 11 | * Ruby 2.1.X, 2.2.X, 2.3.X 12 | * Rails 3.X, 4.X, 5.X, 6.0 13 | * ThinReports 0.10.0 or later 14 | 15 | ## Installation 16 | 17 | Add this line to your application's Gemfile: 18 | 19 | gem 'thinreports-rails' 20 | 21 | And then execute: 22 | 23 | $ bundle 24 | 25 | Or install it yourself as: 26 | 27 | $ gem install thinreports-rails 28 | 29 | ## Usage 30 | 31 | ### Example to, Display in the browser. 32 | 33 | #### Controllers 34 | ``` ruby 35 | class OrdersController < ApplicationController 36 | def index 37 | @orders = Order.all 38 | end 39 | end 40 | ``` 41 | 42 | #### Views 43 | 44 | app/views/orders/index.pdf.thinreports 45 | 46 | ``` ruby 47 | report.start_new_page 48 | report.page.values printed_at: Time.now 49 | @orders.each do |order| 50 | report.page.list(:list).add_row do |row| 51 | row.item(:col1).value order.name 52 | row.item(:col2).value order.num 53 | end 54 | end 55 | ``` 56 | 57 | ### Example to, Download PDF. 58 | 59 | ``` ruby 60 | class OrdersController < ApplicationController 61 | def index 62 | @orders = Order.all 63 | respond_to do |format| 64 | format.pdf { 65 | send_data render_to_string, filename: 'foo.pdf', type: 'application/pdf', disposition: 'attachment' 66 | } 67 | end 68 | end 69 | end 70 | ``` 71 | 72 | ### Configuration 73 | 74 | ### Layout file(.tlf) and options. 75 | 76 | Example of using the `app/views/reports/index.tlf`. 77 | Write code like this to `index.pdf.thinreports`. 78 | 79 | `:layout_options` is an option `ThinReports::Report::Base#use_layout` method. 80 | 81 | ``` ruby 82 | report.set_layout tlf: 'reports/index', layout_options: { default: true } 83 | ``` 84 | 85 | ### generate options. 86 | ``` ruby 87 | report.generate_options(security: { 88 | user_password: 'foo', 89 | owner_password: 'bar', 90 | permissions: { 91 | print_document: false, 92 | modify_contents: false, 93 | copy_contents: false 94 | } 95 | }) 96 | ``` 97 | 98 | ### Partial 99 | 100 | For exsample to use, `app/views/orders/_header.pdf.thinreports`. 101 | `title` is local variable in `_header.pdf.thinreports`. 102 | 103 | ``` ruby 104 | report.partial! 'header', title: title 105 | ``` 106 | 107 | ## Author 108 | 109 | * TwitterID: @takeshinoda 110 | * Blog: http://d.hatena.ne.jp/takeshinoda/ 111 | 112 | ## Contributing 113 | 114 | m(__)m, send me pull request. 115 | 116 | ## Copyright 117 | 118 | Copyright (c) 2012 Takeshi Shinoda. 119 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.3.0.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 3.0.0' 3 | gemspec :path => '../' 4 | 5 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.3.1.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 3.1.0' 3 | gemspec :path => '../' 4 | 5 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.3.2.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 3.2.0' 3 | gemspec :path => '../' 4 | 5 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.4.0.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 4.0.0' 3 | gemspec :path => '../' 4 | 5 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.4.1.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 4.1.0' 3 | gemspec :path => '../' 4 | 5 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.4.2.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 4.2.0' 3 | gemspec :path => '../' 4 | 5 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.5.0.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 5.0.0' 3 | gemspec :path => '../' 4 | 5 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.5.1.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 5.1.0' 3 | gemspec :path => '../' 4 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.5.2.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 5.2.0' 3 | gemspec :path => '../' 4 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.6.0.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '~> 6.0.0' 3 | gemspec :path => '../' 4 | -------------------------------------------------------------------------------- /lib/thinreports-rails.rb: -------------------------------------------------------------------------------- 1 | require "thinreports-rails/version" 2 | require "thinreports-rails/railtie" 3 | 4 | -------------------------------------------------------------------------------- /lib/thinreports-rails/railtie.rb: -------------------------------------------------------------------------------- 1 | require 'rails' 2 | 3 | module ThinreportsRails 4 | class Railtie < ::Rails::Railtie 5 | initializer 'thinreports-rails' do 6 | ::ActiveSupport.on_load(:action_view) do 7 | ::Mime::Type.register('application/pdf', :pdf) unless ::Mime::Type.lookup_by_extension(:pdf) 8 | require 'thinreports-rails/template_handler' 9 | end 10 | end 11 | end 12 | end 13 | 14 | -------------------------------------------------------------------------------- /lib/thinreports-rails/template_handler.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require 'delegate' 3 | require 'active_support/core_ext' 4 | require 'thinreports' 5 | 6 | module ThinreportsRails 7 | class ThinreportsTemplate < SimpleDelegator 8 | attr_accessor :_generate_options 9 | 10 | def initialize(thinreports_report_base_obj, template_context, template_virtual_path) 11 | @_template_context = template_context 12 | @_template_virtual_path = template_virtual_path 13 | super(thinreports_report_base_obj) 14 | end 15 | 16 | def partial!(options, locals = {}) 17 | case options 18 | when Hash 19 | options[:locals] ||= {} 20 | options[:locals].merge!(:report => self) 21 | @_template_context.render(options) 22 | else 23 | @_template_context.render(options, locals.merge(:report => self)) 24 | end 25 | end 26 | 27 | def search_tlf_path(virtual_path) 28 | "#{virtual_path || @_template_virtual_path}.tlf" 29 | end 30 | 31 | def generate_options(options) 32 | self._generate_options = options 33 | end 34 | 35 | def set_layout(options = {}) 36 | _options = options ? options.dup: {} 37 | tlf_path = search_tlf_path(_options[:tlf]) 38 | 39 | ActionController::Base.view_paths.each do |view_path| 40 | full_path = File.join(view_path.to_s, tlf_path) 41 | if File.exist?(full_path) 42 | return self.use_layout(full_path, *([_options[:layout_options]].compact)) 43 | end 44 | end 45 | raise("#{tlf_path} not found.") unless _options[:allow_no_layout] 46 | end 47 | end 48 | 49 | class TemplateHandler 50 | cattr_accessor :default_format 51 | self.default_format = 'application/pdf' 52 | 53 | def self.call(template, source = nil) 54 | source ||= template.source 55 | 56 | %{ 57 | if defined?(report) 58 | #{source} 59 | else 60 | generate_options = nil 61 | Thinreports::Report.create do |__report__| 62 | report = ThinreportsRails::ThinreportsTemplate.new(__report__, self, '#{template.virtual_path}') 63 | report.set_layout :allow_no_layout => true 64 | 65 | #{source} 66 | 67 | generate_options = report._generate_options 68 | end.generate(*([generate_options].compact)) 69 | end 70 | } 71 | end 72 | end 73 | end 74 | 75 | ActionView::Template.register_template_handler :thinreports, ThinreportsRails::TemplateHandler 76 | -------------------------------------------------------------------------------- /lib/thinreports-rails/version.rb: -------------------------------------------------------------------------------- 1 | module ThinreportsRails 2 | VERSION = "0.5.0" 3 | end 4 | 5 | -------------------------------------------------------------------------------- /test/test_app/app/views/orders/_header.pdf.thinreports: -------------------------------------------------------------------------------- 1 | report.start_new_page 2 | report.page.values :printed_at => Time.at(OrdersController::CURRENT) # 2012-06-27 11:41:33 +0900 3 | -------------------------------------------------------------------------------- /test/test_app/app/views/orders/_other_header.pdf.thinreports: -------------------------------------------------------------------------------- 1 | report.start_new_page 2 | report.page.values :printed_at => current_time 3 | 4 | -------------------------------------------------------------------------------- /test/test_app/app/views/orders/index.pdf.thinreports: -------------------------------------------------------------------------------- 1 | report.set_layout 2 | report.partial! 'header' 3 | @orders.each do |order| 4 | report.page.list(:list).add_row do |row| 5 | row.item(:col1).value order.name 6 | row.item(:col2).value order.num 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/test_app/app/views/orders/index.tlf: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.9.0", 3 | "items": [ 4 | { 5 | "id": "printed_at", 6 | "type": "text-block", 7 | "display": true, 8 | "description": "", 9 | "x": 339.1, 10 | "y": 100, 11 | "width": 236.1, 12 | "height": 18, 13 | "style": { 14 | "font-family": [ 15 | "Helvetica" 16 | ], 17 | "font-size": 18, 18 | "color": "#000000", 19 | "text-align": "left", 20 | "vertical-align": "top", 21 | "line-height": "", 22 | "line-height-ratio": "", 23 | "letter-spacing": "", 24 | "font-style": [], 25 | "overflow": "truncate", 26 | "word-wrap": "none" 27 | }, 28 | "reference-id": "", 29 | "value": "", 30 | "multiple-line": false, 31 | "format": { 32 | "base": "", 33 | "type": "datetime", 34 | "datetime": { 35 | "format": "%Y/%m/%d %H:%M:%S" 36 | } 37 | } 38 | }, 39 | { 40 | "id": "", 41 | "type": "text", 42 | "display": true, 43 | "description": "", 44 | "x": 166.1, 45 | "y": 20, 46 | "width": 263, 47 | "height": 52, 48 | "style": { 49 | "font-family": [ 50 | "IPAPMincho" 51 | ], 52 | "font-size": 48, 53 | "color": "#000000", 54 | "text-align": "center", 55 | "vertical-align": "top", 56 | "line-height": "", 57 | "line-height-ratio": "", 58 | "letter-spacing": "", 59 | "font-style": [] 60 | }, 61 | "texts": [ 62 | "テスト注文書" 63 | ] 64 | }, 65 | { 66 | "id": "list", 67 | "type": "list", 68 | "display": true, 69 | "description": "", 70 | "x": 20, 71 | "y": 178.1, 72 | "width": 555.2, 73 | "height": 511.1, 74 | "header": { 75 | "enabled": true, 76 | "height": 7.4, 77 | "translate": { 78 | "x": -47, 79 | "y": -30 80 | }, 81 | "items": [] 82 | }, 83 | "detail": { 84 | "height": 34.6, 85 | "translate": { 86 | "x": -47, 87 | "y": -30 88 | }, 89 | "items": [ 90 | { 91 | "id": "col1", 92 | "type": "text-block", 93 | "display": true, 94 | "description": "", 95 | "x": 67, 96 | "y": 215.5, 97 | "width": 274.1, 98 | "height": 18, 99 | "style": { 100 | "font-family": [ 101 | "Helvetica" 102 | ], 103 | "font-size": 18, 104 | "color": "#000000", 105 | "text-align": "left", 106 | "vertical-align": "top", 107 | "line-height": "", 108 | "line-height-ratio": "", 109 | "letter-spacing": "", 110 | "font-style": [], 111 | "overflow": "truncate", 112 | "word-wrap": "none" 113 | }, 114 | "reference-id": "", 115 | "value": "", 116 | "multiple-line": false, 117 | "format": { 118 | "base": "", 119 | "type": "" 120 | } 121 | }, 122 | { 123 | "id": "col2", 124 | "type": "text-block", 125 | "display": true, 126 | "description": "", 127 | "x": 342.2, 128 | "y": 215.5, 129 | "width": 280, 130 | "height": 18, 131 | "style": { 132 | "font-family": [ 133 | "Helvetica" 134 | ], 135 | "font-size": 18, 136 | "color": "#000000", 137 | "text-align": "left", 138 | "vertical-align": "top", 139 | "line-height": "", 140 | "line-height-ratio": "", 141 | "letter-spacing": "", 142 | "font-style": [], 143 | "overflow": "truncate", 144 | "word-wrap": "none" 145 | }, 146 | "reference-id": "", 147 | "value": "", 148 | "multiple-line": false, 149 | "format": { 150 | "base": "", 151 | "type": "" 152 | } 153 | }, 154 | { 155 | "id": "", 156 | "type": "line", 157 | "display": true, 158 | "description": "", 159 | "style": { 160 | "border-color": "#000000", 161 | "border-width": 1, 162 | "border-style": "solid" 163 | }, 164 | "x1": 67, 165 | "y1": 235, 166 | "x2": 575.2, 167 | "y2": 235 168 | }, 169 | { 170 | "id": "", 171 | "type": "line", 172 | "display": true, 173 | "description": "", 174 | "style": { 175 | "border-color": "#000000", 176 | "border-width": 1, 177 | "border-style": "solid" 178 | }, 179 | "x1": 622.2, 180 | "y1": 250.1, 181 | "x2": 575.2, 182 | "y2": 249.1 183 | } 184 | ] 185 | }, 186 | "page-footer": { 187 | "enabled": true, 188 | "height": 5.6, 189 | "translate": { 190 | "x": -47, 191 | "y": -2.8 192 | }, 193 | "items": [] 194 | }, 195 | "footer": { 196 | "enabled": true, 197 | "height": 5.6, 198 | "translate": { 199 | "x": -47, 200 | "y": -2.8 201 | }, 202 | "items": [] 203 | }, 204 | "content-height": 503.70000000000005, 205 | "auto-page-break": true 206 | }, 207 | { 208 | "id": "", 209 | "type": "line", 210 | "display": true, 211 | "description": "", 212 | "style": { 213 | "border-color": "#000000", 214 | "border-width": 1, 215 | "border-style": "solid" 216 | }, 217 | "x1": 158.8, 218 | "y1": 84, 219 | "x2": 427.4, 220 | "y2": 84 221 | } 222 | ], 223 | "state": { 224 | "layout-guides": [] 225 | }, 226 | "title": "Japanese Paper", 227 | "report": { 228 | "paper-type": "A4", 229 | "orientation": "portrait", 230 | "margin": [ 231 | 20, 232 | 20, 233 | 20, 234 | 20 235 | ] 236 | } 237 | } -------------------------------------------------------------------------------- /test/test_app/app/views/orders/no_set_layout.pdf.thinreports: -------------------------------------------------------------------------------- 1 | report.partial! 'header' 2 | @orders.each do |order| 3 | report.page.list(:list).add_row do |row| 4 | row.item(:col1).value order.name 5 | row.item(:col2).value order.num 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/test_app/app/views/orders/no_set_layout.tlf: -------------------------------------------------------------------------------- 1 | index.tlf -------------------------------------------------------------------------------- /test/test_app/app/views/orders/no_tlf.pdf.thinreports: -------------------------------------------------------------------------------- 1 | report.set_layout :tlf => 'orders/no_tlf' 2 | report.partial! 'header' 3 | -------------------------------------------------------------------------------- /test/test_app/app/views/orders/other_tlf_path.pdf.thinreports: -------------------------------------------------------------------------------- 1 | report.set_layout :tlf => 'reports/other' 2 | report.partial! 'other_header', :current_time => Time.at(OrdersController::CURRENT) # 2012-06-27 11:41:33 +0900 3 | @orders.each do |order| 4 | report.page.list(:list).add_row do |row| 5 | row.item(:col1).value order.name 6 | row.item(:col2).value order.num 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/test_app/app/views/reports/other.tlf: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.9.0", 3 | "items": [ 4 | { 5 | "id": "printed_at", 6 | "type": "text-block", 7 | "display": true, 8 | "description": "", 9 | "x": 339.1, 10 | "y": 100, 11 | "width": 236.1, 12 | "height": 18, 13 | "style": { 14 | "font-family": [ 15 | "Helvetica" 16 | ], 17 | "font-size": 18, 18 | "color": "#000000", 19 | "text-align": "left", 20 | "vertical-align": "top", 21 | "line-height": "", 22 | "line-height-ratio": "", 23 | "letter-spacing": "", 24 | "font-style": [], 25 | "overflow": "truncate", 26 | "word-wrap": "none" 27 | }, 28 | "reference-id": "", 29 | "value": "", 30 | "multiple-line": false, 31 | "format": { 32 | "base": "", 33 | "type": "datetime", 34 | "datetime": { 35 | "format": "%Y/%m/%d %H:%M:%S" 36 | } 37 | } 38 | }, 39 | { 40 | "id": "", 41 | "type": "text", 42 | "display": true, 43 | "description": "", 44 | "x": 166.1, 45 | "y": 20, 46 | "width": 288, 47 | "height": 52, 48 | "style": { 49 | "font-family": [ 50 | "IPAPMincho" 51 | ], 52 | "font-size": 48, 53 | "color": "#000000", 54 | "text-align": "center", 55 | "vertical-align": "top", 56 | "line-height": "", 57 | "line-height-ratio": "", 58 | "letter-spacing": "", 59 | "font-style": [] 60 | }, 61 | "texts": [ 62 | "テスト注文書" 63 | ] 64 | }, 65 | { 66 | "id": "list", 67 | "type": "list", 68 | "display": true, 69 | "description": "", 70 | "x": 20, 71 | "y": 178.1, 72 | "width": 555.2, 73 | "height": 511.1, 74 | "header": { 75 | "enabled": true, 76 | "height": 7.4, 77 | "translate": { 78 | "x": -47, 79 | "y": -30 80 | }, 81 | "items": [] 82 | }, 83 | "detail": { 84 | "height": 34.6, 85 | "translate": { 86 | "x": -47, 87 | "y": -30 88 | }, 89 | "items": [ 90 | { 91 | "id": "col1", 92 | "type": "text-block", 93 | "display": true, 94 | "description": "", 95 | "x": 67, 96 | "y": 215.5, 97 | "width": 274.1, 98 | "height": 18, 99 | "style": { 100 | "font-family": [ 101 | "Helvetica" 102 | ], 103 | "font-size": 18, 104 | "color": "#000000", 105 | "text-align": "left", 106 | "vertical-align": "top", 107 | "line-height": "", 108 | "line-height-ratio": "", 109 | "letter-spacing": "", 110 | "font-style": [], 111 | "overflow": "truncate", 112 | "word-wrap": "none" 113 | }, 114 | "reference-id": "", 115 | "value": "", 116 | "multiple-line": false, 117 | "format": { 118 | "base": "", 119 | "type": "" 120 | } 121 | }, 122 | { 123 | "id": "col2", 124 | "type": "text-block", 125 | "display": true, 126 | "description": "", 127 | "x": 342.2, 128 | "y": 215.5, 129 | "width": 280, 130 | "height": 18, 131 | "style": { 132 | "font-family": [ 133 | "Helvetica" 134 | ], 135 | "font-size": 18, 136 | "color": "#000000", 137 | "text-align": "left", 138 | "vertical-align": "top", 139 | "line-height": "", 140 | "line-height-ratio": "", 141 | "letter-spacing": "", 142 | "font-style": [], 143 | "overflow": "truncate", 144 | "word-wrap": "none" 145 | }, 146 | "reference-id": "", 147 | "value": "", 148 | "multiple-line": false, 149 | "format": { 150 | "base": "", 151 | "type": "" 152 | } 153 | }, 154 | { 155 | "id": "", 156 | "type": "line", 157 | "display": true, 158 | "description": "", 159 | "style": { 160 | "border-color": "#000000", 161 | "border-width": 1, 162 | "border-style": "solid" 163 | }, 164 | "x1": 67, 165 | "y1": 235, 166 | "x2": 575.2, 167 | "y2": 235 168 | }, 169 | { 170 | "id": "", 171 | "type": "line", 172 | "display": true, 173 | "description": "", 174 | "style": { 175 | "border-color": "#000000", 176 | "border-width": 1, 177 | "border-style": "solid" 178 | }, 179 | "x1": 622.2, 180 | "y1": 250.1, 181 | "x2": 575.2, 182 | "y2": 249.1 183 | } 184 | ] 185 | }, 186 | "page-footer": { 187 | "enabled": true, 188 | "height": 5.6, 189 | "translate": { 190 | "x": -47, 191 | "y": -2.8 192 | }, 193 | "items": [] 194 | }, 195 | "footer": { 196 | "enabled": true, 197 | "height": 5.6, 198 | "translate": { 199 | "x": -47, 200 | "y": -2.8 201 | }, 202 | "items": [] 203 | }, 204 | "content-height": 503.70000000000005, 205 | "auto-page-break": true 206 | }, 207 | { 208 | "id": "", 209 | "type": "line", 210 | "display": true, 211 | "description": "", 212 | "style": { 213 | "border-color": "#000000", 214 | "border-width": 1, 215 | "border-style": "solid" 216 | }, 217 | "x1": 158.8, 218 | "y1": 84, 219 | "x2": 427.4, 220 | "y2": 84 221 | } 222 | ], 223 | "state": { 224 | "layout-guides": [] 225 | }, 226 | "title": "Japanese Paper", 227 | "report": { 228 | "paper-type": "A4", 229 | "orientation": "portrait", 230 | "margin": [ 231 | 20, 232 | 20, 233 | 20, 234 | 20 235 | ] 236 | } 237 | } -------------------------------------------------------------------------------- /test/test_app/test_app.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require 'action_controller/railtie' 3 | require 'action_view/railtie' 4 | 5 | module ThinreportsRailsTestApp 6 | class Application < Rails::Application 7 | if Rails.version >= '4.0.0' 8 | config.eager_load = false 9 | config.secret_key_base = 'aaaaaaaaa' 10 | end 11 | config.active_support.deprecation = :log 12 | config.root = File.dirname(__FILE__) 13 | end 14 | end 15 | ThinreportsRailsTestApp::Application.initialize! 16 | 17 | 18 | # Route 19 | ThinreportsRailsTestApp::Application.routes.draw do 20 | resources :orders, :only => [:index] do 21 | collection do 22 | get 'no_tlf' 23 | get 'other_tlf_path' 24 | get 'no_set_layout' 25 | end 26 | end 27 | end 28 | 29 | 30 | # Model 31 | class Order 32 | attr_accessor :name, :num 33 | 34 | def initialize(name, num) 35 | self.name = name 36 | self.num = num 37 | end 38 | end 39 | 40 | 41 | # Controller 42 | class ApplicationController < ActionController::Base; end 43 | 44 | class OrdersController < ApplicationController 45 | CURRENT = 1340764893 # 2012-06-27 11:41:33 +0900 46 | 47 | def index 48 | @orders = [Order.new('order1', 2), 49 | Order.new('order2', 10)] 50 | respond_to do |f| 51 | f.pdf { render } 52 | end 53 | end 54 | alias no_tlf index 55 | alias other_tlf_path index 56 | alias no_set_layout index 57 | end 58 | 59 | -------------------------------------------------------------------------------- /test/thinreports-rails_test.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 3 | $LOAD_PATH.unshift(File.dirname(__FILE__)) 4 | 5 | require 'rubygems' 6 | 7 | require 'rails' 8 | 9 | if Rails.version[0..2] >= '4.1' 10 | require 'minitest/autorun' 11 | else 12 | require 'test/unit' 13 | end 14 | 15 | require 'rack/test' 16 | require 'rails/test_help' 17 | 18 | require 'thinreports-rails' 19 | require 'test_app/test_app' 20 | 21 | class ThinreportsRailsTest < ActionController::TestCase 22 | tests OrdersController 23 | 24 | test 'index.tlf is selected.' do 25 | get :index, :format => :pdf 26 | assert_response :success 27 | end 28 | 29 | test 'other tlf can select.' do 30 | get :other_tlf_path, :format => :pdf 31 | assert_response :success 32 | end 33 | 34 | test 'use default tlf. no call set_layout. ' do 35 | get :no_set_layout, :format => :pdf 36 | assert_response :success 37 | end 38 | 39 | test 'tlf can not choose not. raise Exception.' do 40 | assert_raise(ActionView::Template::Error) { get :no_tlf, :format => :pdf } 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /thinreports-rails.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/thinreports-rails/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["Takeshi Shinoda"] 6 | gem.email = ["takeshinoda@gmail.com"] 7 | gem.description = %q{Rails plugin for ThinReports DSL. This plugin can write DSL to View.} 8 | gem.summary = %q{Rails plugin for ThinReports DSL.} 9 | gem.homepage = "https://github.com/takeshinoda/thinreports-rails" 10 | 11 | gem.files = `git ls-files`.split($\) 12 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 13 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 14 | gem.name = "thinreports-rails" 15 | gem.require_paths = ["lib"] 16 | gem.version = ThinreportsRails::VERSION 17 | 18 | gem.add_runtime_dependency "thinreports", '>= 0.10' 19 | gem.add_development_dependency 'bundler', '>= 1.7' 20 | end 21 | 22 | --------------------------------------------------------------------------------