goldendocx 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +47 -0
  4. data/CHANGELOG.md +43 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +101 -0
  7. data/README.md +76 -0
  8. data/Rakefile +10 -0
  9. data/coverage/.last_run.json +5 -0
  10. data/demo/charts/create_bar_chart.rb +30 -0
  11. data/demo/charts/create_column_chart.rb +29 -0
  12. data/demo/charts/create_doughnut_chart.rb +28 -0
  13. data/demo/charts/create_line_chart.rb +41 -0
  14. data/demo/images/append_image.rb +21 -0
  15. data/demo/images/append_styled_image.rb +14 -0
  16. data/demo/tables/create_embed_image_table.rb +42 -0
  17. data/demo/tables/create_plain_table.rb +22 -0
  18. data/demo/tables/create_styled_table.rb +36 -0
  19. data/demo/templates/bg.png +0 -0
  20. data/demo/templates/blankDocument.docx +0 -0
  21. data/demo/templates/image_base64 +1 -0
  22. data/demo/templates/styles/reportLabel +19 -0
  23. data/demo/templates/styles/reportSubTitle +20 -0
  24. data/demo/templates/styles/reportTable +27 -0
  25. data/demo/templates/styles/reportTitle +19 -0
  26. data/demo/texts/append_plain_text.rb +13 -0
  27. data/demo/texts/append_styled_text.rb +23 -0
  28. data/lib/goldendocx/charts/category_axis.rb +20 -0
  29. data/lib/goldendocx/charts/properties/auto_title_deleted_property.rb +16 -0
  30. data/lib/goldendocx/charts/properties/axis_property.rb +16 -0
  31. data/lib/goldendocx/charts/properties/bar_chart_property.rb +28 -0
  32. data/lib/goldendocx/charts/properties/chart_property.rb +16 -0
  33. data/lib/goldendocx/charts/properties/column_chart_property.rb +28 -0
  34. data/lib/goldendocx/charts/properties/cross_axis_property.rb +16 -0
  35. data/lib/goldendocx/charts/properties/data_lables_property.rb +16 -0
  36. data/lib/goldendocx/charts/properties/direction_property.rb +16 -0
  37. data/lib/goldendocx/charts/properties/doughnut_chart_property.rb +17 -0
  38. data/lib/goldendocx/charts/properties/grouping_property.rb +16 -0
  39. data/lib/goldendocx/charts/properties/hole_property.rb +16 -0
  40. data/lib/goldendocx/charts/properties/index_property.rb +16 -0
  41. data/lib/goldendocx/charts/properties/label_hidden_property.rb +16 -0
  42. data/lib/goldendocx/charts/properties/layout_property.rb +14 -0
  43. data/lib/goldendocx/charts/properties/line_chart_property.rb +24 -0
  44. data/lib/goldendocx/charts/properties/marker_property.rb +16 -0
  45. data/lib/goldendocx/charts/properties/number_list_property.rb +17 -0
  46. data/lib/goldendocx/charts/properties/order_property.rb +16 -0
  47. data/lib/goldendocx/charts/properties/plot_area_property.rb +23 -0
  48. data/lib/goldendocx/charts/properties/point_count_property.rb +16 -0
  49. data/lib/goldendocx/charts/properties/point_property.rb +18 -0
  50. data/lib/goldendocx/charts/properties/rounded_corner_property.rb +16 -0
  51. data/lib/goldendocx/charts/properties/series_category_property.rb +16 -0
  52. data/lib/goldendocx/charts/properties/series_text_property.rb +16 -0
  53. data/lib/goldendocx/charts/properties/series_value_property.rb +16 -0
  54. data/lib/goldendocx/charts/properties/smooth_property.rb +14 -0
  55. data/lib/goldendocx/charts/properties/string_list_property.rb +17 -0
  56. data/lib/goldendocx/charts/properties/symbol_property.rb +16 -0
  57. data/lib/goldendocx/charts/properties/text_value_property.rb +16 -0
  58. data/lib/goldendocx/charts/properties.rb +12 -0
  59. data/lib/goldendocx/charts/reference.rb +16 -0
  60. data/lib/goldendocx/charts/series.rb +57 -0
  61. data/lib/goldendocx/charts/value_axis.rb +20 -0
  62. data/lib/goldendocx/charts.rb +26 -0
  63. data/lib/goldendocx/components/bar_chart.rb +17 -0
  64. data/lib/goldendocx/components/chart.rb +55 -0
  65. data/lib/goldendocx/components/column_chart.rb +17 -0
  66. data/lib/goldendocx/components/doughnut_chart.rb +17 -0
  67. data/lib/goldendocx/components/image.rb +77 -0
  68. data/lib/goldendocx/components/line_chart.rb +17 -0
  69. data/lib/goldendocx/components/paragraph.rb +23 -0
  70. data/lib/goldendocx/components/properties/align_property.rb +16 -0
  71. data/lib/goldendocx/components/properties/bold_property.rb +16 -0
  72. data/lib/goldendocx/components/properties/color_property.rb +16 -0
  73. data/lib/goldendocx/components/properties/drawing.rb +16 -0
  74. data/lib/goldendocx/components/properties/extents_property.rb +17 -0
  75. data/lib/goldendocx/components/properties/graphic_data_property.rb +17 -0
  76. data/lib/goldendocx/components/properties/graphic_frame_locks_property.rb +18 -0
  77. data/lib/goldendocx/components/properties/graphic_frame_property.rb +16 -0
  78. data/lib/goldendocx/components/properties/graphic_property.rb +16 -0
  79. data/lib/goldendocx/components/properties/inline.rb +20 -0
  80. data/lib/goldendocx/components/properties/non_visual_property.rb +17 -0
  81. data/lib/goldendocx/components/properties/padding_property.rb +19 -0
  82. data/lib/goldendocx/components/properties/property.rb +17 -0
  83. data/lib/goldendocx/components/properties/run.rb +20 -0
  84. data/lib/goldendocx/components/properties/run_property.rb +17 -0
  85. data/lib/goldendocx/components/properties/style_property.rb +16 -0
  86. data/lib/goldendocx/components/properties/textual.rb +16 -0
  87. data/lib/goldendocx/components/properties.rb +12 -0
  88. data/lib/goldendocx/components/table.rb +44 -0
  89. data/lib/goldendocx/components/text.rb +35 -0
  90. data/lib/goldendocx/components.rb +16 -0
  91. data/lib/goldendocx/configuration.rb +18 -0
  92. data/lib/goldendocx/content_types/default.rb +22 -0
  93. data/lib/goldendocx/content_types/override.rb +22 -0
  94. data/lib/goldendocx/document.rb +51 -0
  95. data/lib/goldendocx/documents/body.rb +90 -0
  96. data/lib/goldendocx/documents/document.rb +29 -0
  97. data/lib/goldendocx/documents/element.rb +23 -0
  98. data/lib/goldendocx/documents/relationship.rb +17 -0
  99. data/lib/goldendocx/documents/relationships.rb +39 -0
  100. data/lib/goldendocx/documents/style.rb +21 -0
  101. data/lib/goldendocx/documents/styles.rb +74 -0
  102. data/lib/goldendocx/documents/unparsed_style.rb +17 -0
  103. data/lib/goldendocx/documents.rb +10 -0
  104. data/lib/goldendocx/docx.rb +108 -0
  105. data/lib/goldendocx/element.rb +192 -0
  106. data/lib/goldendocx/images/picture.rb +41 -0
  107. data/lib/goldendocx/images/properties/blip_property.rb +16 -0
  108. data/lib/goldendocx/images/properties/drawing_property.rb +14 -0
  109. data/lib/goldendocx/images/properties/extents_property.rb +17 -0
  110. data/lib/goldendocx/images/properties/fill_rectangle_property.rb +14 -0
  111. data/lib/goldendocx/images/properties/image_data_property.rb +17 -0
  112. data/lib/goldendocx/images/properties/non_visual_drawing_property.rb +17 -0
  113. data/lib/goldendocx/images/properties/non_visual_picture_property.rb +17 -0
  114. data/lib/goldendocx/images/properties/picture_fill_property.rb +17 -0
  115. data/lib/goldendocx/images/properties/picture_shape_property.rb +16 -0
  116. data/lib/goldendocx/images/properties/shape_property.rb +30 -0
  117. data/lib/goldendocx/images/properties/stretch_property.rb +17 -0
  118. data/lib/goldendocx/images/properties/transform_property.rb +16 -0
  119. data/lib/goldendocx/images/properties.rb +12 -0
  120. data/lib/goldendocx/images/shape.rb +32 -0
  121. data/lib/goldendocx/images.rb +12 -0
  122. data/lib/goldendocx/parts/content_types.rb +63 -0
  123. data/lib/goldendocx/parts/documents.rb +103 -0
  124. data/lib/goldendocx/parts/media.rb +43 -0
  125. data/lib/goldendocx/parts.rb +10 -0
  126. data/lib/goldendocx/tables/cell.rb +33 -0
  127. data/lib/goldendocx/tables/header_cell.rb +16 -0
  128. data/lib/goldendocx/tables/header_row.rb +14 -0
  129. data/lib/goldendocx/tables/image_cell.rb +23 -0
  130. data/lib/goldendocx/tables/properties/cell_property.rb +19 -0
  131. data/lib/goldendocx/tables/properties/cell_width_property.rb +17 -0
  132. data/lib/goldendocx/tables/properties/grid_column_property.rb +16 -0
  133. data/lib/goldendocx/tables/properties/grid_property.rb +16 -0
  134. data/lib/goldendocx/tables/properties/grid_span_property.rb +16 -0
  135. data/lib/goldendocx/tables/properties/header_row_property.rb +14 -0
  136. data/lib/goldendocx/tables/properties/property.rb +17 -0
  137. data/lib/goldendocx/tables/properties/row_height_property.rb +17 -0
  138. data/lib/goldendocx/tables/properties/row_property.rb +16 -0
  139. data/lib/goldendocx/tables/properties/shading_property.rb +18 -0
  140. data/lib/goldendocx/tables/properties/style_property.rb +16 -0
  141. data/lib/goldendocx/tables/properties/vertical_align_property.rb +16 -0
  142. data/lib/goldendocx/tables/properties/width_property.rb +17 -0
  143. data/lib/goldendocx/tables/properties.rb +12 -0
  144. data/lib/goldendocx/tables/row.rb +28 -0
  145. data/lib/goldendocx/tables.rb +19 -0
  146. data/lib/goldendocx/units.rb +11 -0
  147. data/lib/goldendocx/version.rb +5 -0
  148. data/lib/goldendocx/xml_serializers/nokogiri.rb +66 -0
  149. data/lib/goldendocx/xml_serializers/ox.rb +63 -0
  150. data/lib/goldendocx.rb +72 -0
  151. data/sig/goldendocx.rbs +4 -0
  152. metadata +347 -0
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class LayoutProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :layout
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class LineChartProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :lineChart
11
+
12
+ embeds_one :grouping, class_name: 'Goldendocx::Charts::Properties::GroupingProperty', auto_build: true
13
+
14
+ embeds_many :axes, class_name: 'Goldendocx::Charts::Properties::AxisProperty'
15
+ embeds_many :series, class_name: 'Goldendocx::Charts::Series'
16
+
17
+ def initialize
18
+ build_axis(axis_id: 9374902)
19
+ build_axis(axis_id: 2094739)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class MarkerProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :marker
11
+
12
+ embeds_one :symbol, class_name: 'Goldendocx::Charts::Properties::SymbolProperty', auto_build: true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class NumberListProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :numLit
11
+
12
+ embeds_one :count, class_name: 'Goldendocx::Charts::Properties::PointCountProperty', auto_build: true
13
+ embeds_many :points, class_name: 'Goldendocx::Charts::Properties::PointProperty'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class OrderProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :order
11
+
12
+ attribute :order, alias_name: :val
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class PlotAreaProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :plotArea
11
+
12
+ embeds_one :layout, class_name: 'Goldendocx::Charts::Properties::LayoutProperty', auto_build: true
13
+ embeds_one :category_axis, class_name: 'Goldendocx::Charts::CategoryAxis', auto_build: true
14
+ embeds_one :value_axis, class_name: 'Goldendocx::Charts::ValueAxis', auto_build: true
15
+
16
+ embeds_one :line_chart, class_name: 'Goldendocx::Charts::Properties::LineChartProperty', auto_build: false
17
+ embeds_one :bar_chart, class_name: 'Goldendocx::Charts::Properties::BarChartProperty', auto_build: false
18
+ embeds_one :column_chart, class_name: 'Goldendocx::Charts::Properties::ColumnChartProperty', auto_build: false
19
+ embeds_one :doughnut_chart, class_name: 'Goldendocx::Charts::Properties::DoughnutChartProperty', auto_build: false
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class PointCountProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :ptCount
11
+
12
+ attribute :count, alias_name: :val
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class PointProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :pt
11
+
12
+ attribute :index, alias_name: :idx
13
+
14
+ embeds_one :value, class_name: 'Goldendocx::Charts::Properties::TextValueProperty'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class RoundedCornerProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :roundedCorner
11
+
12
+ attribute :enabled, alias_name: :val, default: true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class SeriesCategoryProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :cat
11
+
12
+ embeds_one :values, class_name: 'Goldendocx::Charts::Properties::StringListProperty', auto_build: true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class SeriesTextProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :tx
11
+
12
+ embeds_one :value, class_name: 'Goldendocx::Charts::Properties::TextValueProperty', auto_build: true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class SeriesValueProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :val
11
+
12
+ embeds_one :values, class_name: 'Goldendocx::Charts::Properties::NumberListProperty', auto_build: true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class SmoothProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :smooth
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class StringListProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :strLit
11
+
12
+ embeds_one :count, class_name: 'Goldendocx::Charts::Properties::PointCountProperty', auto_build: true
13
+ embeds_many :points, class_name: 'Goldendocx::Charts::Properties::PointProperty'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class SymbolProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :symbol
11
+
12
+ attribute :type, alias_name: :val, default: :dot
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class TextValueProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :v
11
+
12
+ embeds_one :value, class_name: 'String'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ end
7
+ end
8
+ end
9
+
10
+ Dir.glob(File.join(File.dirname(__FILE__), 'properties', '*.rb').to_s).sort.each do |file|
11
+ require file
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ module Properties
6
+ class Reference
7
+ include Goldendocx::Element
8
+
9
+ namespace :c
10
+ tag :chart
11
+
12
+ attribute :relationship_id, alias_name: :id, namespace: :r
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ class Series
6
+ include Goldendocx::Element
7
+
8
+ namespace :c
9
+ tag :ser
10
+
11
+ embeds_one :index, class_name: 'Goldendocx::Charts::Properties::IndexProperty', auto_build: true
12
+ embeds_one :order, class_name: 'Goldendocx::Charts::Properties::OrderProperty', auto_build: true
13
+ embeds_one :smooth, class_name: 'Goldendocx::Charts::Properties::SmoothProperty', auto_build: true
14
+ embeds_one :marker, class_name: 'Goldendocx::Charts::Properties::MarkerProperty', auto_build: true
15
+ embeds_one :text, class_name: 'Goldendocx::Charts::Properties::SeriesTextProperty', auto_build: true
16
+ embeds_one :labels_property, class_name: 'Goldendocx::Charts::Properties::DataLabelsProperty', auto_build: true
17
+
18
+ embeds_one :category_axis, class_name: 'Goldendocx::Charts::Properties::SeriesCategoryProperty', auto_build: true
19
+ embeds_one :value_axis, class_name: 'Goldendocx::Charts::Properties::SeriesValueProperty', auto_build: true
20
+
21
+ def initialize(**attributes)
22
+ attributes.each do |name, value|
23
+ send("#{name}=", value) if respond_to?("#{name}=")
24
+ end
25
+ end
26
+
27
+ def categories=(categories)
28
+ category_axis.values.build_count(count: categories.size)
29
+ categories.each_with_index do |cat, index|
30
+ point = category_axis.values.build_point(index: index)
31
+ point.build_value(value: cat)
32
+ end
33
+ end
34
+
35
+ def values=(values)
36
+ value_axis.values.build_count(count: values.size)
37
+ values.each_with_index do |val, index|
38
+ point = value_axis.values.build_point(index: index)
39
+ point.build_value(value: val)
40
+ end
41
+ end
42
+
43
+ def id=(id)
44
+ return unless id
45
+
46
+ index.index = id
47
+ order.order = id
48
+ end
49
+
50
+ def name=(name)
51
+ return unless name
52
+
53
+ text.value.value = name
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ class ValueAxis
6
+ include Goldendocx::Element
7
+
8
+ namespace :c
9
+ tag :valAx
10
+
11
+ embeds_one :axis_id, class_name: 'Goldendocx::Charts::Properties::AxisProperty', auto_build: true
12
+ embeds_one :cross_axis, class_name: 'Goldendocx::Charts::Properties::CrossAxisProperty', auto_build: true
13
+
14
+ def initialize
15
+ build_axis_id(axis_id: 2094739)
16
+ build_cross_axis(axis_id: 9374902)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Charts
5
+ CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml'
6
+ PART_NAME_PATTERN = '/word/charts/chart%<id>s.xml'
7
+
8
+ RELATIONSHIP_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart'
9
+ RELATIONSHIP_NAME_PATTERN = 'charts/chart%<id>s.xml'
10
+
11
+ DEFAULT_WIDTH = Goldendocx::Units::EMU_PER_CENTIMETER * 16
12
+ DEFAULT_HEIGHT = Goldendocx::Units::EMU_PER_CENTIMETER * 10
13
+
14
+ class InvalidChartType < StandardError
15
+ def initialize
16
+ super('Invalid chart type, supported types are [ line, bar, column, doughnut ]')
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ require 'goldendocx/charts/properties'
23
+
24
+ Dir.glob(File.join(File.dirname(__FILE__), 'charts', '*.rb').to_s).sort.each do |file|
25
+ require file
26
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Components
5
+ class BarChart < Chart
6
+ def initialize(chart_id, relationship_id, **attributes)
7
+ super(chart_id, relationship_id, **attributes)
8
+
9
+ build_chart.plot_area.build_bar_chart
10
+ end
11
+
12
+ def the_chart
13
+ chart.plot_area.bar_chart
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'goldendocx/charts'
4
+
5
+ # It is weired because this will generate two parts of XMLs
6
+ module Goldendocx
7
+ module Components
8
+ class Chart
9
+ include Goldendocx::Document
10
+
11
+ namespace :c
12
+ tag :chartSpace
13
+ concern_namespaces :c, :a, :r, :mc, :c14
14
+
15
+ embeds_one :rounded_corner, class_name: 'Goldendocx::Charts::Properties::RoundedCornerProperty', auto_build: true
16
+ embeds_one :chart, class_name: 'Goldendocx::Charts::Properties::ChartProperty', auto_build: true
17
+
18
+ attr_accessor :name
19
+ attr_reader :id, :series
20
+
21
+ def initialize(chart_id, relationship_id, **attributes)
22
+ @id = chart_id
23
+ @series = []
24
+
25
+ @paragraph = Goldendocx::Components::Paragraph.new
26
+ inline_drawing = @paragraph.build_run.build_drawing.build_inline
27
+ inline_drawing.build_non_visual_property(relationship_id: relationship_id)
28
+ inline_drawing.build_extents(width: attributes[:width], height: attributes[:height])
29
+ inline_drawing.build_graphic.build_data.build_chart(relationship_id: relationship_id)
30
+ end
31
+
32
+ def add_series(name, categories, values)
33
+ ser_id = series.size + 1
34
+ the_chart.build_series(categories: categories, values: values, id: ser_id, name: name)
35
+ ser = Goldendocx::Charts::Series.new(categories: categories, values: values, id: ser_id, name: name)
36
+ series << ser
37
+ ser
38
+ end
39
+
40
+ def to_xml
41
+ @paragraph.to_xml
42
+ end
43
+
44
+ def to_element(**context)
45
+ @paragraph.to_element(**context)
46
+ end
47
+
48
+ def write_to(zos)
49
+ entry_name = format(Goldendocx::Charts::RELATIONSHIP_NAME_PATTERN, id: id)
50
+ zos.put_next_entry "word/#{entry_name}"
51
+ zos.write to_document_xml
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Components
5
+ class ColumnChart < Chart
6
+ def initialize(chart_id, relationship_id, **attributes)
7
+ super(chart_id, relationship_id, **attributes)
8
+
9
+ build_chart.plot_area.build_column_chart
10
+ end
11
+
12
+ def the_chart
13
+ chart.plot_area.column_chart
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Components
5
+ class DoughnutChart < Chart
6
+ def initialize(chart_id, relationship_id, **attributes)
7
+ super(chart_id, relationship_id, **attributes)
8
+
9
+ build_chart.plot_area.build_doughnut_chart
10
+ end
11
+
12
+ def the_chart
13
+ chart.plot_area.doughnut_chart
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'goldendocx/images'
4
+
5
+ module Goldendocx
6
+ module Components
7
+ class Image
8
+ include Goldendocx::Element
9
+
10
+ namespace :w
11
+ tag :p
12
+
13
+ embeds_one :property, class_name: 'Goldendocx::Components::Properties::Property', auto_build: true
14
+ embeds_many :runs, class_name: 'Goldendocx::Components::Properties::Run'
15
+
16
+ attr_reader :type, :container, :relationship_id, :width, :height
17
+
18
+ def initialize(type: :shape, **attributes)
19
+ @type = type
20
+ @container = build_run
21
+
22
+ case type
23
+ when :picture
24
+ inline_drawing = @container.build_drawing.build_inline
25
+ inline_drawing.build_non_visual_property
26
+ inline_drawing.build_extents
27
+ inline_drawing.build_graphic.build_data.build_picture
28
+ else
29
+ @container.build_shape
30
+ end
31
+
32
+ attributes.each do |name, value|
33
+ send("#{name}=", value) if respond_to?("#{name}=")
34
+ end
35
+ end
36
+
37
+ def relationship_id=(relationship_id)
38
+ return unless relationship_id
39
+
40
+ @relationship_id = relationship_id
41
+ case type
42
+ when :picture
43
+ container.drawing.inline.non_visual_property.relationship_id = relationship_id
44
+ container.drawing.inline.graphic.data.picture.relationship_id = relationship_id
45
+ else
46
+ container.shape.relationship_id = relationship_id
47
+ end
48
+ end
49
+
50
+ def width=(width)
51
+ return unless width
52
+
53
+ @width = width
54
+ case type
55
+ when :picture
56
+ container.drawing.inline.extents.width = width
57
+ container.drawing.inline.graphic.data.picture.width = width
58
+ else
59
+ container.shape.width = width
60
+ end
61
+ end
62
+
63
+ def height=(height)
64
+ return unless height
65
+
66
+ @height = height
67
+ case type
68
+ when :picture
69
+ container.drawing.inline.extents.height = height
70
+ container.drawing.inline.graphic.data.picture.height = height
71
+ else
72
+ container.shape.height = height
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Components
5
+ class LineChart < Chart
6
+ def initialize(chart_id, relationship_id, **attributes)
7
+ super(chart_id, relationship_id, **attributes)
8
+
9
+ build_chart.plot_area.build_line_chart
10
+ end
11
+
12
+ def the_chart
13
+ chart.plot_area.line_chart
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Components
5
+ class Paragraph
6
+ include Goldendocx::Element
7
+
8
+ namespace :w
9
+ tag :p
10
+
11
+ embeds_one :property, class_name: 'Goldendocx::Components::Properties::Property', auto_build: true
12
+ embeds_many :runs, class_name: 'Goldendocx::Components::Properties::Run'
13
+
14
+ def align=(align)
15
+ property.align.align = align if align
16
+ end
17
+
18
+ def style=(style)
19
+ property.style.style_id = style if style
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Goldendocx
4
+ module Components
5
+ module Properties
6
+ class AlignProperty
7
+ include Goldendocx::Element
8
+
9
+ namespace :w
10
+ tag :jc
11
+
12
+ attribute :align, alias_name: :val, namespace: :w
13
+ end
14
+ end
15
+ end
16
+ end