goldendocx 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +47 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +101 -0
- data/README.md +76 -0
- data/Rakefile +10 -0
- data/coverage/.last_run.json +5 -0
- data/demo/charts/create_bar_chart.rb +30 -0
- data/demo/charts/create_column_chart.rb +29 -0
- data/demo/charts/create_doughnut_chart.rb +28 -0
- data/demo/charts/create_line_chart.rb +41 -0
- data/demo/images/append_image.rb +21 -0
- data/demo/images/append_styled_image.rb +14 -0
- data/demo/tables/create_embed_image_table.rb +42 -0
- data/demo/tables/create_plain_table.rb +22 -0
- data/demo/tables/create_styled_table.rb +36 -0
- data/demo/templates/bg.png +0 -0
- data/demo/templates/blankDocument.docx +0 -0
- data/demo/templates/image_base64 +1 -0
- data/demo/templates/styles/reportLabel +19 -0
- data/demo/templates/styles/reportSubTitle +20 -0
- data/demo/templates/styles/reportTable +27 -0
- data/demo/templates/styles/reportTitle +19 -0
- data/demo/texts/append_plain_text.rb +13 -0
- data/demo/texts/append_styled_text.rb +23 -0
- data/lib/goldendocx/charts/category_axis.rb +20 -0
- data/lib/goldendocx/charts/properties/auto_title_deleted_property.rb +16 -0
- data/lib/goldendocx/charts/properties/axis_property.rb +16 -0
- data/lib/goldendocx/charts/properties/bar_chart_property.rb +28 -0
- data/lib/goldendocx/charts/properties/chart_property.rb +16 -0
- data/lib/goldendocx/charts/properties/column_chart_property.rb +28 -0
- data/lib/goldendocx/charts/properties/cross_axis_property.rb +16 -0
- data/lib/goldendocx/charts/properties/data_lables_property.rb +16 -0
- data/lib/goldendocx/charts/properties/direction_property.rb +16 -0
- data/lib/goldendocx/charts/properties/doughnut_chart_property.rb +17 -0
- data/lib/goldendocx/charts/properties/grouping_property.rb +16 -0
- data/lib/goldendocx/charts/properties/hole_property.rb +16 -0
- data/lib/goldendocx/charts/properties/index_property.rb +16 -0
- data/lib/goldendocx/charts/properties/label_hidden_property.rb +16 -0
- data/lib/goldendocx/charts/properties/layout_property.rb +14 -0
- data/lib/goldendocx/charts/properties/line_chart_property.rb +24 -0
- data/lib/goldendocx/charts/properties/marker_property.rb +16 -0
- data/lib/goldendocx/charts/properties/number_list_property.rb +17 -0
- data/lib/goldendocx/charts/properties/order_property.rb +16 -0
- data/lib/goldendocx/charts/properties/plot_area_property.rb +23 -0
- data/lib/goldendocx/charts/properties/point_count_property.rb +16 -0
- data/lib/goldendocx/charts/properties/point_property.rb +18 -0
- data/lib/goldendocx/charts/properties/rounded_corner_property.rb +16 -0
- data/lib/goldendocx/charts/properties/series_category_property.rb +16 -0
- data/lib/goldendocx/charts/properties/series_text_property.rb +16 -0
- data/lib/goldendocx/charts/properties/series_value_property.rb +16 -0
- data/lib/goldendocx/charts/properties/smooth_property.rb +14 -0
- data/lib/goldendocx/charts/properties/string_list_property.rb +17 -0
- data/lib/goldendocx/charts/properties/symbol_property.rb +16 -0
- data/lib/goldendocx/charts/properties/text_value_property.rb +16 -0
- data/lib/goldendocx/charts/properties.rb +12 -0
- data/lib/goldendocx/charts/reference.rb +16 -0
- data/lib/goldendocx/charts/series.rb +57 -0
- data/lib/goldendocx/charts/value_axis.rb +20 -0
- data/lib/goldendocx/charts.rb +26 -0
- data/lib/goldendocx/components/bar_chart.rb +17 -0
- data/lib/goldendocx/components/chart.rb +55 -0
- data/lib/goldendocx/components/column_chart.rb +17 -0
- data/lib/goldendocx/components/doughnut_chart.rb +17 -0
- data/lib/goldendocx/components/image.rb +77 -0
- data/lib/goldendocx/components/line_chart.rb +17 -0
- data/lib/goldendocx/components/paragraph.rb +23 -0
- data/lib/goldendocx/components/properties/align_property.rb +16 -0
- data/lib/goldendocx/components/properties/bold_property.rb +16 -0
- data/lib/goldendocx/components/properties/color_property.rb +16 -0
- data/lib/goldendocx/components/properties/drawing.rb +16 -0
- data/lib/goldendocx/components/properties/extents_property.rb +17 -0
- data/lib/goldendocx/components/properties/graphic_data_property.rb +17 -0
- data/lib/goldendocx/components/properties/graphic_frame_locks_property.rb +18 -0
- data/lib/goldendocx/components/properties/graphic_frame_property.rb +16 -0
- data/lib/goldendocx/components/properties/graphic_property.rb +16 -0
- data/lib/goldendocx/components/properties/inline.rb +20 -0
- data/lib/goldendocx/components/properties/non_visual_property.rb +17 -0
- data/lib/goldendocx/components/properties/padding_property.rb +19 -0
- data/lib/goldendocx/components/properties/property.rb +17 -0
- data/lib/goldendocx/components/properties/run.rb +20 -0
- data/lib/goldendocx/components/properties/run_property.rb +17 -0
- data/lib/goldendocx/components/properties/style_property.rb +16 -0
- data/lib/goldendocx/components/properties/textual.rb +16 -0
- data/lib/goldendocx/components/properties.rb +12 -0
- data/lib/goldendocx/components/table.rb +44 -0
- data/lib/goldendocx/components/text.rb +35 -0
- data/lib/goldendocx/components.rb +16 -0
- data/lib/goldendocx/configuration.rb +18 -0
- data/lib/goldendocx/content_types/default.rb +22 -0
- data/lib/goldendocx/content_types/override.rb +22 -0
- data/lib/goldendocx/document.rb +51 -0
- data/lib/goldendocx/documents/body.rb +90 -0
- data/lib/goldendocx/documents/document.rb +29 -0
- data/lib/goldendocx/documents/element.rb +23 -0
- data/lib/goldendocx/documents/relationship.rb +17 -0
- data/lib/goldendocx/documents/relationships.rb +39 -0
- data/lib/goldendocx/documents/style.rb +21 -0
- data/lib/goldendocx/documents/styles.rb +74 -0
- data/lib/goldendocx/documents/unparsed_style.rb +17 -0
- data/lib/goldendocx/documents.rb +10 -0
- data/lib/goldendocx/docx.rb +108 -0
- data/lib/goldendocx/element.rb +192 -0
- data/lib/goldendocx/images/picture.rb +41 -0
- data/lib/goldendocx/images/properties/blip_property.rb +16 -0
- data/lib/goldendocx/images/properties/drawing_property.rb +14 -0
- data/lib/goldendocx/images/properties/extents_property.rb +17 -0
- data/lib/goldendocx/images/properties/fill_rectangle_property.rb +14 -0
- data/lib/goldendocx/images/properties/image_data_property.rb +17 -0
- data/lib/goldendocx/images/properties/non_visual_drawing_property.rb +17 -0
- data/lib/goldendocx/images/properties/non_visual_picture_property.rb +17 -0
- data/lib/goldendocx/images/properties/picture_fill_property.rb +17 -0
- data/lib/goldendocx/images/properties/picture_shape_property.rb +16 -0
- data/lib/goldendocx/images/properties/shape_property.rb +30 -0
- data/lib/goldendocx/images/properties/stretch_property.rb +17 -0
- data/lib/goldendocx/images/properties/transform_property.rb +16 -0
- data/lib/goldendocx/images/properties.rb +12 -0
- data/lib/goldendocx/images/shape.rb +32 -0
- data/lib/goldendocx/images.rb +12 -0
- data/lib/goldendocx/parts/content_types.rb +63 -0
- data/lib/goldendocx/parts/documents.rb +103 -0
- data/lib/goldendocx/parts/media.rb +43 -0
- data/lib/goldendocx/parts.rb +10 -0
- data/lib/goldendocx/tables/cell.rb +33 -0
- data/lib/goldendocx/tables/header_cell.rb +16 -0
- data/lib/goldendocx/tables/header_row.rb +14 -0
- data/lib/goldendocx/tables/image_cell.rb +23 -0
- data/lib/goldendocx/tables/properties/cell_property.rb +19 -0
- data/lib/goldendocx/tables/properties/cell_width_property.rb +17 -0
- data/lib/goldendocx/tables/properties/grid_column_property.rb +16 -0
- data/lib/goldendocx/tables/properties/grid_property.rb +16 -0
- data/lib/goldendocx/tables/properties/grid_span_property.rb +16 -0
- data/lib/goldendocx/tables/properties/header_row_property.rb +14 -0
- data/lib/goldendocx/tables/properties/property.rb +17 -0
- data/lib/goldendocx/tables/properties/row_height_property.rb +17 -0
- data/lib/goldendocx/tables/properties/row_property.rb +16 -0
- data/lib/goldendocx/tables/properties/shading_property.rb +18 -0
- data/lib/goldendocx/tables/properties/style_property.rb +16 -0
- data/lib/goldendocx/tables/properties/vertical_align_property.rb +16 -0
- data/lib/goldendocx/tables/properties/width_property.rb +17 -0
- data/lib/goldendocx/tables/properties.rb +12 -0
- data/lib/goldendocx/tables/row.rb +28 -0
- data/lib/goldendocx/tables.rb +19 -0
- data/lib/goldendocx/units.rb +11 -0
- data/lib/goldendocx/version.rb +5 -0
- data/lib/goldendocx/xml_serializers/nokogiri.rb +66 -0
- data/lib/goldendocx/xml_serializers/ox.rb +63 -0
- data/lib/goldendocx.rb +72 -0
- data/sig/goldendocx.rbs +4 -0
- metadata +347 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Images
|
5
|
+
module Properties
|
6
|
+
class ShapeProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
# 1 : 0.618
|
10
|
+
DEFAULT_SHAPE_WIDTH = Goldendocx::Units::EMU_PER_CENTIMETER * 15
|
11
|
+
DEFAULT_SHAPE_HEIGHT = Goldendocx::Units::EMU_PER_CENTIMETER * 9.27
|
12
|
+
|
13
|
+
attr_accessor :width, :height
|
14
|
+
|
15
|
+
namespace :v
|
16
|
+
tag :shape
|
17
|
+
|
18
|
+
attribute :style, method: :formatted_style
|
19
|
+
|
20
|
+
embeds_one :image_data, class_name: 'Goldendocx::Images::Properties::ImageDataProperty', auto_build: true
|
21
|
+
|
22
|
+
def formatted_style
|
23
|
+
height = ((self.height || DEFAULT_SHAPE_HEIGHT) / Goldendocx::Units::EMU_PER_CENTIMETER).round(2)
|
24
|
+
width = ((self.width || DEFAULT_SHAPE_WIDTH) / Goldendocx::Units::EMU_PER_CENTIMETER).round(2)
|
25
|
+
"height:#{height}cm;width:#{width}cm"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Images
|
5
|
+
module Properties
|
6
|
+
class StretchProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :a
|
10
|
+
tag :stretch
|
11
|
+
|
12
|
+
embeds_one :fill_rectangle, class_name: 'Goldendocx::Images::Properties::FillRectangleProperty',
|
13
|
+
auto_build: true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Images
|
5
|
+
module Properties
|
6
|
+
class TransformProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :a
|
10
|
+
tag :xfrm
|
11
|
+
|
12
|
+
embeds_one :extents, class_name: 'Goldendocx::Images::Properties::ExtentsProperty', auto_build: true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Images
|
5
|
+
class Shape
|
6
|
+
include Goldendocx::Element
|
7
|
+
|
8
|
+
namespace :w
|
9
|
+
tag :pict
|
10
|
+
|
11
|
+
embeds_one :property, class_name: 'Goldendocx::Images::Properties::ShapeProperty', auto_build: true
|
12
|
+
|
13
|
+
def initialize(**attributes)
|
14
|
+
attributes.each do |name, value|
|
15
|
+
send("#{name}=", value) if respond_to?("#{name}=")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def width=(width)
|
20
|
+
property.width = width if width
|
21
|
+
end
|
22
|
+
|
23
|
+
def height=(height)
|
24
|
+
property.height = height if height
|
25
|
+
end
|
26
|
+
|
27
|
+
def relationship_id=(relationship_id)
|
28
|
+
property.image_data.relationship_id = relationship_id if relationship_id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'goldendocx/content_types/default'
|
4
|
+
require 'goldendocx/content_types/override'
|
5
|
+
|
6
|
+
module Goldendocx
|
7
|
+
module Parts
|
8
|
+
class ContentTypes
|
9
|
+
include Goldendocx::Document
|
10
|
+
|
11
|
+
XML_PATH = '[Content_Types].xml'
|
12
|
+
NAMESPACE = 'http://schemas.openxmlformats.org/package/2006/content-types'
|
13
|
+
|
14
|
+
attr_reader :defaults, :overrides
|
15
|
+
|
16
|
+
tag :Types
|
17
|
+
attribute :xmlns, default: NAMESPACE, readonly: true
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def read_from(docx_file)
|
21
|
+
content_types = Goldendocx::Parts::ContentTypes.new
|
22
|
+
content_types.read_defaults(docx_file)
|
23
|
+
content_types.read_overrides(docx_file)
|
24
|
+
content_types
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@defaults = []
|
30
|
+
@overrides = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_defaults(docx_file)
|
34
|
+
@defaults = Goldendocx.xml_serializer.parse(docx_file.read(XML_PATH), %w[Types Default]).map do |node|
|
35
|
+
Goldendocx::ContentTypes::Default.new(node[:Extension], node[:ContentType])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def read_overrides(docx_file)
|
40
|
+
@overrides = Goldendocx.xml_serializer.parse(docx_file.read(XML_PATH), %w[Types Override]).map do |node|
|
41
|
+
Goldendocx::ContentTypes::Override.new(node[:PartName], node[:ContentType])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_default(extension, content_type)
|
46
|
+
new_default = Goldendocx::ContentTypes::Default.new(extension, content_type)
|
47
|
+
defaults << new_default if defaults.none?(new_default)
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_override(part_name, content_type)
|
51
|
+
new_override = Goldendocx::ContentTypes::Override.new(part_name, content_type)
|
52
|
+
overrides << new_override if overrides.none?(new_override)
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_document_xml
|
56
|
+
super do |xml|
|
57
|
+
defaults.each { |default| xml << default }
|
58
|
+
overrides.each { |override| xml << override }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Parts hold entries at directory word/
|
4
|
+
module Goldendocx
|
5
|
+
module Parts
|
6
|
+
class Documents
|
7
|
+
XML_PATH = 'word/'
|
8
|
+
|
9
|
+
attr_reader :document, # document.xml
|
10
|
+
:styles, # styles.xml
|
11
|
+
:relationships, # _rels/document.xml.rels
|
12
|
+
:charts, # charts/
|
13
|
+
:medias # New Medias to media/
|
14
|
+
|
15
|
+
attr_accessor :media_amount # Entries amount in directory media/ for generating relationship id
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def read_from(docx_file)
|
19
|
+
parts = Goldendocx::Parts::Documents.new
|
20
|
+
parts.document.read_from(docx_file)
|
21
|
+
parts.styles.read_from(docx_file)
|
22
|
+
parts.relationships.read_from(docx_file)
|
23
|
+
parts.media_amount = docx_file.entries.count { |entry| entry.name.start_with?('word/media/') }
|
24
|
+
parts
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@document = Goldendocx::Documents::Document.new
|
30
|
+
@styles = Goldendocx::Documents::Styles.new
|
31
|
+
@relationships = Goldendocx::Documents::Relationships.new
|
32
|
+
@medias = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def write_stream(zos)
|
36
|
+
styles.write_to(zos)
|
37
|
+
relationships.write_to(zos)
|
38
|
+
document.write_to(zos)
|
39
|
+
medias.each { |media| media.write_to(zos) }
|
40
|
+
document.body.charts.each { |chart| chart.write_to(zos) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_text(text, options = {})
|
44
|
+
paragraph = document.body.create_text(text, options)
|
45
|
+
|
46
|
+
style = styles.find_text_style(options[:style])
|
47
|
+
paragraph.style = style.id if style
|
48
|
+
|
49
|
+
paragraph
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_table(options = {})
|
53
|
+
table = document.body.create_table(options)
|
54
|
+
|
55
|
+
style = styles.find_table_style(options[:style])
|
56
|
+
table.style = style.id if style
|
57
|
+
|
58
|
+
table
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_image(image_data, options = {})
|
62
|
+
image_media = add_image_media(image_data, options)
|
63
|
+
relationship_id = relationships.add_relationship(image_media.type, image_media.target)
|
64
|
+
|
65
|
+
document.body.create_image(relationship_id, options)
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_embed_image(image_data, options = {})
|
69
|
+
image_media = add_image_media(image_data, options)
|
70
|
+
relationship_id = relationships.add_relationship(image_media.type, image_media.target)
|
71
|
+
|
72
|
+
document.body.create_embed_image(relationship_id, options)
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_image_media(image_data, _options = {})
|
76
|
+
extension = 'png'
|
77
|
+
# Add to media
|
78
|
+
@media_amount += 1
|
79
|
+
image_name = "image#{media_amount}.#{extension}"
|
80
|
+
Goldendocx::Parts::Media.new(image_name, image_data).tap do |media|
|
81
|
+
medias << media
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_chart(chart_type, width, height)
|
86
|
+
document.body.ensure_chart_type(chart_type)
|
87
|
+
|
88
|
+
chart_id = document.body.charts.size + 1
|
89
|
+
|
90
|
+
relationship_id = relationships.add_relationship(
|
91
|
+
Goldendocx::Charts::RELATIONSHIP_TYPE,
|
92
|
+
format(Goldendocx::Charts::RELATIONSHIP_NAME_PATTERN, id: chart_id)
|
93
|
+
)
|
94
|
+
|
95
|
+
document.body.create_chart(chart_type, chart_id, relationship_id, width: width, height: height)
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_style(fragment)
|
99
|
+
styles.add_style(fragment)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A parts holds media
|
4
|
+
module Goldendocx
|
5
|
+
module Parts
|
6
|
+
class Media
|
7
|
+
BASE64_PNG_PATTERN = %r{
|
8
|
+
^data:image/png;base64,
|
9
|
+
(?<data>(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?)$
|
10
|
+
}x.freeze
|
11
|
+
|
12
|
+
def initialize(name, data)
|
13
|
+
@name = name
|
14
|
+
@data = data
|
15
|
+
end
|
16
|
+
|
17
|
+
def target
|
18
|
+
"media/#{@name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def type
|
22
|
+
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image'
|
23
|
+
end
|
24
|
+
|
25
|
+
def input_stream
|
26
|
+
return StringIO.new(BASE64_PNG_PATTERN.match(@data)['data'].unpack1('m'), 'rb') if base64_png_data?
|
27
|
+
|
28
|
+
@data
|
29
|
+
end
|
30
|
+
|
31
|
+
def write_to(zos)
|
32
|
+
zos.put_next_entry "word/#{target}"
|
33
|
+
zos.write input_stream.read
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def base64_png_data?
|
39
|
+
@data.is_a?(String) && @data.match?(BASE64_PNG_PATTERN)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
class Cell
|
6
|
+
include Goldendocx::Element
|
7
|
+
|
8
|
+
namespace :w
|
9
|
+
tag :tc
|
10
|
+
|
11
|
+
embeds_one :property, class_name: 'Goldendocx::Tables::Properties::CellProperty', auto_build: true
|
12
|
+
embeds_one :text, class_name: 'Goldendocx::Components::Text', auto_build: true
|
13
|
+
|
14
|
+
def initialize(**attributes)
|
15
|
+
attributes.each do |name, value|
|
16
|
+
send("#{name}=", value) if respond_to?("#{name}=")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def content=(content)
|
21
|
+
text.run.build_text.value = content.to_s if content
|
22
|
+
end
|
23
|
+
|
24
|
+
def align=(align)
|
25
|
+
text.property.align.align = align if align
|
26
|
+
end
|
27
|
+
|
28
|
+
def span=(span)
|
29
|
+
property.grid_span.span = span if span
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
class HeaderCell < Cell
|
6
|
+
def initialize(**attributes)
|
7
|
+
super
|
8
|
+
property.build_shading(value: :clear, color: :auto, fill: DEFAULT_BACKGROUND_COLOR)
|
9
|
+
end
|
10
|
+
|
11
|
+
def width=(width, type: :dxa)
|
12
|
+
property.width.assign_attributes(width: width, type: type)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
class HeaderRow < Row
|
6
|
+
include Goldendocx::Element
|
7
|
+
|
8
|
+
namespace :w
|
9
|
+
tag :tr
|
10
|
+
|
11
|
+
embeds_one :header_row, class_name: 'Goldendocx::Tables::Properties::HeaderRowProperty', auto_build: true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
class ImageCell < Cell
|
6
|
+
embeds_one :image, class_name: 'Goldendocx::Components::Image'
|
7
|
+
|
8
|
+
def image=(image)
|
9
|
+
build_image(
|
10
|
+
relationship_id: image.relationship_id,
|
11
|
+
width: image.width,
|
12
|
+
height: image.height
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def content=(content)
|
17
|
+
return unless content
|
18
|
+
|
19
|
+
image.build_run.build_text.value = content
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class CellProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :tcPr
|
11
|
+
|
12
|
+
embeds_one :width, class_name: 'Goldendocx::Tables::Properties::CellWidthProperty', auto_build: true
|
13
|
+
embeds_one :vertical_align, class_name: 'Goldendocx::Tables::Properties::VerticalAlignProperty', auto_build: true
|
14
|
+
embeds_one :grid_span, class_name: 'Goldendocx::Tables::Properties::GridSpanProperty', auto_build: true
|
15
|
+
embeds_one :shading, class_name: 'Goldendocx::Tables::Properties::ShadingProperty', auto_build: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class CellWidthProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :tcW
|
11
|
+
|
12
|
+
attribute :width, namespace: :w, alias_name: :w
|
13
|
+
attribute :type, namespace: :w, default: :auto
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class GridColumnProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :gridCol
|
11
|
+
|
12
|
+
attribute :width, alias_name: :w, namespace: :w, default: Goldendocx::Tables::DEFAULT_CELL_DXA_WIDTH
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class GridProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :tblGrid
|
11
|
+
|
12
|
+
embeds_many :grid_columns, class_name: 'Goldendocx::Tables::Properties::GridColumnProperty'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class GridSpanProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :gridSpan
|
11
|
+
|
12
|
+
attribute :span, alias_name: :val, namespace: :w
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class Property
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :tblPr
|
11
|
+
|
12
|
+
embeds_one :table_style, class_name: 'Goldendocx::Tables::Properties::StyleProperty', auto_build: true
|
13
|
+
embeds_one :table_width, class_name: 'Goldendocx::Tables::Properties::WidthProperty', auto_build: true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class RowHeightProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :trHeight
|
11
|
+
|
12
|
+
attribute :height, alias_name: :val, namespace: :w, default: Goldendocx::Tables::DEFAULT_CELL_DXA_HEIGHT
|
13
|
+
attribute :rule, alias_name: :hRule, namespace: :w, default: :atLeast
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class RowProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :trPr
|
11
|
+
|
12
|
+
embeds_one :height, class_name: 'Goldendocx::Tables::Properties::RowHeightProperty', auto_build: true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class ShadingProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :shd
|
11
|
+
|
12
|
+
attribute :value, alias_name: :val, namespace: :w
|
13
|
+
attribute :color, namespace: :w
|
14
|
+
attribute :fill, namespace: :w
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class StyleProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :tblStyle
|
11
|
+
|
12
|
+
attribute :style_id, alias_name: :val, namespace: :w
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class VerticalAlignProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :vAlign
|
11
|
+
|
12
|
+
attribute :align, alias_name: :val, namespace: :w, default: :center
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldendocx
|
4
|
+
module Tables
|
5
|
+
module Properties
|
6
|
+
class WidthProperty
|
7
|
+
include Goldendocx::Element
|
8
|
+
|
9
|
+
namespace :w
|
10
|
+
tag :tblW
|
11
|
+
|
12
|
+
attribute :width, alias_name: :w, namespace: :w, default: Goldendocx::Tables::DEFAULT_TABLE_DXA_WIDTH
|
13
|
+
attribute :type, namespace: :w, default: :dxa
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|