thinreports 0.7.6 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -5
  3. data/.travis.yml +8 -4
  4. data/CHANGELOG.md +220 -0
  5. data/Gemfile +2 -9
  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/examples/dynamic_style/dynamic_style.rb +150 -0
  14. data/examples/dynamic_style/dynamic_style.tlf +1 -0
  15. data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
  16. data/examples/eudc/eudc.rb +20 -0
  17. data/examples/eudc/eudc.tlf +1 -0
  18. data/examples/helper.rb +50 -0
  19. data/examples/hidden_shapes/hidden_shapes.rb +9 -0
  20. data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
  21. data/examples/list_events/list_events.rb +59 -0
  22. data/examples/list_events/list_events_0_7_7.tlf +1 -0
  23. data/examples/list_events/list_events_0_8.tlf +1 -0
  24. data/examples/list_manual_generation/list_manual_generation.rb +22 -0
  25. data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
  26. data/examples/list_page_number/list_page_number.rb +17 -0
  27. data/examples/list_page_number/list_page_number.tlf +1 -0
  28. data/examples/page_number/page_number.rb +33 -0
  29. data/examples/page_number/page_number.tlf +1 -0
  30. data/examples/password_setting/password_setting.rb +10 -0
  31. data/examples/password_setting/password_setting.tlf +1 -0
  32. data/examples/report_callbacks/report_callbacks.rb +31 -0
  33. data/examples/report_callbacks/report_callbacks.tlf +1 -0
  34. data/examples/single_line_tblock/single_line_tblock.rb +13 -0
  35. data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
  36. data/examples/tblock_overflow/tblock_overflow.rb +20 -0
  37. data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
  38. data/examples/tblock_styles/font_size.tlf +1 -0
  39. data/examples/tblock_styles/tblock_styles.rb +43 -0
  40. data/examples/tblock_styles/tblock_styles.tlf +1 -0
  41. data/examples/text_align/text_align.rb +8 -0
  42. data/examples/text_align/text_align.tlf +1 -0
  43. data/examples/typeB_page_size/B4_ISO.tlf +1 -0
  44. data/examples/typeB_page_size/B4_JIS.tlf +1 -0
  45. data/examples/typeB_page_size/typeB_page_size.rb +17 -0
  46. data/examples/word_wrap/word_wrap.rb +26 -0
  47. data/examples/word_wrap/word_wrap.tlf +1 -0
  48. data/lib/thinreports/config.rb +30 -10
  49. data/lib/thinreports/core/errors.rb +23 -20
  50. data/lib/thinreports/core/events.rb +18 -19
  51. data/lib/thinreports/core/format/base.rb +20 -25
  52. data/lib/thinreports/core/format/builder.rb +19 -27
  53. data/lib/thinreports/core/shape/base/interface.rb +15 -15
  54. data/lib/thinreports/core/shape/base/internal.rb +15 -20
  55. data/lib/thinreports/core/shape/base.rb +4 -5
  56. data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
  57. data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
  58. data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
  59. data/lib/thinreports/core/shape/basic/format.rb +11 -10
  60. data/lib/thinreports/core/shape/basic/interface.rb +3 -3
  61. data/lib/thinreports/core/shape/basic/internal.rb +9 -6
  62. data/lib/thinreports/core/shape/basic.rb +1 -1
  63. data/lib/thinreports/core/shape/image_block/format.rb +5 -6
  64. data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
  65. data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
  66. data/lib/thinreports/core/shape/image_block.rb +1 -1
  67. data/lib/thinreports/core/shape/list/configuration.rb +37 -16
  68. data/lib/thinreports/core/shape/list/events.rb +11 -11
  69. data/lib/thinreports/core/shape/list/format.rb +27 -28
  70. data/lib/thinreports/core/shape/list/manager.rb +135 -95
  71. data/lib/thinreports/core/shape/list/page.rb +57 -51
  72. data/lib/thinreports/core/shape/list/page_state.rb +19 -17
  73. data/lib/thinreports/core/shape/list/section_format.rb +14 -15
  74. data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
  75. data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
  76. data/lib/thinreports/core/shape/list/store.rb +10 -11
  77. data/lib/thinreports/core/shape/list.rb +1 -1
  78. data/lib/thinreports/core/shape/manager/format.rb +10 -11
  79. data/lib/thinreports/core/shape/manager/internal.rb +22 -21
  80. data/lib/thinreports/core/shape/manager/target.rb +63 -34
  81. data/lib/thinreports/core/shape/manager.rb +1 -1
  82. data/lib/thinreports/core/shape/page_number/format.rb +25 -0
  83. data/lib/thinreports/core/shape/page_number/interface.rb +27 -0
  84. data/lib/thinreports/core/shape/page_number/internal.rb +57 -0
  85. data/lib/thinreports/core/shape/page_number.rb +15 -0
  86. data/lib/thinreports/core/shape/style/base.rb +29 -29
  87. data/lib/thinreports/core/shape/style/basic.rb +1 -1
  88. data/lib/thinreports/core/shape/style/graphic.rb +10 -25
  89. data/lib/thinreports/core/shape/style/text.rb +41 -31
  90. data/lib/thinreports/core/shape/style.rb +1 -1
  91. data/lib/thinreports/core/shape/text/format.rb +8 -9
  92. data/lib/thinreports/core/shape/text/interface.rb +2 -2
  93. data/lib/thinreports/core/shape/text/internal.rb +6 -7
  94. data/lib/thinreports/core/shape/text.rb +1 -1
  95. data/lib/thinreports/core/shape/text_block/format.rb +17 -17
  96. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
  97. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
  98. data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
  99. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
  100. data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
  101. data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
  102. data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
  103. data/lib/thinreports/core/shape/text_block.rb +1 -1
  104. data/lib/thinreports/core/shape.rb +11 -13
  105. data/lib/thinreports/core/utils.rb +33 -32
  106. data/lib/thinreports/generator/base.rb +15 -24
  107. data/lib/thinreports/generator/configuration.rb +10 -9
  108. data/lib/thinreports/generator/pdf/configuration.rb +11 -6
  109. data/lib/thinreports/generator/pdf/document/draw_shape.rb +41 -32
  110. data/lib/thinreports/generator/pdf/document/font.rb +53 -44
  111. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +34 -25
  112. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
  113. data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
  114. data/lib/thinreports/generator/pdf/document/graphics/text.rb +43 -41
  115. data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
  116. data/lib/thinreports/generator/pdf/document/page.rb +37 -23
  117. data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
  118. data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
  119. data/lib/thinreports/generator/pdf/document.rb +28 -28
  120. data/lib/thinreports/generator/pdf/drawer/base.rb +16 -22
  121. data/lib/thinreports/generator/pdf/drawer/list.rb +39 -21
  122. data/lib/thinreports/generator/pdf/drawer/list_section.rb +17 -18
  123. data/lib/thinreports/generator/pdf/drawer/page.rb +37 -26
  124. data/lib/thinreports/generator/pdf/prawn_ext.rb +18 -17
  125. data/lib/thinreports/generator/pdf.rb +28 -31
  126. data/lib/thinreports/generator.rb +6 -8
  127. data/lib/thinreports/layout/base.rb +24 -36
  128. data/lib/thinreports/layout/configuration.rb +11 -9
  129. data/lib/thinreports/layout/format.rb +26 -31
  130. data/lib/thinreports/layout/version.rb +8 -9
  131. data/lib/thinreports/layout.rb +2 -2
  132. data/lib/thinreports/report/base.rb +117 -109
  133. data/lib/thinreports/report/events.rb +5 -5
  134. data/lib/thinreports/report/internal.rb +48 -38
  135. data/lib/thinreports/{core → report}/page.rb +42 -32
  136. data/lib/thinreports/report.rb +10 -14
  137. data/lib/thinreports/version.rb +2 -3
  138. data/lib/thinreports.rb +14 -2
  139. data/test/data/font.ttf +0 -0
  140. data/test/data/layout_block.tlf +1 -0
  141. data/test/data/layout_list.tlf +1 -0
  142. data/test/data/layout_list_noheader.tlf +1 -0
  143. data/test/data/layout_text1.tlf +1 -0
  144. data/test/data/layout_text2.tlf +1 -0
  145. data/test/test_helper.rb +74 -0
  146. data/test/tmp/.gitkeep +0 -0
  147. data/test/unit/core/format/test_base.rb +14 -14
  148. data/test/unit/core/format/test_builder.rb +20 -25
  149. data/test/unit/core/shape/base/test_internal.rb +34 -37
  150. data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
  151. data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
  152. data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
  153. data/test/unit/core/shape/basic/test_format.rb +4 -4
  154. data/test/unit/core/shape/basic/test_interface.rb +36 -46
  155. data/test/unit/core/shape/basic/test_internal.rb +29 -18
  156. data/test/unit/core/shape/image_block/test_format.rb +5 -5
  157. data/test/unit/core/shape/image_block/test_interface.rb +17 -16
  158. data/test/unit/core/shape/image_block/test_internal.rb +19 -16
  159. data/test/unit/core/shape/list/test_configuration.rb +50 -33
  160. data/test/unit/core/shape/list/test_events.rb +7 -7
  161. data/test/unit/core/shape/list/test_format.rb +16 -18
  162. data/test/unit/core/shape/list/test_manager.rb +15 -5
  163. data/test/unit/core/shape/list/test_page.rb +80 -22
  164. data/test/unit/core/shape/list/test_page_state.rb +13 -13
  165. data/test/unit/core/shape/list/test_section_format.rb +16 -17
  166. data/test/unit/core/shape/list/test_section_interface.rb +30 -22
  167. data/test/unit/core/shape/list/test_section_internal.rb +21 -19
  168. data/test/unit/core/shape/list/test_store.rb +7 -7
  169. data/test/unit/core/shape/manager/test_format.rb +11 -15
  170. data/test/unit/core/shape/manager/test_internal.rb +9 -9
  171. data/test/unit/core/shape/manager/test_target.rb +85 -57
  172. data/test/unit/core/shape/page_number/test_format.rb +73 -0
  173. data/test/unit/core/shape/page_number/test_interface.rb +33 -0
  174. data/test/unit/core/shape/page_number/test_internal.rb +81 -0
  175. data/test/unit/core/shape/styles/test_base.rb +9 -9
  176. data/test/unit/core/shape/styles/test_basic.rb +5 -5
  177. data/test/unit/core/shape/styles/test_graphic.rb +19 -33
  178. data/test/unit/core/shape/styles/test_text.rb +29 -7
  179. data/test/unit/core/shape/text/test_format.rb +6 -6
  180. data/test/unit/core/shape/text/test_internal.rb +11 -12
  181. data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
  182. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +22 -20
  183. data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
  184. data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
  185. data/test/unit/core/shape/text_block/test_format.rb +13 -8
  186. data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
  187. data/test/unit/core/shape/text_block/test_interface.rb +37 -20
  188. data/test/unit/core/shape/text_block/test_internal.rb +38 -38
  189. data/test/unit/core/test_events.rb +10 -8
  190. data/test/unit/core/test_shape.rb +11 -7
  191. data/test/unit/core/test_utils.rb +68 -0
  192. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +10 -4
  193. data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
  194. data/test/unit/generator/pdf/document/test_draw_shape.rb +14 -6
  195. data/test/unit/generator/pdf/document/test_font.rb +79 -58
  196. data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
  197. data/test/unit/generator/pdf/document/test_page.rb +68 -43
  198. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  199. data/test/unit/generator/pdf/test_configuration.rb +16 -9
  200. data/test/unit/generator/pdf/test_document.rb +8 -16
  201. data/test/unit/generator/test_base.rb +31 -42
  202. data/test/unit/generator/test_configuration.rb +6 -6
  203. data/test/unit/generator/test_pdf.rb +15 -21
  204. data/test/unit/layout/test_base.rb +34 -79
  205. data/test/unit/layout/test_configuration.rb +12 -37
  206. data/test/unit/layout/test_format.rb +36 -39
  207. data/test/unit/layout/test_version.rb +4 -4
  208. data/test/unit/report/test_base.rb +160 -192
  209. data/test/unit/report/test_events.rb +4 -4
  210. data/test/unit/report/test_internal.rb +102 -82
  211. data/test/unit/test_config.rb +31 -12
  212. data/test/unit/test_layout.rb +7 -7
  213. data/test/unit/test_report.rb +12 -24
  214. data/thinreports.gemspec +23 -26
  215. metadata +118 -181
  216. data/.yardopts +0 -1
  217. data/LICENSE +0 -1
  218. data/README.rdoc +0 -167
  219. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  220. data/lib/thinreports/core/ext/array.rb +0 -19
  221. data/lib/thinreports/core/ext/hash.rb +0 -19
  222. data/lib/thinreports/core/ext/object.rb +0 -25
  223. data/lib/thinreports/core/ext.rb +0 -5
  224. data/lib/thinreports/core/format.rb +0 -14
  225. data/lib/thinreports/core/ordered_hash.rb +0 -39
  226. data/lib/thinreports/core.rb +0 -20
  227. data/lib/thinreports/generator/pdf/drawer.rb +0 -16
  228. data/tasks/doc.rake +0 -13
  229. data/tasks/test.rake +0 -56
  230. data/test/benchmark/basic_estimate.tlf +0 -1
  231. data/test/benchmark/bench_basic_estimate.rb +0 -95
  232. data/test/case/character_spacing/character_spacing.rb +0 -7
  233. data/test/case/character_spacing/character_spacing.tlf +0 -1
  234. data/test/case/dynamic_image/dynamic_image.rb +0 -41
  235. data/test/case/dynamic_image/dynamic_image.tlf +0 -1
  236. data/test/case/dynamic_style/dynamic_style.rb +0 -154
  237. data/test/case/dynamic_style/dynamic_style.tlf +0 -1
  238. data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
  239. data/test/case/eudc/eudc.rb +0 -20
  240. data/test/case/eudc/eudc.tlf +0 -1
  241. data/test/case/helper.rb +0 -29
  242. data/test/case/hidden_shapes/hidden_shapes.rb +0 -13
  243. data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
  244. data/test/case/list_events/list_events.rb +0 -32
  245. data/test/case/list_events/list_events.tlf +0 -1
  246. data/test/case/list_header_inheriting/list_header_inheriting.rb +0 -17
  247. data/test/case/list_header_inheriting/list_header_inheriting.tlf +0 -1
  248. data/test/case/list_manual_generation/list_manual_generation.rb +0 -22
  249. data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
  250. data/test/case/single_line_tblock/single_line_tblock.rb +0 -15
  251. data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
  252. data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
  253. data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
  254. data/test/case/tblock_styles/tblock_styles.rb +0 -27
  255. data/test/case/tblock_styles/tblock_styles.tlf +0 -1
  256. data/test/case/text_align/text_align.rb +0 -9
  257. data/test/case/text_align/text_align.tlf +0 -1
  258. data/test/unit/core/ext/array_spec.rb +0 -29
  259. data/test/unit/core/ext/hash_spec.rb +0 -29
  260. data/test/unit/core/ext/object_spec.rb +0 -30
  261. data/test/unit/core/ordered_hash_spec.rb +0 -51
  262. data/test/unit/core/shape/base/test_interface.rb +0 -52
  263. data/test/unit/core/utils_spec.rb +0 -56
  264. data/test/unit/data/basic_layout1.tlf +0 -1
  265. data/test/unit/data/basic_layout2.tlf +0 -1
  266. data/test/unit/data/basic_list_layout.tlf +0 -1
  267. data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
  268. data/test/unit/helper.rb +0 -65
  269. /data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
  270. /data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
  271. /data/{test/case → examples}/dynamic_style/image.png +0 -0
  272. /data/{test/case → examples}/eudc/eudc.ttf +0 -0
  273. /data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
  274. /data/{resources/fonts → fonts}/ipag.ttf +0 -0
  275. /data/{resources/fonts → fonts}/ipagp.ttf +0 -0
  276. /data/{resources/fonts → fonts}/ipam.ttf +0 -0
  277. /data/{resources/fonts → fonts}/ipamp.ttf +0 -0
@@ -1,28 +1,35 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
4
- module Generator
5
-
6
- # @private
7
- class PDF::Drawer::Page < PDF::Drawer::Base
3
+ module Thinreports
4
+ module Generator::PDF::Drawer
5
+
6
+ class Page < Base
8
7
  # @param (see PDF::Drawer::Base#initialize)
9
8
  def initialize(pdf, format)
10
9
  super
11
10
  @lists = {}
12
11
  end
13
-
14
- # @param [ThinReports::Core::Shape::Manager::Internal] manager
15
- def draw(manager)
12
+
13
+ # @param [Thinreports::Report::Page] page
14
+ def draw(page)
15
+ manager = page.manager
16
+
16
17
  manager.format.shapes.each_key do |id|
17
- if shape = manager.final_shape(id)
18
- draw_shape(shape.internal)
18
+ next unless shape = manager.final_shape(id)
19
+
20
+ shape = shape.internal
21
+
22
+ if shape.type_of?(:pageno)
23
+ # Do not draw pageno if is not for Report
24
+ draw_pageno_shape(shape, page) if page.count? && shape.for_report?
25
+ else
26
+ draw_shape(shape)
19
27
  end
20
28
  end
21
29
  end
22
-
30
+
23
31
  private
24
-
25
- # @param [ThinReports::Core::Shape::Base::Internal] shape
32
+
26
33
  def draw_shape(shape)
27
34
  case
28
35
  when shape.type_of?(:tblock)
@@ -32,7 +39,7 @@ module ThinReports
32
39
  when shape.type_of?(:iblock)
33
40
  draw_iblock_shape(shape)
34
41
  else
35
- id = shape_stamp_id(shape)
42
+ id = shape.identifier
36
43
  unless @stamps.include?(id)
37
44
  create_basic_shape_stamp(shape)
38
45
  @stamps << id
@@ -40,24 +47,28 @@ module ThinReports
40
47
  pdf_stamp(shape)
41
48
  end
42
49
  end
43
-
50
+
51
+ def draw_pageno_shape(shape, page)
52
+ @pdf.draw_shape_pageno(shape, page.no, page.report.page_count)
53
+ end
54
+
44
55
  # @see #draw_shape
45
56
  def draw_list_shape(shape)
46
- drawer = @lists[shape.id] ||= PDF::Drawer::List.new(@pdf, shape.format)
57
+ drawer = @lists[shape.id] ||= List.new(@pdf, shape.format)
47
58
  drawer.draw(shape)
48
59
  end
49
-
60
+
50
61
  # @see #draw_shape
51
62
  def draw_tblock_shape(shape)
52
63
  @pdf.draw_shape_tblock(shape)
53
64
  end
54
-
65
+
55
66
  # @see #draw_shape
56
67
  def draw_iblock_shape(shape)
57
68
  @pdf.draw_shape_iblock(shape)
58
69
  end
59
-
60
- # @param [ThinReports::Core::Shape::Base::Internal] shape
70
+
71
+ # @param [Thinreports::Core::Shape::Base::Internal] shape
61
72
  def create_basic_shape_stamp(shape)
62
73
  case
63
74
  when shape.type_of?(:text) then create_text_stamp(shape)
@@ -67,35 +78,35 @@ module ThinReports
67
78
  when shape.type_of?(:line) then create_line_stamp(shape)
68
79
  end
69
80
  end
70
-
81
+
71
82
  # @see #create_basic_shape_stamp
72
83
  def create_image_stamp(shape)
73
84
  create_pdf_stamp(shape) do
74
85
  @pdf.draw_shape_image(shape)
75
86
  end
76
87
  end
77
-
88
+
78
89
  # @see #create_basic_shape_stamp
79
90
  def create_rect_stamp(shape)
80
91
  create_pdf_stamp(shape) do
81
92
  @pdf.draw_shape_rect(shape)
82
93
  end
83
94
  end
84
-
95
+
85
96
  # @see #create_basic_shape_stamp
86
97
  def create_ellipse_stamp(shape)
87
98
  create_pdf_stamp(shape) do
88
99
  @pdf.draw_shape_ellipse(shape)
89
100
  end
90
101
  end
91
-
102
+
92
103
  # @see #create_basic_shape_stamp
93
104
  def create_line_stamp(shape)
94
105
  create_pdf_stamp(shape) do
95
106
  @pdf.draw_shape_line(shape)
96
107
  end
97
108
  end
98
-
109
+
99
110
  # @see #create_basic_shape_stamp
100
111
  def create_text_stamp(shape)
101
112
  create_pdf_stamp(shape) do
@@ -103,6 +114,6 @@ module ThinReports
103
114
  end
104
115
  end
105
116
  end
106
-
117
+
107
118
  end
108
119
  end
@@ -1,31 +1,32 @@
1
1
  # coding: utf-8
2
2
 
3
- # @private
4
3
  module Prawn
5
- # @private
6
4
  class Document
7
- # Create around alias.
8
5
  alias_method :original_width_of, :width_of
9
-
6
+
10
7
  def width_of(string, options={})
11
8
  font.compute_width_of(string, options) +
12
9
  (character_spacing * (font.character_count(string) - 1))
13
10
  end
14
-
15
- private
16
- # Create around alias.
17
- alias_method :original_calc_image_dimensions, :calc_image_dimensions
18
-
19
- def calc_image_dimensions(info, options)
20
- if options[:auto_fit]
21
- w, h = info.width, info.height
22
- sw, sh = options.delete(:auto_fit)
23
-
24
- if w > sw || h > sh
25
- options[:fit] = [sw, sh]
11
+ end
12
+
13
+ module Images
14
+ class Image
15
+ alias_method :original_calc_image_dimensions, :calc_image_dimensions
16
+
17
+ def calc_image_dimensions(options)
18
+ if options[:auto_fit]
19
+ w = options[:width] || width
20
+ h = options[:height] || height
21
+
22
+ box_width, box_height = options.delete(:auto_fit)
23
+
24
+ if w > box_width || h > box_height
25
+ options[:fit] = [box_width, box_height]
26
+ end
26
27
  end
28
+ original_calc_image_dimensions(options)
27
29
  end
28
- original_calc_image_dimensions(info, options)
29
30
  end
30
31
  end
31
32
  end
@@ -1,68 +1,65 @@
1
1
  # coding: utf-8
2
2
 
3
3
  begin
4
- gem 'prawn', '0.12.0'
4
+ gem 'prawn', '1.3.0'
5
5
  require 'prawn'
6
6
  rescue LoadError
7
- puts 'ThinReports requires Prawn = 0.12.0. ' +
8
- 'Please `gem install prawn -v 0.12.0` and try again.'
7
+ puts 'Thinreports requires Prawn = 1.3.0. ' +
8
+ 'Please `gem install prawn -v 1.3.0` and try again.'
9
9
  end
10
10
 
11
- module ThinReports
11
+ module Thinreports
12
12
  module Generator
13
-
13
+
14
14
  class PDF < Base
15
- # @param report (see ThinReports::Generator::Base#initialize)
15
+ # @param report (see Thinreports::Generator::Base#initialize)
16
16
  # @param [Hash] options
17
17
  # @option options [Hash] :security (nil)
18
18
  # See Prawn::Document#encrypt_document
19
19
  def initialize(report, options)
20
20
  super
21
-
21
+
22
22
  title = default_layout ? default_layout.format.report_title : nil
23
23
 
24
- @pdf = Document.new(options, :Title => title)
24
+ @document = Document.new(options, Title: title)
25
25
  @drawers = {}
26
26
  end
27
-
28
- # @see ThinReports::Generator::Base#generate
29
- def generate
30
- draw_report
31
- @pdf.render
32
- end
33
-
34
- # @see ThinReports::Generator::Base#generate_file
35
- def generate_file(filename)
27
+
28
+ # @see Thinreports::Generator::Base#generate
29
+ def generate(filename = nil)
36
30
  draw_report
37
- @pdf.render_file(filename)
31
+ filename ? @document.render_file(filename) : @document.render
38
32
  end
39
-
33
+
40
34
  private
41
-
35
+
42
36
  def draw_report
43
37
  report.pages.each do |page|
44
38
  draw_page(page)
45
39
  end
46
40
  end
47
-
41
+
48
42
  def draw_page(page)
49
- return @pdf.add_blank_page if page.blank?
50
-
43
+ return @document.add_blank_page if page.blank?
44
+
51
45
  format = page.layout.format
52
- @pdf.start_new_page(format)
53
-
54
- drawer(format).draw(page.manager)
46
+ @document.start_new_page(format)
47
+
48
+ drawer(format).draw(page)
55
49
  end
56
-
50
+
57
51
  def drawer(format)
58
- @drawers[format.identifier] ||= Drawer::Page.new(@pdf, format)
59
- end
52
+ @drawers[format.identifier] ||= Drawer::Page.new(@document, format)
53
+ end
60
54
  end
61
-
55
+
62
56
  end
63
57
  end
64
58
 
65
59
  require 'thinreports/generator/pdf/configuration'
66
60
  require 'thinreports/generator/pdf/prawn_ext'
67
61
  require 'thinreports/generator/pdf/document'
68
- require 'thinreports/generator/pdf/drawer'
62
+ require 'thinreports/generator/pdf/drawer/base'
63
+ require 'thinreports/generator/pdf/drawer/page'
64
+ require 'thinreports/generator/pdf/drawer/list'
65
+ require 'thinreports/generator/pdf/drawer/list_section'
@@ -1,24 +1,22 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
 
5
5
  module Generator
6
6
  # @param [Symbol] type
7
- # @param report (see ThinReports::Generator::Base#initialize)
8
- # @param options (see ThinReports::Generator::Base#initialize)
7
+ # @param report (see Thinreports::Generator::Base#initialize)
8
+ # @param options (see Thinreports::Generator::Base#initialize)
9
9
  def self.new(type, report, options = {})
10
10
  unless generator = registry[type]
11
- raise ThinReports::Errors::UnknownGeneratorType.new(type)
11
+ raise Thinreports::Errors::UnknownGeneratorType.new(type)
12
12
  end
13
13
  generator.new(report, options)
14
14
  end
15
-
16
- # @private
15
+
17
16
  def self.register(type, generator)
18
17
  registry[type] = generator
19
18
  end
20
-
21
- # @private
19
+
22
20
  def self.registry
23
21
  @generators ||= {}
24
22
  end
@@ -1,49 +1,36 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Layout
5
-
5
+
6
6
  class Base
7
7
  EXT_NAME = 'tlf'
8
-
8
+ include Utils
9
+
9
10
  class << self
10
11
  # @param [String] filename
11
- # @return [ThinReports::Layout::Format]
12
- # @raise [ThinReports::Errors::InvalidLayoutFormat]
13
- # @raise [ThinReports::Errors::IncompatibleLayoutFormat]
14
- # @private
12
+ # @return [Thinreports::Layout::Format]
13
+ # @raise [Thinreports::Errors::InvalidLayoutFormat]
14
+ # @raise [Thinreports::Errors::IncompatibleLayoutFormat]
15
15
  def load_format(filename)
16
16
  filename += ".#{EXT_NAME}" unless filename =~/\.#{EXT_NAME}$/
17
-
17
+
18
18
  unless File.exists?(filename)
19
- raise ThinReports::Errors::LayoutFileNotFound
19
+ raise Thinreports::Errors::LayoutFileNotFound
20
20
  end
21
21
  # Build format.
22
- ThinReports::Layout::Format.build(filename)
23
- end
24
-
25
- # @private
26
- def Page
27
- const_defined?(:Page) ? Page : Core::Page
28
- end
29
-
30
- private
31
-
32
- # @private
33
- def PageHelpers(&block)
34
- const_set(:Page, ::Class.new(Core::Page, &block))
22
+ Thinreports::Layout::Format.build(filename)
35
23
  end
36
24
  end
37
-
38
- # @private
25
+
39
26
  attr_reader :format
40
-
27
+
41
28
  # @return [String]
42
29
  attr_reader :filename
43
-
30
+
44
31
  # @return [Symbol]
45
32
  attr_reader :id
46
-
33
+
47
34
  # @param [String] filename
48
35
  # @param [Hash] options
49
36
  # @option options [Symbol] :id (nil)
@@ -52,27 +39,28 @@ module ThinReports
52
39
  @format = self.class.load_format(filename)
53
40
  @id = options[:id]
54
41
  end
55
-
42
+
56
43
  # @return [Boolean] Return the true if is default layout.
57
44
  def default?
58
45
  @id.nil?
59
46
  end
60
-
47
+
61
48
  # @yield [config]
62
49
  # @yieldparam [List::Configuration] config
63
50
  # @return [List::Configuration]
64
51
  def config(&block)
65
52
  @config ||= Layout::Configuration.new(self)
66
- block_exec_on(@config, &block)
53
+ call_block_in(@config, &block)
67
54
  end
68
-
69
- # @param [ThinReports::Report::Base] parent
55
+
56
+ # @param [Thinreports::Report::Base] parent
57
+ # @param [Hash] options ({})
58
+ # @option option [Boolean] :count (true)
70
59
  # @return [Page]
71
- # @private
72
- def init_new_page(parent)
73
- self.class.Page.new(parent, self)
60
+ def new_page(parent, options = {})
61
+ Report::Page.new(parent, self, options)
74
62
  end
75
63
  end
76
-
64
+
77
65
  end
78
66
  end
@@ -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,44 +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
- :page_margin_top => %w( config page margin-top ),
17
- :page_margin_bottom => %w( config page margin-bottom ),
18
- :page_margin_left => %w( config page margin-left ),
19
- :page_margin_left => %w( config page margin-right )
20
-
21
- config_checker 'user', :user_paper_type => %w( config page paper-type )
22
-
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
+
23
18
  class << self
24
-
19
+
25
20
  private
26
-
21
+
27
22
  # @param [String] filename
28
23
  # @param [Hash] options
29
24
  # @option options [Boolean] :force (false)
30
25
  def build_internal(filename, options = {})
31
26
  build_once(filename, options[:force]) do |content, id|
32
27
  raw_format = parse_json(content)
33
-
28
+
34
29
  # Check the compatibility of specified layout file.
35
- unless ThinReports::Layout::Version.compatible?(raw_format['version'])
30
+ unless Thinreports::Layout::Version.compatible?(raw_format['version'])
36
31
  info = [filename, raw_format['version'],
37
- ThinReports::Layout::Version.inspect_required_rules]
38
- raise ThinReports::Errors::IncompatibleLayoutFormat.new(*info)
32
+ Thinreports::Layout::Version.inspect_required_rules]
33
+ raise Thinreports::Errors::IncompatibleLayoutFormat.new(*info)
39
34
  end
40
-
35
+
41
36
  compact_format!(raw_format)
42
-
37
+
43
38
  # Build and initialize format.
44
39
  new(raw_format, id) do |f|
45
40
  build_layout(f) do |type, shape_format|
@@ -49,17 +44,17 @@ module ThinReports
49
44
  end
50
45
  end
51
46
  end
52
-
47
+
53
48
  # @param [Hash] raw_format A parsed json.
54
49
  def compact_format!(raw_format)
55
50
  %w( finger-print state version ).each {|attr| raw_format.delete(attr) }
56
51
  end
57
-
52
+
58
53
  # @param [String] filename
59
54
  # @param [Boolean] force (false)
60
55
  def build_once(filename, force = false, &block)
61
56
  content = read_format_file(filename)
62
-
57
+
63
58
  if force
64
59
  block.call(content, nil)
65
60
  else
@@ -67,19 +62,19 @@ module ThinReports
67
62
  built_format_registry[id] ||= block.call(content, id)
68
63
  end
69
64
  end
70
-
65
+
71
66
  # @param [String] filename
72
67
  # @return [String]
73
68
  def read_format_file(filename)
74
69
  File.open(filename, 'r:UTF-8') {|f| f.read }
75
70
  end
76
-
71
+
77
72
  # @return [Hash]
78
73
  def built_format_registry
79
74
  @built_format_registry ||= {}
80
- end
75
+ end
81
76
  end
82
77
  end
83
-
78
+
84
79
  end
85
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,9 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
 
5
5
  module Layout
6
- # @see ThinReports::Layout::Base#initialize
6
+ # @see Thinreports::Layout::Base#initialize
7
7
  def self.new(filename, options = {})
8
8
  Base.new(filename, options)
9
9
  end