thinreports 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -6
  3. data/.travis.yml +4 -10
  4. data/CHANGELOG.md +220 -0
  5. data/Gemfile +3 -3
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +286 -0
  8. data/Rakefile +38 -8
  9. data/examples/character_spacing/character_spacing.rb +8 -0
  10. data/examples/character_spacing/character_spacing.tlf +1 -0
  11. data/examples/dynamic_image/dynamic_image.rb +31 -0
  12. data/examples/dynamic_image/dynamic_image.tlf +1 -0
  13. data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
  14. data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
  15. data/examples/dynamic_style/dynamic_style.rb +150 -0
  16. data/examples/dynamic_style/dynamic_style.tlf +1 -0
  17. data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
  18. data/{test/case → examples}/dynamic_style/image.png +0 -0
  19. data/examples/eudc/eudc.rb +20 -0
  20. data/examples/eudc/eudc.tlf +1 -0
  21. data/{test/case → examples}/eudc/eudc.ttf +0 -0
  22. data/{test/case → examples}/helper.rb +14 -12
  23. data/examples/hidden_shapes/hidden_shapes.rb +9 -0
  24. data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
  25. data/examples/list_events/list_events.rb +59 -0
  26. data/examples/list_events/list_events_0_7_7.tlf +1 -0
  27. data/examples/list_events/list_events_0_8.tlf +1 -0
  28. data/{test/case → examples}/list_manual_generation/list_manual_generation.rb +4 -4
  29. data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
  30. data/{test/case → examples}/list_page_number/list_page_number.rb +3 -3
  31. data/examples/list_page_number/list_page_number.tlf +1 -0
  32. data/examples/page_number/page_number.rb +33 -0
  33. data/examples/page_number/page_number.tlf +1 -0
  34. data/examples/password_setting/password_setting.rb +10 -0
  35. data/examples/password_setting/password_setting.tlf +1 -0
  36. data/examples/report_callbacks/report_callbacks.rb +31 -0
  37. data/examples/report_callbacks/report_callbacks.tlf +1 -0
  38. data/{test/case → examples}/single_line_tblock/single_line_tblock.rb +2 -2
  39. data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
  40. data/examples/tblock_overflow/tblock_overflow.rb +20 -0
  41. data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
  42. data/examples/tblock_styles/font_size.tlf +1 -0
  43. data/examples/tblock_styles/tblock_styles.rb +43 -0
  44. data/examples/tblock_styles/tblock_styles.tlf +1 -0
  45. data/examples/text_align/text_align.rb +8 -0
  46. data/examples/text_align/text_align.tlf +1 -0
  47. data/examples/typeB_page_size/B4_ISO.tlf +1 -0
  48. data/examples/typeB_page_size/B4_JIS.tlf +1 -0
  49. data/{test/case → examples}/typeB_page_size/typeB_page_size.rb +3 -3
  50. data/examples/word_wrap/word_wrap.rb +26 -0
  51. data/examples/word_wrap/word_wrap.tlf +1 -0
  52. data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
  53. data/{resources/fonts → fonts}/ipag.ttf +0 -0
  54. data/{resources/fonts → fonts}/ipagp.ttf +0 -0
  55. data/{resources/fonts → fonts}/ipam.ttf +0 -0
  56. data/{resources/fonts → fonts}/ipamp.ttf +0 -0
  57. data/lib/thinreports.rb +14 -2
  58. data/lib/thinreports/config.rb +30 -10
  59. data/lib/thinreports/core/errors.rb +23 -20
  60. data/lib/thinreports/core/events.rb +18 -19
  61. data/lib/thinreports/core/format/base.rb +20 -20
  62. data/lib/thinreports/core/format/builder.rb +14 -22
  63. data/lib/thinreports/core/shape.rb +9 -13
  64. data/lib/thinreports/core/shape/base.rb +4 -5
  65. data/lib/thinreports/core/shape/base/interface.rb +15 -15
  66. data/lib/thinreports/core/shape/base/internal.rb +15 -20
  67. data/lib/thinreports/core/shape/basic.rb +1 -1
  68. data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
  69. data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
  70. data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
  71. data/lib/thinreports/core/shape/basic/format.rb +11 -10
  72. data/lib/thinreports/core/shape/basic/interface.rb +3 -3
  73. data/lib/thinreports/core/shape/basic/internal.rb +4 -5
  74. data/lib/thinreports/core/shape/image_block.rb +1 -1
  75. data/lib/thinreports/core/shape/image_block/format.rb +5 -6
  76. data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
  77. data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
  78. data/lib/thinreports/core/shape/list.rb +1 -1
  79. data/lib/thinreports/core/shape/list/configuration.rb +30 -15
  80. data/lib/thinreports/core/shape/list/events.rb +11 -11
  81. data/lib/thinreports/core/shape/list/format.rb +27 -28
  82. data/lib/thinreports/core/shape/list/manager.rb +128 -95
  83. data/lib/thinreports/core/shape/list/page.rb +54 -50
  84. data/lib/thinreports/core/shape/list/page_state.rb +15 -16
  85. data/lib/thinreports/core/shape/list/section_format.rb +14 -15
  86. data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
  87. data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
  88. data/lib/thinreports/core/shape/list/store.rb +10 -11
  89. data/lib/thinreports/core/shape/manager.rb +1 -1
  90. data/lib/thinreports/core/shape/manager/format.rb +10 -11
  91. data/lib/thinreports/core/shape/manager/internal.rb +21 -20
  92. data/lib/thinreports/core/shape/manager/target.rb +63 -34
  93. data/lib/thinreports/core/shape/page_number.rb +1 -1
  94. data/lib/thinreports/core/shape/page_number/format.rb +3 -3
  95. data/lib/thinreports/core/shape/page_number/interface.rb +2 -2
  96. data/lib/thinreports/core/shape/page_number/internal.rb +3 -3
  97. data/lib/thinreports/core/shape/style.rb +1 -1
  98. data/lib/thinreports/core/shape/style/base.rb +29 -29
  99. data/lib/thinreports/core/shape/style/basic.rb +1 -1
  100. data/lib/thinreports/core/shape/style/graphic.rb +10 -25
  101. data/lib/thinreports/core/shape/style/text.rb +36 -30
  102. data/lib/thinreports/core/shape/text.rb +1 -1
  103. data/lib/thinreports/core/shape/text/format.rb +8 -9
  104. data/lib/thinreports/core/shape/text/interface.rb +2 -2
  105. data/lib/thinreports/core/shape/text/internal.rb +6 -7
  106. data/lib/thinreports/core/shape/text_block.rb +1 -1
  107. data/lib/thinreports/core/shape/text_block/format.rb +17 -18
  108. data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
  109. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
  110. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
  111. data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
  112. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
  113. data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
  114. data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
  115. data/lib/thinreports/core/utils.rb +33 -32
  116. data/lib/thinreports/generator.rb +6 -8
  117. data/lib/thinreports/generator/base.rb +15 -24
  118. data/lib/thinreports/generator/configuration.rb +10 -9
  119. data/lib/thinreports/generator/pdf.rb +27 -30
  120. data/lib/thinreports/generator/pdf/configuration.rb +11 -6
  121. data/lib/thinreports/generator/pdf/document.rb +28 -28
  122. data/lib/thinreports/generator/pdf/document/draw_shape.rb +30 -31
  123. data/lib/thinreports/generator/pdf/document/font.rb +53 -44
  124. data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
  125. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +25 -25
  126. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
  127. data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
  128. data/lib/thinreports/generator/pdf/document/graphics/text.rb +40 -41
  129. data/lib/thinreports/generator/pdf/document/page.rb +20 -21
  130. data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
  131. data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
  132. data/lib/thinreports/generator/pdf/drawer/base.rb +13 -14
  133. data/lib/thinreports/generator/pdf/drawer/list.rb +13 -14
  134. data/lib/thinreports/generator/pdf/drawer/list_section.rb +13 -14
  135. data/lib/thinreports/generator/pdf/drawer/page.rb +16 -17
  136. data/lib/thinreports/generator/pdf/prawn_ext.rb +17 -33
  137. data/lib/thinreports/layout.rb +2 -2
  138. data/lib/thinreports/layout/base.rb +22 -36
  139. data/lib/thinreports/layout/configuration.rb +11 -9
  140. data/lib/thinreports/layout/format.rb +26 -27
  141. data/lib/thinreports/layout/version.rb +8 -9
  142. data/lib/thinreports/report.rb +10 -14
  143. data/lib/thinreports/report/base.rb +104 -126
  144. data/lib/thinreports/report/events.rb +5 -5
  145. data/lib/thinreports/report/internal.rb +41 -33
  146. data/lib/thinreports/{core → report}/page.rb +38 -30
  147. data/lib/thinreports/version.rb +2 -3
  148. data/test/data/font.ttf +0 -0
  149. data/test/data/layout_block.tlf +1 -0
  150. data/test/data/layout_list.tlf +1 -0
  151. data/test/data/layout_list_noheader.tlf +1 -0
  152. data/test/data/layout_text1.tlf +1 -0
  153. data/test/data/layout_text2.tlf +1 -0
  154. data/test/test_helper.rb +74 -0
  155. data/test/{unit/tmp → tmp}/.gitkeep +0 -0
  156. data/test/unit/core/format/test_base.rb +14 -14
  157. data/test/unit/core/format/test_builder.rb +19 -23
  158. data/test/unit/core/shape/base/test_internal.rb +34 -37
  159. data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
  160. data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
  161. data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
  162. data/test/unit/core/shape/basic/test_format.rb +4 -4
  163. data/test/unit/core/shape/basic/test_interface.rb +36 -46
  164. data/test/unit/core/shape/basic/test_internal.rb +23 -20
  165. data/test/unit/core/shape/image_block/test_format.rb +5 -5
  166. data/test/unit/core/shape/image_block/test_interface.rb +17 -16
  167. data/test/unit/core/shape/image_block/test_internal.rb +19 -16
  168. data/test/unit/core/shape/list/test_configuration.rb +45 -33
  169. data/test/unit/core/shape/list/test_events.rb +7 -7
  170. data/test/unit/core/shape/list/test_format.rb +16 -18
  171. data/test/unit/core/shape/list/test_manager.rb +5 -5
  172. data/test/unit/core/shape/list/test_page.rb +80 -22
  173. data/test/unit/core/shape/list/test_page_state.rb +12 -12
  174. data/test/unit/core/shape/list/test_section_format.rb +16 -17
  175. data/test/unit/core/shape/list/test_section_interface.rb +30 -22
  176. data/test/unit/core/shape/list/test_section_internal.rb +21 -19
  177. data/test/unit/core/shape/list/test_store.rb +7 -7
  178. data/test/unit/core/shape/manager/test_format.rb +11 -15
  179. data/test/unit/core/shape/manager/test_internal.rb +9 -9
  180. data/test/unit/core/shape/manager/test_target.rb +85 -57
  181. data/test/unit/core/shape/page_number/test_format.rb +4 -4
  182. data/test/unit/core/shape/page_number/test_interface.rb +11 -8
  183. data/test/unit/core/shape/page_number/test_internal.rb +5 -5
  184. data/test/unit/core/shape/styles/test_base.rb +9 -9
  185. data/test/unit/core/shape/styles/test_basic.rb +5 -5
  186. data/test/unit/core/shape/styles/test_graphic.rb +19 -33
  187. data/test/unit/core/shape/styles/test_text.rb +18 -7
  188. data/test/unit/core/shape/text/test_format.rb +6 -6
  189. data/test/unit/core/shape/text/test_internal.rb +11 -12
  190. data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
  191. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +4 -4
  192. data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
  193. data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
  194. data/test/unit/core/shape/text_block/test_format.rb +8 -8
  195. data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
  196. data/test/unit/core/shape/text_block/test_interface.rb +37 -20
  197. data/test/unit/core/shape/text_block/test_internal.rb +38 -38
  198. data/test/unit/core/test_events.rb +5 -5
  199. data/test/unit/core/test_shape.rb +6 -6
  200. data/test/unit/core/test_utils.rb +68 -0
  201. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +4 -4
  202. data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
  203. data/test/unit/generator/pdf/document/test_draw_shape.rb +9 -7
  204. data/test/unit/generator/pdf/document/test_font.rb +79 -58
  205. data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
  206. data/test/unit/generator/pdf/document/test_page.rb +44 -45
  207. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  208. data/test/unit/generator/pdf/test_configuration.rb +16 -9
  209. data/test/unit/generator/pdf/test_document.rb +8 -16
  210. data/test/unit/generator/test_base.rb +31 -42
  211. data/test/unit/generator/test_configuration.rb +6 -6
  212. data/test/unit/generator/test_pdf.rb +17 -14
  213. data/test/unit/layout/test_base.rb +34 -79
  214. data/test/unit/layout/test_configuration.rb +12 -37
  215. data/test/unit/layout/test_format.rb +36 -39
  216. data/test/unit/layout/test_version.rb +4 -4
  217. data/test/unit/report/test_base.rb +134 -213
  218. data/test/unit/report/test_events.rb +4 -4
  219. data/test/unit/report/test_internal.rb +84 -86
  220. data/test/unit/test_config.rb +31 -12
  221. data/test/unit/test_layout.rb +7 -7
  222. data/test/unit/test_report.rb +12 -24
  223. data/thinreports.gemspec +18 -22
  224. metadata +101 -200
  225. data/LICENSE +0 -1
  226. data/README.rdoc +0 -166
  227. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  228. data/lib/thinreports/core.rb +0 -20
  229. data/lib/thinreports/core/ext.rb +0 -5
  230. data/lib/thinreports/core/ext/array.rb +0 -19
  231. data/lib/thinreports/core/ext/hash.rb +0 -19
  232. data/lib/thinreports/core/ext/object.rb +0 -25
  233. data/lib/thinreports/core/format.rb +0 -14
  234. data/lib/thinreports/core/ordered_hash.rb +0 -39
  235. data/lib/thinreports/generator/pdf/drawer.rb +0 -16
  236. data/tasks/doc.rake +0 -12
  237. data/tasks/test.rake +0 -56
  238. data/test/benchmark/basic_estimate.tlf +0 -1
  239. data/test/benchmark/bench_basic_estimate.rb +0 -95
  240. data/test/case/character_spacing/character_spacing.rb +0 -8
  241. data/test/case/character_spacing/character_spacing.tlf +0 -1
  242. data/test/case/dynamic_image/dynamic_image.rb +0 -41
  243. data/test/case/dynamic_image/dynamic_image.tlf +0 -1
  244. data/test/case/dynamic_style/dynamic_style.rb +0 -154
  245. data/test/case/dynamic_style/dynamic_style.tlf +0 -1
  246. data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
  247. data/test/case/eudc/eudc.rb +0 -20
  248. data/test/case/eudc/eudc.tlf +0 -1
  249. data/test/case/hidden_shapes/hidden_shapes.rb +0 -9
  250. data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
  251. data/test/case/list_events/list_events.rb +0 -32
  252. data/test/case/list_events/list_events.tlf +0 -1
  253. data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
  254. data/test/case/list_page_number/list_page_number.tlf +0 -1
  255. data/test/case/page_number/page_number.rb +0 -33
  256. data/test/case/page_number/page_number.tlf +0 -1
  257. data/test/case/password_setting/password_setting.rb +0 -10
  258. data/test/case/password_setting/password_setting.tlf +0 -1
  259. data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
  260. data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
  261. data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
  262. data/test/case/tblock_styles/tblock_styles.rb +0 -27
  263. data/test/case/tblock_styles/tblock_styles.tlf +0 -1
  264. data/test/case/text_align/text_align.rb +0 -8
  265. data/test/case/text_align/text_align.tlf +0 -1
  266. data/test/case/typeB_page_size/B4_ISO.tlf +0 -1
  267. data/test/case/typeB_page_size/B4_JIS.tlf +0 -1
  268. data/test/case/word_wrap/word_wrap.rb +0 -26
  269. data/test/case/word_wrap/word_wrap.tlf +0 -1
  270. data/test/unit/core/ext/array_spec.rb +0 -29
  271. data/test/unit/core/ext/hash_spec.rb +0 -29
  272. data/test/unit/core/ext/object_spec.rb +0 -30
  273. data/test/unit/core/ordered_hash_spec.rb +0 -51
  274. data/test/unit/core/shape/base/test_interface.rb +0 -52
  275. data/test/unit/core/utils_spec.rb +0 -56
  276. data/test/unit/data/basic_layout1.tlf +0 -1
  277. data/test/unit/data/basic_layout2.tlf +0 -1
  278. data/test/unit/data/basic_list_layout.tlf +0 -1
  279. data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
  280. data/test/unit/helper.rb +0 -87
@@ -1,27 +1,29 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Layout
5
-
5
+
6
+ # @deprecated This class will be removed in the next major version.
6
7
  class Configuration
7
8
  include Core::Shape::Manager::Target
8
-
9
- undef_method :items, :values
10
-
11
- # @param [ThinReports::Layout::Base] layout
9
+
10
+ # @param [Thinreports::Layout::Base] layout
12
11
  def initialize(layout)
13
12
  initialize_manager(layout.format) do |f|
14
13
  Core::Shape::Configuration(f.type).new
15
14
  end
16
15
  end
17
-
16
+
18
17
  # @param [String, Symbol] shape_id
19
18
  # @return [Object, nil]
20
- # @private
21
19
  def activate(shape_id)
22
20
  (config = manager.shapes[shape_id.to_sym]) && config.copy
23
21
  end
22
+
23
+ def values
24
+ raise NoMethodError
25
+ end
24
26
  end
25
-
27
+
26
28
  end
27
29
  end
@@ -2,40 +2,39 @@
2
2
 
3
3
  require 'digest/sha1'
4
4
 
5
- module ThinReports
5
+ module Thinreports
6
6
  module Layout
7
-
8
- # @private
7
+
9
8
  class Format < Core::Shape::Manager::Format
10
- config_reader :last_version => %w( version )
11
- config_reader :report_title => %w( config title )
12
- config_reader :page_paper_type => %w( config page paper-type ),
13
- :page_width => %w( config page width ),
14
- :page_height => %w( config page height ),
15
- :page_orientation => %w( config page orientation )
16
-
17
- config_checker 'user', :user_paper_type => %w( config page paper-type )
18
-
9
+ config_reader last_version: %w( version )
10
+ config_reader report_title: %w( config title )
11
+ config_reader page_paper_type: %w( config page paper-type ),
12
+ page_width: %w( config page width ),
13
+ page_height: %w( config page height ),
14
+ page_orientation: %w( config page orientation )
15
+
16
+ config_checker 'user', user_paper_type: %w( config page paper-type )
17
+
19
18
  class << self
20
-
19
+
21
20
  private
22
-
21
+
23
22
  # @param [String] filename
24
23
  # @param [Hash] options
25
24
  # @option options [Boolean] :force (false)
26
25
  def build_internal(filename, options = {})
27
26
  build_once(filename, options[:force]) do |content, id|
28
27
  raw_format = parse_json(content)
29
-
28
+
30
29
  # Check the compatibility of specified layout file.
31
- unless ThinReports::Layout::Version.compatible?(raw_format['version'])
30
+ unless Thinreports::Layout::Version.compatible?(raw_format['version'])
32
31
  info = [filename, raw_format['version'],
33
- ThinReports::Layout::Version.inspect_required_rules]
34
- raise ThinReports::Errors::IncompatibleLayoutFormat.new(*info)
32
+ Thinreports::Layout::Version.inspect_required_rules]
33
+ raise Thinreports::Errors::IncompatibleLayoutFormat.new(*info)
35
34
  end
36
-
35
+
37
36
  compact_format!(raw_format)
38
-
37
+
39
38
  # Build and initialize format.
40
39
  new(raw_format, id) do |f|
41
40
  build_layout(f) do |type, shape_format|
@@ -45,17 +44,17 @@ module ThinReports
45
44
  end
46
45
  end
47
46
  end
48
-
47
+
49
48
  # @param [Hash] raw_format A parsed json.
50
49
  def compact_format!(raw_format)
51
50
  %w( finger-print state version ).each {|attr| raw_format.delete(attr) }
52
51
  end
53
-
52
+
54
53
  # @param [String] filename
55
54
  # @param [Boolean] force (false)
56
55
  def build_once(filename, force = false, &block)
57
56
  content = read_format_file(filename)
58
-
57
+
59
58
  if force
60
59
  block.call(content, nil)
61
60
  else
@@ -63,19 +62,19 @@ module ThinReports
63
62
  built_format_registry[id] ||= block.call(content, id)
64
63
  end
65
64
  end
66
-
65
+
67
66
  # @param [String] filename
68
67
  # @return [String]
69
68
  def read_format_file(filename)
70
69
  File.open(filename, 'r:UTF-8') {|f| f.read }
71
70
  end
72
-
71
+
73
72
  # @return [Hash]
74
73
  def built_format_registry
75
74
  @built_format_registry ||= {}
76
- end
75
+ end
77
76
  end
78
77
  end
79
-
78
+
80
79
  end
81
80
  end
@@ -1,18 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Layout
5
-
6
- # @private
5
+
7
6
  module Version
8
- REQUIRED_RULES = ['>= 0.6.0.pre3', '< 0.8.0']
9
-
7
+ REQUIRED_RULES = ['>= 0.7.7.0', '< 1.0.0']
8
+
10
9
  # @param [String] version
11
10
  # @return [Boolean]
12
11
  def self.compatible?(version)
13
12
  compare(version, *REQUIRED_RULES)
14
13
  end
15
-
14
+
16
15
  # @param [String] base
17
16
  # @param [Array<String>] rules
18
17
  # @return [Boolean]
@@ -22,12 +21,12 @@ module ThinReports
22
21
  comparable_version(base).send(op.to_sym, comparable_version(ver))
23
22
  end
24
23
  end
25
-
24
+
26
25
  # @return [String]
27
26
  def self.inspect_required_rules
28
27
  '(' + REQUIRED_RULES.join(' and ') + ')'
29
28
  end
30
-
29
+
31
30
  # @param [String] version
32
31
  # @return [String]
33
32
  def self.comparable_version(version)
@@ -38,6 +37,6 @@ module ThinReports
38
37
  end
39
38
  end
40
39
  end
41
-
40
+
42
41
  end
43
42
  end
@@ -1,31 +1,27 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
4
-
3
+ module Thinreports
4
+
5
5
  module Report
6
- # @see ThinReports::Report::Base#initialize
6
+ # @see Thinreports::Report::Base#initialize
7
7
  def self.new(*args)
8
8
  Base.new(*args)
9
9
  end
10
-
11
- # @see ThinReports::Report::Base#create
10
+
11
+ # @see Thinreports::Report::Base#create
12
12
  def self.create(*args, &block)
13
13
  Base.create(*args, &block)
14
14
  end
15
-
16
- # @see ThinReports::Report::Base#generate
15
+
16
+ # @see Thinreports::Report::Base#generate
17
17
  def self.generate(*args, &block)
18
18
  Base.generate(*args, &block)
19
19
  end
20
-
21
- # @see ThinReports::Report::Base#generate_file
22
- def self.generate_file(*args, &block)
23
- Base.generate_file(*args, &block)
24
- end
25
20
  end
26
-
21
+
27
22
  end
28
23
 
29
24
  require 'thinreports/report/base'
30
25
  require 'thinreports/report/internal'
31
- require 'thinreports/report/events'
26
+ require 'thinreports/report/events'
27
+ require 'thinreports/report/page'
@@ -1,33 +1,29 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Report
5
-
5
+
6
6
  class Base
7
- # @return [ThinReports::Report::Internal]
8
- # @private
9
- attr_reader :internal
7
+ extend Forwardable
8
+ include Utils
10
9
 
11
- # @return [Integer]
12
- attr_reader :start_page_number
13
-
14
10
  class << self
15
11
  # @param options (see #initialize)
16
12
  # @option options (see #initialize)
17
13
  # @yield [report]
18
- # @yieldparam [ThinReports::Report::Base] report
19
- # @return [ThinReports::Report::Base]
14
+ # @yieldparam [Thinreports::Report::Base] report
15
+ # @return [Thinreports::Report::Base]
20
16
  def create(options = {}, &block)
21
17
  unless block_given?
22
18
  raise ArgumentError, '#create requires a block'
23
19
  end
24
20
  report = new(options)
25
- block_exec_on(report, &block)
21
+ call_block_in(report, &block)
26
22
  report.finalize
27
-
23
+
28
24
  report
29
25
  end
30
-
26
+
31
27
  # @overload generate(type, options = {}, &block)
32
28
  # @param [Symbol] type
33
29
  # @param [Hash] options
@@ -42,41 +38,22 @@ module ThinReports
42
38
  # @return [String]
43
39
  def generate(*args, &block)
44
40
  raise ArgumentError, '#generate requires a block' unless block_given?
45
-
41
+
46
42
  report_opts, generator_opts = extract_options!(args)
47
-
43
+
48
44
  report = create(report_opts, &block)
49
45
  report.generate(*args.push(generator_opts))
50
46
  end
51
-
52
- # @overload generate_file(type, filename, options = {}, &block)
53
- # @overload generate_file(filename, options = {}, &block)
54
- # @param filename (see #generate_file)
55
- # @yield (see .create)
56
- # @yieldparam (see .create)
57
- # @see .generate
58
- # @deprecated Please use the #generate method with :filename option instead.
59
- # @return [void]
60
- def generate_file(*args, &block)
61
- raise ArgumentError, '#generate_file requires a block' unless block_given?
62
47
 
63
- report_opts, generator_opts = extract_options!(args)
64
-
65
- report = create(report_opts, &block)
66
- report.generate_file(*args.push(generator_opts))
67
- end
68
-
69
- private
70
-
71
48
  # @param [Array] args
72
49
  # @return [Array<Hash>]
73
50
  def extract_options!(args)
74
51
  if args.last.is_a?(::Hash)
75
52
  options = args.pop
76
-
53
+
77
54
  generator = options.delete(:generator) || {}
78
55
  report = options.delete(:report) || {}
79
-
56
+
80
57
  if options.key?(:layout)
81
58
  report[:layout] = options.delete(:layout)
82
59
  end
@@ -86,150 +63,151 @@ module ThinReports
86
63
  end
87
64
  end
88
65
  end
89
-
66
+
67
+ # @return [Thinreports::Report::Internal]
68
+ attr_reader :internal
69
+
70
+ # @return [Integer]
71
+ attr_reader :start_page_number
72
+
73
+ # @return [Thinreports::Report::Page]
74
+ def_delegator :internal, :page
75
+
76
+ # @return [Integer]
77
+ def_delegator :internal, :page_count
78
+
79
+ # @return [Array<Thinreports::Report::Page>]
80
+ def_delegator :internal, :pages
81
+
82
+ # @return [Thinreports::Layout::Base]
83
+ def_delegator :internal, :default_layout
84
+
90
85
  # @param [Hash] options
91
86
  # @option options [String, nil] :layout (nil)
92
87
  def initialize(options = {})
93
88
  @internal = Report::Internal.new(self, options)
94
89
  @start_page_number = 1
90
+
91
+ @page_create_handler = nil
92
+ @generate_handler = nil
93
+ end
94
+
95
+ # @yield [page]
96
+ # @yieldparam [Thinreports::Report::Page] page
97
+ # @example
98
+ # report.on_page_create do |page|
99
+ # page.item(:header_title).value = 'Title'
100
+ # end
101
+ def on_page_create(&block)
102
+ internal.page_create_handler = block
95
103
  end
96
104
 
97
105
  # @param [Integer] page_number
98
106
  def start_page_number_from(page_number)
99
107
  @start_page_number = page_number
100
108
  end
101
-
102
- # @param [String] layout path to layout-file.
109
+
110
+ # @param [String] layout filename of layout file
103
111
  # @param [Hash] options
104
112
  # @option options [Boolean] :default (true)
105
113
  # @option options [Symbol] :id (nil)
106
114
  # @yield [config]
107
- # @yieldparam [ThinReports::Layout::Configuration] config
108
- # @return [void]
115
+ # @yieldparam [Thinreports::Layout::Configuration] config
116
+ # @example
117
+ # report.use_layout '/path/to/default_layout.tlf' # Default layout
118
+ # report.use_layout '/path/to/default_layout.tlf', default: true
119
+ # report.use_layout '/path/to/other_layout', id: :other_layout
109
120
  def use_layout(layout, options = {}, &block)
110
121
  internal.register_layout(layout, options, &block)
111
122
  end
112
-
123
+
124
+ # @example
125
+ # page = report.start_new_page
126
+ #
127
+ # report.start_new_page do |page|
128
+ # page.item(:text).value = 'value'
129
+ # end
130
+ #
131
+ # report.use_layout 'foo.tlf', default: true
132
+ # report.use_layout 'bar.tlf', id: :bar
133
+ #
134
+ # report.start_new_page # Use 'foo.tlf'
135
+ # report.start_new_page layout: :bar # Use 'bar.tlf'
136
+ # report.start_new_page layout: 'boo.tlf' # Use 'boo.tlf'
113
137
  # @param [Hash] options
114
138
  # @option options [String, Symbol] :layout (nil)
115
139
  # @option options [Boolean] :count (true)
116
140
  # @yield [page]
117
- # @yieldparam [ThinReports::Core::Page] page
118
- # @return [ThinReports::Core::Page]
141
+ # @yieldparam [Thinreports::Report::Page] page
142
+ # @return [Thinreports::Report::Page]
119
143
  def start_new_page(options = {}, &block)
120
144
  unless layout = internal.load_layout(options.delete(:layout))
121
- raise ThinReports::Errors::NoRegisteredLayoutFound
145
+ raise Thinreports::Errors::NoRegisteredLayoutFound
122
146
  end
123
-
124
- page = internal.add_page(layout.init_new_page(self, options))
125
- block_exec_on(page, &block)
147
+
148
+ page = internal.add_page(layout.new_page(self, options))
149
+ call_block_in(page, &block)
126
150
  end
127
-
151
+
128
152
  # @param [Hash] options
129
153
  # @option options [Boolean] :count (true)
130
- # @return [ThinReports::Core::BlankPage]
154
+ # @return [Thinreports::Report::BlankPage]
131
155
  def add_blank_page(options = {})
132
- internal.add_page(Core::BlankPage.new(options[:count]))
156
+ internal.add_page(Report::BlankPage.new(options[:count]))
133
157
  end
134
158
  alias_method :blank_page, :add_blank_page
135
-
136
- # @param [Symbol, nil] id Return the default layout
137
- # if nil (see #default_layout).
138
- # @return [ThinReports::Layout::Base]
159
+
160
+ # @param [Symbol, nil] id
161
+ # @return [Thinreports::Layout::Base]
139
162
  def layout(id = nil)
140
163
  if id
141
164
  internal.layout_registry[id] ||
142
- raise(ThinReports::Errors::UnknownLayoutId)
165
+ raise(Thinreports::Errors::UnknownLayoutId)
143
166
  else
144
167
  internal.default_layout
145
168
  end
146
169
  end
147
-
148
- # @return [ThinReports::Layout::Base]
149
- def default_layout
150
- internal.default_layout
151
- end
152
-
153
- # @overload generate(type, options = {})
154
- # Specify the generator type.
155
- # @param [Symbol] type
156
- # @return [String]
170
+
157
171
  # @overload generate(options = {})
158
- # Using the default generator type.
159
172
  # @param [Hash] options ({})
160
173
  # @return [String]
161
- # @example Generate the PDF data
162
- # report.generate(:pdf) #=> "%PDF-1.4...."
163
- #
164
- # # Or, you can omit the type of generator
165
- # report.generate
166
- # @example Create the PDF file (Since v0.8)
167
- # report.generate(:pdf, :filename => 'foo.pdf')
174
+ # @overload generate(type, options = {})
175
+ # This way has been DEPRECATED. Use instead #generate(options = {}).
176
+ # @param [Symbol] type
177
+ # @return [String]
178
+ # @example Generate PDF data
179
+ # report.generate # => "%PDF-1.4...."
180
+ # @example Create a PDF file
181
+ # report.generate(filename: 'foo.pdf')
168
182
  def generate(*args)
169
183
  options = args.last.is_a?(::Hash) ? args.pop : {}
170
- type = args.first || ThinReports.config.generator.default
184
+ type = args.first || Thinreports.config.generator.default
171
185
  filename = options.delete(:filename)
172
- generator = ThinReports::Generator.new(type, self, options)
186
+ generator = Thinreports::Generator.new(type, self, options)
173
187
 
174
- if filename
175
- generator.generate_file(filename)
176
- else
177
- generator.generate
178
- end
188
+ generator.generate(filename)
179
189
  end
180
-
181
- # @overload generate_file(type, filename, options = {})
182
- # @param type (#generate)
183
- # @return [void]
184
- # @overload generate_file(filename, options = {})
185
- # @param [String] filename
186
- # @param options (see #generate)
187
- # @return [void]
188
- # @deprecated Please use the #generate method with :filename option instead.
189
- def generate_file(*args)
190
- warn '[DEPRECATION] The #generate_file method is deprecated. ' +
191
- 'Please use the #generate(:filename => "filename") instead.'
192
190
 
193
- options = args.last.is_a?(::Hash) ? args.pop : {}
194
- args.unshift(ThinReports.config.generator.default) if args.size == 1
195
- type, filename = args
196
-
197
- generate(type, options.merge(:filename => filename))
198
- end
199
-
200
- # @see ThinReports::Core::Shape::Manager::Target#list
191
+ # @see Thinreports::Core::Shape::Manager::Target#list
201
192
  def list(id = nil, &block)
202
193
  start_new_page if page.nil? || page.finalized?
203
194
  page.list(id, &block)
204
195
  end
205
-
206
- # @return [ThinReports::Report::Events]
196
+
197
+ # @return [Thinreports::Report::Events]
198
+ # @deprecated
199
+ # `Report::Base#events` will be removed in the next major version.
200
+ # Please use #on_page_create callbacks instead.
201
+ # See also https://github.com/thinreports/thinreports-generator/blob/master/examples/report_callbacks/report_callbacks.rb.
207
202
  def events
203
+ warn '[DEPRECATION] `Report::Base#events` will be removed in the next major version. ' +
204
+ 'Please use #on_page_create callbacks instead. ' +
205
+ 'See also https://github.com/thinreports/thinreports-generator/blob/master/examples/report_callbacks/report_callbacks.rb.'
208
206
  internal.events
209
207
  end
210
-
211
- # @return [ThinReports::Core::Page, nil]
212
- def page
213
- internal.page
214
- end
215
-
216
- # @return [Integer]
217
- def page_count
218
- internal.page_count
219
- end
220
-
221
- # @return [void]
222
- # @private
223
- def finalize
224
- internal.finalize
225
- end
226
-
227
- # @return [Boolean]
228
- # @private
229
- def finalized?
230
- internal.finalized?
231
- end
208
+
209
+ def_delegators :internal, :finalize, :finalized?
232
210
  end
233
-
211
+
234
212
  end
235
213
  end