thinreports-rails 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in thinreports-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
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.
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # ThinreportsRails
2
+ ThinReporsRails is constructed by Rails Template Handler [ThinReports](http://www.thinreports.org/ "ThinReposts") the PDF.
3
+
4
+ Oldname: thinreports-handler
5
+
6
+ ## Supported versions
7
+
8
+ * Ruby 1.8.7, 1.9.3
9
+ * Rails 3.0.X, 3.1.X, 3.2.X
10
+ * ThinReports 0.7.X
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'thinreports-rails'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install thinreports-rails
25
+
26
+ ## Usage
27
+
28
+ ### Example to, Display in the browser.
29
+
30
+ #### Controllers
31
+ ``` ruby
32
+ class OrdersController < ApplicationController
33
+ def index
34
+ @orders = Order.all
35
+ end
36
+ end
37
+ ```
38
+
39
+ #### Views
40
+
41
+ app/views/orders/index.pdf.thinreports
42
+
43
+ ``` ruby
44
+ report.set_layout # ! <= Required. default use: orders/index.tlf
45
+ report.start_new_page
46
+ report.page.values printed_at: Time.now
47
+ @orders.each do |order|
48
+ report.page.list(:list).add_row do |row|
49
+ row.item(:col1).value order.name
50
+ row.item(:col2).value order.num
51
+ end
52
+ end
53
+ ```
54
+
55
+ ### Example to, Download PDF.
56
+
57
+ ``` ruby
58
+ class OrdersController < ApplicationController
59
+ def index
60
+ @orders = Order.all
61
+ respond_to do |format|
62
+ format.pdf {
63
+ send_data render_to_string, filename: 'foo.pdf', type: 'application/pdf', disposition: 'attachment'
64
+ }
65
+ end
66
+ end
67
+ end
68
+ ```
69
+
70
+ ### Configuration
71
+
72
+ ### Layout file(.tlf) and options.
73
+
74
+ Example of using the `app/views/reports/index.tlf`.
75
+ Write code like this to `index.pdf.thinreports`.
76
+
77
+ `:layout_options` is an option `ThinReports::Report::Base#use_layout` method.
78
+
79
+ ``` ruby
80
+ report.set_layout tlf: 'reports/index', layout_options: { default: true }
81
+ ```
82
+
83
+ ### generate options.
84
+ ``` ruby
85
+ report.generate_options(security: {
86
+ user_password: 'foo',
87
+ owner_password: 'bar',
88
+ permissions: {
89
+ print_document: false,
90
+ modify_contents: false,
91
+ copy_contents: false
92
+ }
93
+ })
94
+ ```
95
+
96
+ ### Partial
97
+
98
+ For exsample to use, `app/views/orders/_header.pdf.thinreports`.
99
+ `title` is local variable in `_header.pdf.thinreports`.
100
+
101
+ ``` ruby
102
+ report.partial! 'header', title: title
103
+ ```
104
+
105
+ ## Authour
106
+
107
+ * TwitterID: @takeshinoda
108
+ * Blog: http://d.hatena.ne.jp/takeshinoda/
109
+
110
+ ## Contributing
111
+
112
+ m(__)m, send me pull request.
113
+
114
+ ## Copyright
115
+
116
+ Copyright (c) 2012 Takeshi Shinoda.
117
+
@@ -0,0 +1,3 @@
1
+ require "thinreports-rails/version"
2
+ require "thinreports-rails/railtie"
3
+
@@ -0,0 +1,13 @@
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
+
@@ -0,0 +1,73 @@
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.")
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)
54
+ %{
55
+ if defined?(report)
56
+ #{template.source}
57
+ else
58
+ generate_options = nil
59
+ ThinReports::Report.create do |__report__|
60
+ report = ThinreportsRails::ThinreportsTemplate.new(__report__, self, '#{template.virtual_path}')
61
+
62
+ #{template.source}
63
+
64
+ generate_options = report._generate_options
65
+ end.generate(*([generate_options].compact))
66
+ end
67
+ }
68
+ end
69
+ end
70
+ end
71
+
72
+ ActionView::Template.register_template_handler :thinreports, ThinreportsRails::TemplateHandler
73
+
@@ -0,0 +1,4 @@
1
+ module ThinreportsRails
2
+ VERSION = "0.1.2"
3
+ end
4
+
@@ -0,0 +1,2 @@
1
+ report.start_new_page
2
+ report.page.values :printed_at => Time.at(OrdersController::CURRENT) # 2012-06-27 11:41:33 +0900
@@ -0,0 +1,3 @@
1
+ report.start_new_page
2
+ report.page.values :printed_at => current_time
3
+
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
1
+ {"version":"0.7.0","finger-print":1367137149,"config":{"title":"Japanese Paper","option":{},"page":{"paper-type":"A4","orientation":"portrait","margin-top":"20","margin-bottom":"20","margin-left":"20","margin-right":"20"}},"svg":"<svg width=\"595.2\" height=\"841.8\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" preserveAspectRatio=\"none\" viewBox=\"0 0 595.2 841.8\"><g class=\"canvas\"><!--SHAPE{\"type\":\"s-tblock\",\"id\":\"printed_at\",\"display\":\"true\",\"desc\":null,\"multiple\":\"false\",\"valign\":\"\",\"line-height\":\"\",\"box\":{\"x\":339.1,\"y\":100,\"width\":236.1,\"height\":18},\"format\":{\"base\":\"\",\"type\":\"datetime\",\"datetime\":{\"format\":\"%Y/%m/%d %H:%M:%S\"}},\"value\":\"\",\"ref-id\":\"\",\"svg\":{\"tag\":\"text\",\"attrs\":{\"x\":339.1,\"y\":117,\"xml:space\":\"preserve\",\"kerning\":\"auto\",\"fill\":\"#000000\",\"fill-opacity\":\"1\",\"font-size\":\"18\",\"font-family\":\"Helvetica\",\"font-weight\":\"normal\",\"font-style\":\"normal\",\"text-anchor\":\"start\",\"text-decoration\":\"none\"}}}SHAPE--><!--LAYOUT<g class=\"s-tblock\" x-format-type=\"datetime\" x-value=\"\" x-format-base=\"\" x-ref-id=\"\" kerning=\"auto\" x-display=\"true\" x-multiple=\"false\" x-id=\"printed_at\" fill=\"#000000\" fill-opacity=\"1\" font-size=\"18\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"start\" text-decoration=\"none\" x-width=\"236.1\" x-height=\"18\" x-left=\"339.1\" x-top=\"100\" x-format-datetime-format=\"%Y/%m/%d %H:%M:%S\"><rect class=\"s-tblock-box\" stroke=\"#7C4007\" fill=\"#f4e2c4\" stroke-width=\"0.28\" fill-opacity=\"0.8\" width=\"236.1\" height=\"18\" x=\"339.1\" y=\"100\"></rect><text class=\"s-tblock-id\" font-size=\"11\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-decoration=\"none\" text-anchor=\"start\" kerning=\"auto\" stroke=\"none\" fill=\"#7C4007\" fill-opacity=\"1\" x=\"341.1\" y=\"111\">printed_at</text></g>LAYOUT--><g class=\"s-text\" stroke-width=\"0\" fill=\"#000000\" fill-opacity=\"1\" kerning=\"auto\" x-display=\"true\" x-id=\"\" font-size=\"48\" font-family=\"IPAPMincho\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"middle\" text-decoration=\"none\" x-width=\"263\" x-height=\"52\" x-left=\"166.1\" x-top=\"20\"><rect class=\"s-text-box\" stroke=\"none\" fill=\"#000000\" fill-opacity=\"0.001\" width=\"263\" height=\"52\" x=\"166.1\" y=\"20\"></rect><text class=\"s-text-l0\" xml:space=\"preserve\" stroke=\"none\" fill=\"inherit\" fill-opacity=\"1\" text-decoration=\"none\" x=\"297.6\" y=\"62\">\u30c6\u30b9\u30c8\u6ce8\u6587\u66f8</text></g><!--SHAPE{\"type\":\"s-list\",\"id\":\"list\",\"display\":\"true\",\"desc\":null,\"footer\":{\"height\":5.6,\"svg\":{\"tag\":\"g\",\"content\":\"\"},\"translate\":{\"x\":-47,\"y\":-42.999999999999986}},\"footer-enabled\":\"true\",\"page-footer\":{\"height\":5.6,\"svg\":{\"tag\":\"g\",\"content\":\"\"},\"translate\":{\"x\":-47,\"y\":-37.39999999999999}},\"page-footer-enabled\":\"true\",\"detail\":{\"height\":34.6,\"svg\":{\"tag\":\"g\",\"content\":\"<!---SHAPE{\\\"type\\\":\\\"s-tblock\\\",\\\"id\\\":\\\"col1\\\",\\\"display\\\":\\\"true\\\",\\\"desc\\\":null,\\\"multiple\\\":\\\"false\\\",\\\"valign\\\":\\\"\\\",\\\"line-height\\\":\\\"\\\",\\\"box\\\":{\\\"x\\\":67,\\\"y\\\":215.5,\\\"width\\\":274.1,\\\"height\\\":18},\\\"format\\\":{\\\"base\\\":\\\"\\\",\\\"type\\\":\\\"\\\"},\\\"value\\\":\\\"\\\",\\\"ref-id\\\":\\\"\\\",\\\"svg\\\":{\\\"tag\\\":\\\"text\\\",\\\"attrs\\\":{\\\"x\\\":67,\\\"y\\\":232.5,\\\"xml:space\\\":\\\"preserve\\\",\\\"kerning\\\":\\\"auto\\\",\\\"fill\\\":\\\"#000000\\\",\\\"fill-opacity\\\":\\\"1\\\",\\\"font-size\\\":\\\"18\\\",\\\"font-family\\\":\\\"Helvetica\\\",\\\"font-weight\\\":\\\"normal\\\",\\\"font-style\\\":\\\"normal\\\",\\\"text-anchor\\\":\\\"start\\\",\\\"text-decoration\\\":\\\"none\\\"}}}SHAPE---><!---SHAPE{\\\"type\\\":\\\"s-tblock\\\",\\\"id\\\":\\\"col2\\\",\\\"display\\\":\\\"true\\\",\\\"desc\\\":null,\\\"multiple\\\":\\\"false\\\",\\\"valign\\\":\\\"\\\",\\\"line-height\\\":\\\"\\\",\\\"box\\\":{\\\"x\\\":342.2,\\\"y\\\":215.5,\\\"width\\\":280,\\\"height\\\":18},\\\"format\\\":{\\\"base\\\":\\\"\\\",\\\"type\\\":\\\"\\\"},\\\"value\\\":\\\"\\\",\\\"ref-id\\\":\\\"\\\",\\\"svg\\\":{\\\"tag\\\":\\\"text\\\",\\\"attrs\\\":{\\\"x\\\":342.2,\\\"y\\\":232.5,\\\"xml:space\\\":\\\"preserve\\\",\\\"kerning\\\":\\\"auto\\\",\\\"fill\\\":\\\"#000000\\\",\\\"fill-opacity\\\":\\\"1\\\",\\\"font-size\\\":\\\"18\\\",\\\"font-family\\\":\\\"Helvetica\\\",\\\"font-weight\\\":\\\"normal\\\",\\\"font-style\\\":\\\"normal\\\",\\\"text-anchor\\\":\\\"start\\\",\\\"text-decoration\\\":\\\"none\\\"}}}SHAPE---><line stroke=\\\"#000000\\\" stroke-width=\\\"1\\\" fill=\\\"none\\\" class=\\\"s-line\\\" x-display=\\\"true\\\" x-stroke-type=\\\"solid\\\" stroke-dasharray=\\\"none\\\" x-id=\\\"\\\" x1=\\\"67\\\" x2=\\\"622.2\\\" y1=\\\"235\\\" y2=\\\"235\\\"></line><line stroke=\\\"#000000\\\" stroke-width=\\\"1\\\" fill=\\\"none\\\" class=\\\"s-line\\\" x-display=\\\"true\\\" x-stroke-type=\\\"solid\\\" stroke-dasharray=\\\"none\\\" x-id=\\\"\\\" x1=\\\"622.2\\\" x2=\\\"622.2\\\" y1=\\\"250.1\\\" y2=\\\"249.1\\\"></line>\"},\"translate\":{\"x\":-47,\"y\":-30}},\"header\":{\"height\":7.4,\"svg\":{\"tag\":\"g\",\"content\":\"\"},\"translate\":{\"x\":-47,\"y\":-30}},\"header-enabled\":\"true\",\"svg\":{\"tag\":\"g\",\"attrs\":{}},\"content-height\":503.70000000000005,\"page-break\":\"true\"}SHAPE--><!--LAYOUT<g class=\"s-list\" x-id=\"list\" x-header-enabled=\"true\" x-page-footer-enabled=\"true\" x-footer-enabled=\"true\" x-changing-page=\"true\" x-display=\"true\" width=\"555.2\" height=\"511.1\" x=\"20\" y=\"178.1\"><g class=\"s-list-header\" transform=\"translate(-47,-30) rotate(0 0 0)\" x-top=\"178.1\" x-height=\"7.4\"></g><g class=\"s-list-detail\" transform=\"translate(-47,-30) rotate(0 0 0)\" x-top=\"185.5\" x-height=\"34.6\"><g class=\"s-tblock\" x-format-type=\"\" x-value=\"\" x-format-base=\"\" x-ref-id=\"\" kerning=\"auto\" x-display=\"true\" x-multiple=\"false\" x-id=\"col1\" fill=\"#000000\" fill-opacity=\"1\" font-size=\"18\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"start\" text-decoration=\"none\" x-width=\"274.1\" x-height=\"18\" x-left=\"67\" x-top=\"215.5\"><rect class=\"s-tblock-box\" stroke=\"#7C4007\" fill=\"#f4e2c4\" stroke-width=\"0.28\" fill-opacity=\"0.8\" width=\"274.1\" height=\"18\" x=\"67\" y=\"215.5\"></rect><text class=\"s-tblock-id\" font-size=\"11\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-decoration=\"none\" text-anchor=\"start\" kerning=\"auto\" stroke=\"none\" fill=\"#7C4007\" fill-opacity=\"1\" x=\"69\" y=\"226.5\">col1</text></g><g class=\"s-tblock\" x-format-type=\"\" x-value=\"\" x-format-base=\"\" x-ref-id=\"\" kerning=\"auto\" x-display=\"true\" x-multiple=\"false\" x-id=\"col2\" fill=\"#000000\" fill-opacity=\"1\" font-size=\"18\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"start\" text-decoration=\"none\" x-width=\"280\" x-height=\"18\" x-left=\"342.2\" x-top=\"215.5\"><rect class=\"s-tblock-box\" stroke=\"#7C4007\" fill=\"#f4e2c4\" stroke-width=\"0.28\" fill-opacity=\"0.8\" width=\"280\" height=\"18\" x=\"342.2\" y=\"215.5\"></rect><text class=\"s-tblock-id\" font-size=\"11\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-decoration=\"none\" text-anchor=\"start\" kerning=\"auto\" stroke=\"none\" fill=\"#7C4007\" fill-opacity=\"1\" x=\"344.2\" y=\"226.5\">col2</text></g><line stroke=\"#000000\" stroke-width=\"1\" fill=\"none\" class=\"s-line\" x-display=\"true\" x-stroke-type=\"solid\" stroke-dasharray=\"none\" x-id=\"\" x1=\"67\" x2=\"622.2\" y1=\"235\" y2=\"235\"></line><line stroke=\"#000000\" stroke-width=\"1\" fill=\"none\" class=\"s-line\" x-display=\"true\" x-stroke-type=\"solid\" stroke-dasharray=\"none\" x-id=\"\" x1=\"622.2\" x2=\"622.2\" y1=\"250.1\" y2=\"249.1\"></line></g><g class=\"s-list-page-footer\" transform=\"translate(-47,-2.8) rotate(0 0 0)\" x-top=\"220.1\" x-height=\"5.6\"></g><g class=\"s-list-footer\" transform=\"translate(-47,-2.8) rotate(0 0 0)\" x-top=\"225.7\" x-height=\"5.6\"></g><text class=\"s-list-id\" font-size=\"11\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"start\" stroke=\"none\" fill=\"#7C4007\" fill-opacity=\"1\" x=\"22\" y=\"188.9\">list</text><rect stroke-dasharray=\"5\" stroke=\"#BBBBBB\" stroke-width=\"1\" fill=\"#FFFFFF\" fill-opacity=\"0\" class=\"s-list-face\" width=\"555.2\" height=\"511.1\" x=\"20\" y=\"178.1\"></rect></g>LAYOUT--><line stroke=\"#000000\" stroke-width=\"1\" fill=\"none\" class=\"s-line\" x-display=\"true\" x-stroke-type=\"solid\" stroke-dasharray=\"none\" x-id=\"\" x1=\"158.8\" x2=\"427.4\" y1=\"84\" y2=\"84\"></line></g></svg>"}
@@ -0,0 +1,2 @@
1
+ report.set_layout :tlf => 'orders/no_tlf'
2
+ report.partial! 'header'
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
1
+ {"version":"0.7.0","finger-print":1367137149,"config":{"title":"Japanese Paper","option":{},"page":{"paper-type":"A4","orientation":"portrait","margin-top":"20","margin-bottom":"20","margin-left":"20","margin-right":"20"}},"svg":"<svg width=\"595.2\" height=\"841.8\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" preserveAspectRatio=\"none\" viewBox=\"0 0 595.2 841.8\"><g class=\"canvas\"><!--SHAPE{\"type\":\"s-tblock\",\"id\":\"printed_at\",\"display\":\"true\",\"desc\":null,\"multiple\":\"false\",\"valign\":\"\",\"line-height\":\"\",\"box\":{\"x\":339.1,\"y\":100,\"width\":236.1,\"height\":18},\"format\":{\"base\":\"\",\"type\":\"datetime\",\"datetime\":{\"format\":\"%Y/%m/%d %H:%M:%S\"}},\"value\":\"\",\"ref-id\":\"\",\"svg\":{\"tag\":\"text\",\"attrs\":{\"x\":339.1,\"y\":117,\"xml:space\":\"preserve\",\"kerning\":\"auto\",\"fill\":\"#000000\",\"fill-opacity\":\"1\",\"font-size\":\"18\",\"font-family\":\"Helvetica\",\"font-weight\":\"normal\",\"font-style\":\"normal\",\"text-anchor\":\"start\",\"text-decoration\":\"none\"}}}SHAPE--><!--LAYOUT<g class=\"s-tblock\" x-format-type=\"datetime\" x-value=\"\" x-format-base=\"\" x-ref-id=\"\" kerning=\"auto\" x-display=\"true\" x-multiple=\"false\" x-id=\"printed_at\" fill=\"#000000\" fill-opacity=\"1\" font-size=\"18\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"start\" text-decoration=\"none\" x-width=\"236.1\" x-height=\"18\" x-left=\"339.1\" x-top=\"100\" x-format-datetime-format=\"%Y/%m/%d %H:%M:%S\"><rect class=\"s-tblock-box\" stroke=\"#7C4007\" fill=\"#f4e2c4\" stroke-width=\"0.28\" fill-opacity=\"0.8\" width=\"236.1\" height=\"18\" x=\"339.1\" y=\"100\"></rect><text class=\"s-tblock-id\" font-size=\"11\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-decoration=\"none\" text-anchor=\"start\" kerning=\"auto\" stroke=\"none\" fill=\"#7C4007\" fill-opacity=\"1\" x=\"341.1\" y=\"111\">printed_at</text></g>LAYOUT--><g class=\"s-text\" stroke-width=\"0\" fill=\"#000000\" fill-opacity=\"1\" kerning=\"auto\" x-display=\"true\" x-id=\"\" font-size=\"48\" font-family=\"IPAPMincho\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"middle\" text-decoration=\"none\" x-width=\"263\" x-height=\"52\" x-left=\"166.1\" x-top=\"20\"><rect class=\"s-text-box\" stroke=\"none\" fill=\"#000000\" fill-opacity=\"0.001\" width=\"263\" height=\"52\" x=\"166.1\" y=\"20\"></rect><text class=\"s-text-l0\" xml:space=\"preserve\" stroke=\"none\" fill=\"inherit\" fill-opacity=\"1\" text-decoration=\"none\" x=\"297.6\" y=\"62\">\u30c6\u30b9\u30c8\u6ce8\u6587\u66f8</text></g><!--SHAPE{\"type\":\"s-list\",\"id\":\"list\",\"display\":\"true\",\"desc\":null,\"footer\":{\"height\":5.6,\"svg\":{\"tag\":\"g\",\"content\":\"\"},\"translate\":{\"x\":-47,\"y\":-42.999999999999986}},\"footer-enabled\":\"true\",\"page-footer\":{\"height\":5.6,\"svg\":{\"tag\":\"g\",\"content\":\"\"},\"translate\":{\"x\":-47,\"y\":-37.39999999999999}},\"page-footer-enabled\":\"true\",\"detail\":{\"height\":34.6,\"svg\":{\"tag\":\"g\",\"content\":\"<!---SHAPE{\\\"type\\\":\\\"s-tblock\\\",\\\"id\\\":\\\"col1\\\",\\\"display\\\":\\\"true\\\",\\\"desc\\\":null,\\\"multiple\\\":\\\"false\\\",\\\"valign\\\":\\\"\\\",\\\"line-height\\\":\\\"\\\",\\\"box\\\":{\\\"x\\\":67,\\\"y\\\":215.5,\\\"width\\\":274.1,\\\"height\\\":18},\\\"format\\\":{\\\"base\\\":\\\"\\\",\\\"type\\\":\\\"\\\"},\\\"value\\\":\\\"\\\",\\\"ref-id\\\":\\\"\\\",\\\"svg\\\":{\\\"tag\\\":\\\"text\\\",\\\"attrs\\\":{\\\"x\\\":67,\\\"y\\\":232.5,\\\"xml:space\\\":\\\"preserve\\\",\\\"kerning\\\":\\\"auto\\\",\\\"fill\\\":\\\"#000000\\\",\\\"fill-opacity\\\":\\\"1\\\",\\\"font-size\\\":\\\"18\\\",\\\"font-family\\\":\\\"Helvetica\\\",\\\"font-weight\\\":\\\"normal\\\",\\\"font-style\\\":\\\"normal\\\",\\\"text-anchor\\\":\\\"start\\\",\\\"text-decoration\\\":\\\"none\\\"}}}SHAPE---><!---SHAPE{\\\"type\\\":\\\"s-tblock\\\",\\\"id\\\":\\\"col2\\\",\\\"display\\\":\\\"true\\\",\\\"desc\\\":null,\\\"multiple\\\":\\\"false\\\",\\\"valign\\\":\\\"\\\",\\\"line-height\\\":\\\"\\\",\\\"box\\\":{\\\"x\\\":342.2,\\\"y\\\":215.5,\\\"width\\\":280,\\\"height\\\":18},\\\"format\\\":{\\\"base\\\":\\\"\\\",\\\"type\\\":\\\"\\\"},\\\"value\\\":\\\"\\\",\\\"ref-id\\\":\\\"\\\",\\\"svg\\\":{\\\"tag\\\":\\\"text\\\",\\\"attrs\\\":{\\\"x\\\":342.2,\\\"y\\\":232.5,\\\"xml:space\\\":\\\"preserve\\\",\\\"kerning\\\":\\\"auto\\\",\\\"fill\\\":\\\"#000000\\\",\\\"fill-opacity\\\":\\\"1\\\",\\\"font-size\\\":\\\"18\\\",\\\"font-family\\\":\\\"Helvetica\\\",\\\"font-weight\\\":\\\"normal\\\",\\\"font-style\\\":\\\"normal\\\",\\\"text-anchor\\\":\\\"start\\\",\\\"text-decoration\\\":\\\"none\\\"}}}SHAPE---><line stroke=\\\"#000000\\\" stroke-width=\\\"1\\\" fill=\\\"none\\\" class=\\\"s-line\\\" x-display=\\\"true\\\" x-stroke-type=\\\"solid\\\" stroke-dasharray=\\\"none\\\" x-id=\\\"\\\" x1=\\\"67\\\" x2=\\\"622.2\\\" y1=\\\"235\\\" y2=\\\"235\\\"></line><line stroke=\\\"#000000\\\" stroke-width=\\\"1\\\" fill=\\\"none\\\" class=\\\"s-line\\\" x-display=\\\"true\\\" x-stroke-type=\\\"solid\\\" stroke-dasharray=\\\"none\\\" x-id=\\\"\\\" x1=\\\"622.2\\\" x2=\\\"622.2\\\" y1=\\\"250.1\\\" y2=\\\"249.1\\\"></line>\"},\"translate\":{\"x\":-47,\"y\":-30}},\"header\":{\"height\":7.4,\"svg\":{\"tag\":\"g\",\"content\":\"\"},\"translate\":{\"x\":-47,\"y\":-30}},\"header-enabled\":\"true\",\"svg\":{\"tag\":\"g\",\"attrs\":{}},\"content-height\":503.70000000000005,\"page-break\":\"true\"}SHAPE--><!--LAYOUT<g class=\"s-list\" x-id=\"list\" x-header-enabled=\"true\" x-page-footer-enabled=\"true\" x-footer-enabled=\"true\" x-changing-page=\"true\" x-display=\"true\" width=\"555.2\" height=\"511.1\" x=\"20\" y=\"178.1\"><g class=\"s-list-header\" transform=\"translate(-47,-30) rotate(0 0 0)\" x-top=\"178.1\" x-height=\"7.4\"></g><g class=\"s-list-detail\" transform=\"translate(-47,-30) rotate(0 0 0)\" x-top=\"185.5\" x-height=\"34.6\"><g class=\"s-tblock\" x-format-type=\"\" x-value=\"\" x-format-base=\"\" x-ref-id=\"\" kerning=\"auto\" x-display=\"true\" x-multiple=\"false\" x-id=\"col1\" fill=\"#000000\" fill-opacity=\"1\" font-size=\"18\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"start\" text-decoration=\"none\" x-width=\"274.1\" x-height=\"18\" x-left=\"67\" x-top=\"215.5\"><rect class=\"s-tblock-box\" stroke=\"#7C4007\" fill=\"#f4e2c4\" stroke-width=\"0.28\" fill-opacity=\"0.8\" width=\"274.1\" height=\"18\" x=\"67\" y=\"215.5\"></rect><text class=\"s-tblock-id\" font-size=\"11\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-decoration=\"none\" text-anchor=\"start\" kerning=\"auto\" stroke=\"none\" fill=\"#7C4007\" fill-opacity=\"1\" x=\"69\" y=\"226.5\">col1</text></g><g class=\"s-tblock\" x-format-type=\"\" x-value=\"\" x-format-base=\"\" x-ref-id=\"\" kerning=\"auto\" x-display=\"true\" x-multiple=\"false\" x-id=\"col2\" fill=\"#000000\" fill-opacity=\"1\" font-size=\"18\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"start\" text-decoration=\"none\" x-width=\"280\" x-height=\"18\" x-left=\"342.2\" x-top=\"215.5\"><rect class=\"s-tblock-box\" stroke=\"#7C4007\" fill=\"#f4e2c4\" stroke-width=\"0.28\" fill-opacity=\"0.8\" width=\"280\" height=\"18\" x=\"342.2\" y=\"215.5\"></rect><text class=\"s-tblock-id\" font-size=\"11\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-decoration=\"none\" text-anchor=\"start\" kerning=\"auto\" stroke=\"none\" fill=\"#7C4007\" fill-opacity=\"1\" x=\"344.2\" y=\"226.5\">col2</text></g><line stroke=\"#000000\" stroke-width=\"1\" fill=\"none\" class=\"s-line\" x-display=\"true\" x-stroke-type=\"solid\" stroke-dasharray=\"none\" x-id=\"\" x1=\"67\" x2=\"622.2\" y1=\"235\" y2=\"235\"></line><line stroke=\"#000000\" stroke-width=\"1\" fill=\"none\" class=\"s-line\" x-display=\"true\" x-stroke-type=\"solid\" stroke-dasharray=\"none\" x-id=\"\" x1=\"622.2\" x2=\"622.2\" y1=\"250.1\" y2=\"249.1\"></line></g><g class=\"s-list-page-footer\" transform=\"translate(-47,-2.8) rotate(0 0 0)\" x-top=\"220.1\" x-height=\"5.6\"></g><g class=\"s-list-footer\" transform=\"translate(-47,-2.8) rotate(0 0 0)\" x-top=\"225.7\" x-height=\"5.6\"></g><text class=\"s-list-id\" font-size=\"11\" font-family=\"Helvetica\" font-weight=\"normal\" font-style=\"normal\" text-anchor=\"start\" stroke=\"none\" fill=\"#7C4007\" fill-opacity=\"1\" x=\"22\" y=\"188.9\">list</text><rect stroke-dasharray=\"5\" stroke=\"#BBBBBB\" stroke-width=\"1\" fill=\"#FFFFFF\" fill-opacity=\"0\" class=\"s-list-face\" width=\"555.2\" height=\"511.1\" x=\"20\" y=\"178.1\"></rect></g>LAYOUT--><line stroke=\"#000000\" stroke-width=\"1\" fill=\"none\" class=\"s-line\" x-display=\"true\" x-stroke-type=\"solid\" stroke-dasharray=\"none\" x-id=\"\" x1=\"158.8\" x2=\"427.4\" y1=\"84\" y2=\"84\"></line></g></svg>"}
@@ -0,0 +1,51 @@
1
+ require 'action_controller/railtie'
2
+ require 'action_view/railtie'
3
+
4
+ module ThinreportsRailsTestApp
5
+ class Application < Rails::Application
6
+ config.active_support.deprecation = :log
7
+ config.root = File.dirname(__FILE__)
8
+ end
9
+ end
10
+ ThinreportsRailsTestApp::Application.initialize!
11
+
12
+
13
+ # Route
14
+ ThinreportsRailsTestApp::Application.routes.draw do
15
+ resources :orders, :only => [:index] do
16
+ collection do
17
+ get 'no_tlf'
18
+ get 'other_tlf_path'
19
+ end
20
+ end
21
+ end
22
+
23
+
24
+ # Model
25
+ class Order
26
+ attr_accessor :name, :num
27
+
28
+ def initialize(name, num)
29
+ self.name = name
30
+ self.num = num
31
+ end
32
+ end
33
+
34
+
35
+ # Controller
36
+ class ApplicationController < ActionController::Base; end
37
+
38
+ class OrdersController < ApplicationController
39
+ CURRENT = 1340764893 # 2012-06-27 11:41:33 +0900
40
+
41
+ def index
42
+ @orders = [Order.new('order1', 2),
43
+ Order.new('order2', 10)]
44
+ respond_to do |f|
45
+ f.pdf { render }
46
+ end
47
+ end
48
+ alias no_tlf index
49
+ alias other_tlf_path index
50
+ end
51
+
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rubygems'
4
+
5
+ require 'test/unit'
6
+
7
+ require 'thinreports-rails'
8
+ require 'test_app/test_app'
9
+
10
+ require 'rails'
11
+ require 'rails/test_help'
12
+
13
+ class ThinReportsRailsTest < ActionController::TestCase
14
+ tests OrdersController
15
+
16
+ test 'index.tlf is selected.' do
17
+ get :index, :format => :pdf
18
+ assert_response :success
19
+ end
20
+
21
+ test 'other tlf can select.' do
22
+ get :other_tlf_path, :format => :pdf
23
+ assert_response :success
24
+ end
25
+
26
+ test 'tlf can not choose not. raise Exception.' do
27
+ assert_raise(ActionView::Template::Error) { get :no_tlf, :format => :pdf }
28
+ end
29
+ end
30
+
@@ -0,0 +1,18 @@
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.}
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
+ gem.add_dependency "thinreports", '~>0.7.0'
18
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thinreports-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Takeshi Shinoda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thinreports
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.0
30
+ description: Rails plugin for Thinreports DSL.
31
+ email:
32
+ - takeshinoda@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - lib/thinreports-rails.rb
42
+ - lib/thinreports-rails/railtie.rb
43
+ - lib/thinreports-rails/template_handler.rb
44
+ - lib/thinreports-rails/version.rb
45
+ - test/test_app/app/views/orders/_header.pdf.thinreports
46
+ - test/test_app/app/views/orders/_other_header.pdf.thinreports
47
+ - test/test_app/app/views/orders/index.pdf.thinreports
48
+ - test/test_app/app/views/orders/index.tlf
49
+ - test/test_app/app/views/orders/no_tlf.pdf.thinreports
50
+ - test/test_app/app/views/orders/other_tlf_path.pdf.thinreports
51
+ - test/test_app/app/views/reports/other.tlf
52
+ - test/test_app/test_app.rb
53
+ - test/thinreports-rails_test.rb
54
+ - thinreports-rails.gemspec
55
+ homepage: https://github.com/takeshinoda/thinreports-rails
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.24
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Rails plugin for Thinreports DSL.
79
+ test_files:
80
+ - test/test_app/app/views/orders/_header.pdf.thinreports
81
+ - test/test_app/app/views/orders/_other_header.pdf.thinreports
82
+ - test/test_app/app/views/orders/index.pdf.thinreports
83
+ - test/test_app/app/views/orders/index.tlf
84
+ - test/test_app/app/views/orders/no_tlf.pdf.thinreports
85
+ - test/test_app/app/views/orders/other_tlf_path.pdf.thinreports
86
+ - test/test_app/app/views/reports/other.tlf
87
+ - test/test_app/test_app.rb
88
+ - test/thinreports-rails_test.rb