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,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
5
 
6
6
  module Text
@@ -1,18 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
-
6
- # @private
5
+
7
6
  class Text::Format < Basic::Format
8
7
  config_reader :text, :box, :valign
9
- config_reader :svg_content => %w( svg content ),
10
- :line_height => %w( line-height )
11
-
8
+ config_reader svg_content: %w( svg content ),
9
+ line_height: %w( line-height )
10
+
12
11
  class << self
13
12
  private
14
-
15
- # @see ThinReports::Core::Shape::Basic::Format#build_internal
13
+
14
+ # @see Thinreports::Core::Shape::Basic::Format#build_internal
16
15
  def build_internal(raw_format)
17
16
  new(raw_format) do |f|
18
17
  clean_with_attributes(f.svg_content)
@@ -20,6 +19,6 @@ module ThinReports
20
19
  end
21
20
  end
22
21
  end
23
-
22
+
24
23
  end
25
24
  end
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
5
 
6
6
  class Text::Interface < Basic::Interface
7
7
  private
8
8
 
9
- # @see ThinReports::Core::Shape::Base::Interface#init_internal
9
+ # @see Thinreports::Core::Shape::Base::Interface#init_internal
10
10
  def init_internal(parent, format)
11
11
  Text::Internal.new(parent, format)
12
12
  end
@@ -1,21 +1,20 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
-
6
- # @private
5
+
7
6
  class Text::Internal < Basic::Internal
8
7
  # Delegate to Format's methods
9
8
  format_delegators :svg_content, :text, :box
10
-
9
+
11
10
  def style
12
11
  @style ||= Style::Text.new(format)
13
12
  end
14
-
13
+
15
14
  def type_of?(type_name)
16
15
  type_name == :text
17
16
  end
18
17
  end
19
-
18
+
20
19
  end
21
- end
20
+ end
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
5
 
6
6
  module TextBlock
@@ -1,27 +1,26 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
-
6
- # @private
5
+
7
6
  class TextBlock::Format < Basic::BlockFormat
8
- config_reader :ref_id => %w( ref-id )
7
+ config_reader ref_id: %w( ref-id )
9
8
  config_reader :valign, :overflow
10
- config_reader :line_height => %w( line-height )
11
- config_reader :format_base => %w( format base ),
12
- :format_type => %w( format type ),
13
- :format_datetime_format => %w( format datetime format ),
14
- :format_number_delimiter => %w( format number delimiter ),
15
- :format_number_precision => %w( format number precision ),
16
- :format_padding_char => %w( format padding char ),
17
- :format_padding_dir => %w( format padding direction )
18
- config_reader :word_wrap => %w( word-wrap )
9
+ config_reader line_height: %w( line-height )
10
+ config_reader format_base: %w( format base ),
11
+ format_type: %w( format type ),
12
+ format_datetime_format: %w( format datetime format ),
13
+ format_number_delimiter: %w( format number delimiter ),
14
+ format_number_precision: %w( format number precision ),
15
+ format_padding_char: %w( format padding char ),
16
+ format_padding_dir: %w( format padding direction )
17
+ config_reader word_wrap: %w( word-wrap )
19
18
 
20
19
  config_checker 'true', :multiple
21
- config_checker 'R', :format_padding_rdir => %w( format padding direction )
20
+ config_checker 'R', format_padding_rdir: %w( format padding direction )
22
21
 
23
- config_reader :format_padding_length => %w( format padding length ) do |len|
24
- len.blank? ? 0 : len.to_i
22
+ config_reader format_padding_length: %w( format padding length ) do |len|
23
+ blank_value?(len) ? 0 : len.to_i
25
24
  end
26
25
 
27
26
  config_reader :has_format? => %w( format type ) do |type|
@@ -29,9 +28,9 @@ module ThinReports
29
28
  end
30
29
 
31
30
  config_reader :has_reference? => %w( ref-id ) do |ref_id|
32
- !ref_id.blank?
31
+ !blank_value?(ref_id)
33
32
  end
34
33
  end
35
-
34
+
36
35
  end
37
36
  end
@@ -1,14 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape::TextBlock
5
-
6
- # @private
5
+
7
6
  module Formatter
8
- # @param [ThinReports::Core::Shape::TextBlock::Format] format
9
- # @return [ThinReports::Core::Shape::TextBlock::Formatter::Base]
7
+ # @param [Thinreports::Core::Shape::TextBlock::Format] format
8
+ # @return [Thinreports::Core::Shape::TextBlock::Formatter::Base]
10
9
  def self.setup(format)
11
- klass = if format.format_type.blank?
10
+ klass = if Thinreports.blank_value?(format.format_type)
12
11
  Basic
13
12
  else
14
13
  case format.format_type
@@ -16,13 +15,13 @@ module ThinReports
16
15
  when 'datetime' then Datetime
17
16
  when 'padding' then Padding
18
17
  else
19
- raise ThinReports::Errors::UnknownFormatterType
18
+ raise Thinreports::Errors::UnknownFormatterType
20
19
  end
21
20
  end
22
21
  klass.new(format)
23
22
  end
24
23
  end
25
-
24
+
26
25
  end
27
26
  end
28
27
 
@@ -1,38 +1,39 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape::TextBlock
5
-
6
- # @private
5
+
7
6
  class Formatter::Basic
7
+ include Utils
8
+
8
9
  attr_reader :format
9
-
10
+
10
11
  def initialize(format)
11
12
  @format = format
12
13
  end
13
-
14
+
14
15
  def apply(value)
15
16
  if applicable?(value)
16
17
  value = apply_format_to(value)
17
18
  end
18
-
19
- unless format.format_base.blank?
19
+
20
+ unless blank_value?(format.format_base)
20
21
  format.format_base.gsub(/\{value\}/, value.to_s)
21
22
  else
22
23
  value
23
24
  end
24
25
  end
25
-
26
+
26
27
  private
27
-
28
+
28
29
  def apply_format_to(value)
29
30
  value
30
31
  end
31
-
32
+
32
33
  def applicable?(value)
33
34
  true
34
35
  end
35
36
  end
36
-
37
+
37
38
  end
38
- end
39
+ end
@@ -1,21 +1,20 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape::TextBlock
5
-
6
- # @private
5
+
7
6
  class Formatter::Datetime < Formatter::Basic
8
-
7
+
9
8
  private
10
-
9
+
11
10
  def apply_format_to(value)
12
11
  value.strftime(format.format_datetime_format)
13
12
  end
14
-
13
+
15
14
  def applicable?(value)
16
- !format.format_datetime_format.blank? && value.respond_to?(:strftime)
15
+ !blank_value?(format.format_datetime_format) && value.respond_to?(:strftime)
17
16
  end
18
17
  end
19
-
18
+
20
19
  end
21
- end
20
+ end
@@ -2,23 +2,22 @@
2
2
 
3
3
  require 'bigdecimal'
4
4
 
5
- module ThinReports
5
+ module Thinreports
6
6
  module Core::Shape::TextBlock
7
-
8
- # @private
7
+
9
8
  class Formatter::Number < Formatter::Basic
10
-
9
+
11
10
  private
12
-
11
+
13
12
  def apply_format_to(value)
14
13
  precision = format.format_number_precision
15
14
  delimiter = format.format_number_delimiter
16
-
15
+
17
16
  if_applicable value do |val|
18
- unless precision.blank?
17
+ unless blank_value?(precision)
19
18
  val = number_with_precision(val, precision)
20
19
  end
21
- unless delimiter.blank?
20
+ unless blank_value?(delimiter)
22
21
  val = number_with_delimiter(val, delimiter)
23
22
  end
24
23
  val
@@ -34,16 +33,16 @@ module ThinReports
34
33
  end
35
34
  val.nil? ? value : block.call(val)
36
35
  end
37
-
36
+
38
37
  def number_with_delimiter(value, delimiter = ',')
39
38
  value.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/){ "#{$1}#{delimiter}" }
40
39
  end
41
-
40
+
42
41
  def number_with_precision(value, precision = 3)
43
42
  value = BigDecimal(value.to_s).round(precision)
44
43
  sprintf("%.#{precision}f", value)
45
44
  end
46
45
  end
47
-
46
+
48
47
  end
49
- end
48
+ end
@@ -1,45 +1,22 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape::TextBlock
5
-
6
- # @private
5
+
7
6
  class Formatter::Padding < Formatter::Basic
8
-
9
- private
10
-
11
- ruby_18 do
12
- def apply_format_to(value)
13
- value = value.to_s
14
-
15
- char_length = value.unpack('U*').length
16
- pad_length = format.format_padding_length
17
-
18
- if pad_length > char_length
19
- pad_strs = format.format_padding_char * (pad_length - char_length)
20
- if format.format_padding_rdir?
21
- value + pad_strs
22
- else
23
- pad_strs + value
24
- end
25
- else
26
- value
27
- end
28
- end
29
- end
30
-
31
- ruby_19 do
7
+
8
+ private
9
+
32
10
  def apply_format_to(value)
33
11
  value.to_s.send(format.format_padding_rdir? ? :ljust : :rjust,
34
12
  format.format_padding_length,
35
13
  format.format_padding_char)
36
14
  end
37
- end
38
-
15
+
39
16
  def applicable?(value)
40
- !format.format_padding_char.blank? && format.format_padding_length > 0
17
+ !blank_value?(format.format_padding_char) && format.format_padding_length > 0
41
18
  end
42
19
  end
43
-
20
+
44
21
  end
45
- end
22
+ end
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
5
 
6
6
  class TextBlock::Interface < Basic::BlockInterface
@@ -23,7 +23,7 @@ module ThinReports
23
23
 
24
24
  private
25
25
 
26
- # @see ThinReports::Core::Shape::Base::Interface#init_internal
26
+ # @see Thinreports::Core::Shape::Base::Interface#init_internal
27
27
  def init_internal(parent, format)
28
28
  TextBlock::Internal.new(parent, format)
29
29
  end
@@ -1,26 +1,25 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
-
6
- # @private
5
+
7
6
  class TextBlock::Internal < Basic::BlockInternal
8
7
  format_delegators :multiple?
9
-
8
+
10
9
  def initialize(*args)
11
10
  super(*args)
12
-
11
+
13
12
  @reference = nil
14
13
  @formatter = nil
15
-
14
+
16
15
  @style = Style::Text.new(format)
17
16
  @style.accessible_styles.delete(:valign) unless multiple?
18
17
  end
19
-
18
+
20
19
  def style
21
20
  @style
22
21
  end
23
-
22
+
24
23
  def read_value
25
24
  if format.has_reference?
26
25
  @reference ||= parent.item(format.ref_id)
@@ -29,16 +28,16 @@ module ThinReports
29
28
  super
30
29
  end
31
30
  end
32
-
31
+
33
32
  def write_value(val)
34
33
  if format.has_reference?
35
34
  warn 'The set value was not saved, ' +
36
- "Because '#{format.id}' refers to '#{format.ref_id}'."
35
+ "Because '#{format.id}' has reference to '#{format.ref_id}'."
37
36
  else
38
37
  super
39
38
  end
40
39
  end
41
-
40
+
42
41
  def real_value
43
42
  if format_enabled?
44
43
  formatter.apply(read_value)
@@ -46,31 +45,31 @@ module ThinReports
46
45
  super
47
46
  end
48
47
  end
49
-
48
+
50
49
  def format_enabled(enabled)
51
50
  states[:format_enabled] = enabled
52
51
  end
53
-
52
+
54
53
  def format_enabled?
55
54
  return false if multiple?
56
-
55
+
57
56
  if states.key?(:format_enabled)
58
57
  states[:format_enabled]
59
58
  else
60
- !format.format_base.blank? || format.has_format?
59
+ !blank_value?(format.format_base) || format.has_format?
61
60
  end
62
61
  end
63
-
62
+
64
63
  def type_of?(type_name)
65
64
  type_name == :tblock || super
66
65
  end
67
-
66
+
68
67
  private
69
-
68
+
70
69
  def formatter
71
70
  @formatter ||= TextBlock::Formatter.setup(format)
72
71
  end
73
72
  end
74
-
73
+
75
74
  end
76
- end
75
+ end