openxml-docx 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/{example → examples/base} +1 -1
- data/examples/table +68 -0
- data/lib/openxml/docx/elements/grid_column.rb +12 -0
- data/lib/openxml/docx/elements/table.rb +30 -0
- data/lib/openxml/docx/elements/table_cell.rb +26 -0
- data/lib/openxml/docx/elements/table_grid.rb +10 -0
- data/lib/openxml/docx/elements/table_row.rb +36 -0
- data/lib/openxml/docx/package.rb +3 -0
- data/lib/openxml/docx/properties.rb +2 -0
- data/lib/openxml/docx/properties/base_property.rb +14 -0
- data/lib/openxml/docx/properties/cant_split.rb +8 -0
- data/lib/openxml/docx/properties/columns.rb +2 -0
- data/lib/openxml/docx/properties/grid_after.rb +8 -0
- data/lib/openxml/docx/properties/grid_before.rb +8 -0
- data/lib/openxml/docx/properties/grid_span.rb +8 -0
- data/lib/openxml/docx/properties/header.rb +8 -0
- data/lib/openxml/docx/properties/headers.rb +12 -0
- data/lib/openxml/docx/properties/hidden.rb +8 -0
- data/lib/openxml/docx/properties/hide_mark.rb +8 -0
- data/lib/openxml/docx/properties/no_wrap.rb +8 -0
- data/lib/openxml/docx/properties/table_border.rb +25 -0
- data/lib/openxml/docx/properties/table_borders.rb +13 -0
- data/lib/openxml/docx/properties/table_caption.rb +10 -0
- data/lib/openxml/docx/properties/table_cell_border.rb +25 -0
- data/lib/openxml/docx/properties/table_cell_borders.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_cell_margin.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_fit_text.rb +9 -0
- data/lib/openxml/docx/properties/table_cell_margin.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_margins.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_spacing.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_width.rb +13 -0
- data/lib/openxml/docx/properties/table_description.rb +10 -0
- data/lib/openxml/docx/properties/table_header.rb +10 -0
- data/lib/openxml/docx/properties/table_indent.rb +13 -0
- data/lib/openxml/docx/properties/table_layout.rb +14 -0
- data/lib/openxml/docx/properties/table_look.rb +17 -0
- data/lib/openxml/docx/properties/table_overlap.rb +14 -0
- data/lib/openxml/docx/properties/table_p_pr.rb +41 -0
- data/lib/openxml/docx/properties/table_style.rb +10 -0
- data/lib/openxml/docx/properties/table_width.rb +13 -0
- data/lib/openxml/docx/properties/tr_height.rb +19 -0
- data/lib/openxml/docx/properties/valign.rb +13 -0
- data/lib/openxml/docx/properties/wafter.rb +12 -0
- data/lib/openxml/docx/properties/wbefore.rb +12 -0
- data/lib/openxml/docx/properties/width_property.rb +17 -0
- data/lib/openxml/docx/style.rb +17 -7
- data/lib/openxml/docx/version.rb +1 -1
- data/spec/elements/grid_column_spec.rb +15 -0
- data/spec/elements/table_cell_spec.rb +15 -0
- data/spec/elements/table_grid_spec.rb +17 -0
- data/spec/elements/table_row_spec.rb +18 -0
- data/spec/elements/table_spec.rb +21 -0
- data/spec/properties/border_spec.rb +21 -95
- data/spec/properties/cant_split_spec.rb +23 -0
- data/spec/properties/color_spec.rb +9 -29
- data/spec/properties/column_spec.rb +6 -22
- data/spec/properties/columns_spec.rb +4 -14
- data/spec/properties/conditional_formatting_spec.rb +12 -108
- data/spec/properties/document_grid_spec.rb +12 -53
- data/spec/properties/east_asian_layout_spec.rb +14 -74
- data/spec/properties/font_spec.rb +35 -238
- data/spec/properties/frame_spec.rb +48 -285
- data/spec/properties/grid_after_spec.rb +26 -0
- data/spec/properties/grid_before_spec.rb +26 -0
- data/spec/properties/grid_span_spec.rb +24 -0
- data/spec/properties/header_spec.rb +17 -0
- data/spec/properties/headers_spec.rb +39 -0
- data/spec/properties/hidden_spec.rb +23 -0
- data/spec/properties/hide_mark_spec.rb +23 -0
- data/spec/properties/indentation_spec.rb +32 -136
- data/spec/properties/language_spec.rb +3 -12
- data/spec/properties/latent_styles_exception_spec.rb +7 -22
- data/spec/properties/latent_styles_spec.rb +5 -18
- data/spec/properties/line_numbering_spec.rb +15 -68
- data/spec/properties/manual_width_spec.rb +8 -33
- data/spec/properties/no_wrap_spec.rb +23 -0
- data/spec/properties/numbering_spec.rb +4 -13
- data/spec/properties/page_margins_spec.rb +28 -114
- data/spec/properties/page_numbering_spec.rb +26 -367
- data/spec/properties/page_size_spec.rb +15 -62
- data/spec/properties/paper_source_spec.rb +8 -34
- data/spec/properties/shading_spec.rb +21 -92
- data/spec/properties/spacing_spec.rb +27 -119
- data/spec/properties/table_border_spec.rb +119 -0
- data/spec/properties/table_borders_spec.rb +41 -0
- data/spec/properties/table_caption_spec.rb +17 -0
- data/spec/properties/table_cell_border_spec.rb +119 -0
- data/spec/properties/table_cell_borders_spec.rb +40 -0
- data/spec/properties/table_cell_cell_margin_spec.rb +46 -0
- data/spec/properties/table_cell_fit_text.rb +23 -0
- data/spec/properties/table_cell_margin_spec.rb +40 -0
- data/spec/properties/table_cell_margins_spec.rb +46 -0
- data/spec/properties/table_cell_spacing_spec.rb +21 -0
- data/spec/properties/table_cell_width.rb +21 -0
- data/spec/properties/table_description_spec.rb +17 -0
- data/spec/properties/table_header_spec.rb +23 -0
- data/spec/properties/table_indent_spec.rb +43 -0
- data/spec/properties/table_layout_spec.rb +22 -0
- data/spec/properties/table_look_spec.rb +38 -0
- data/spec/properties/table_overlap_spec.rb +22 -0
- data/spec/properties/table_p_pr_spec.rb +68 -0
- data/spec/properties/table_row_height.rb +20 -0
- data/spec/properties/table_style_spec.rb +17 -0
- data/spec/properties/table_width_spec.rb +21 -0
- data/spec/properties/underline_spec.rb +14 -130
- data/spec/properties/valign_spec.rb +19 -0
- data/spec/properties/wafter_spec.rb +21 -0
- data/spec/properties/wbefore_spec.rb +21 -0
- data/spec/support/data/elements/grid_column_element.xml +4 -0
- data/spec/support/data/elements/table_cell_element.xml +8 -0
- data/spec/support/data/elements/table_element.xml +18 -0
- data/spec/support/data/elements/table_grid_element.xml +6 -0
- data/spec/support/data/elements/table_row_element.xml +13 -0
- data/spec/support/property_test_macros.rb +61 -0
- metadata +86 -3
@@ -0,0 +1,13 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Properties
|
4
|
+
class TableCellMargin < WidthProperty
|
5
|
+
tag_is_one_of %i(top start bottom end)
|
6
|
+
|
7
|
+
attribute :type, expects: :valid_width_type
|
8
|
+
attribute :width, expects: :positive_integer, displays_as: :w
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Properties
|
4
|
+
class TableLook < ComplexProperty
|
5
|
+
tag :tblLook
|
6
|
+
|
7
|
+
attribute :firstColumn, expects: :true_or_false
|
8
|
+
attribute :firstRow, expects: :true_or_false
|
9
|
+
attribute :lastColumn, expects: :true_or_false
|
10
|
+
attribute :lastRow, expects: :true_or_false
|
11
|
+
attribute :noHBand, expects: :true_or_false
|
12
|
+
attribute :noVBand, expects: :true_or_false
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Properties
|
4
|
+
class TablePPr < ComplexProperty
|
5
|
+
tag :tblpPr
|
6
|
+
|
7
|
+
attribute :bottomFromText, expects: :positive_integer
|
8
|
+
attribute :horizAnchor, expects: :valid_anchor
|
9
|
+
attribute :leftFromText, expects: :positive_integer
|
10
|
+
attribute :rightFromText, expects: :positive_integer
|
11
|
+
attribute :tblpX, expects: :integer
|
12
|
+
attribute :tblpXSpec, expects: :valid_x_spec
|
13
|
+
attribute :tblpY, expects: :integer
|
14
|
+
attribute :tblpYSpec, expects: :valid_y_spec
|
15
|
+
attribute :topFromText, expects: :positive_integer
|
16
|
+
attribute :vertAnchor, expects: :valid_anchor
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def valid_anchor(value)
|
21
|
+
list = %i(margin page text)
|
22
|
+
message = "Invalid #{name}: must be one of #{list.join(", ")} (was #{value.inspect})"
|
23
|
+
raise ArgumentError, message unless list.include? value
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_x_spec(value)
|
27
|
+
list = %i(center inside left outside right)
|
28
|
+
message = "Invalid #{name}: must be one of #{list.join(", ")} (was #{value.inspect})"
|
29
|
+
raise ArgumentError, message unless list.include? value
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_y_spec(value)
|
33
|
+
list = %i(bottom center inline inside outside top)
|
34
|
+
message = "Invalid #{name}: must be one of #{list.join(", ")} (was #{value.inspect})"
|
35
|
+
raise ArgumentError, message unless list.include? value
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Properties
|
4
|
+
class TrHeight < ComplexProperty
|
5
|
+
|
6
|
+
attribute :hRule, expects: :valid_hrule
|
7
|
+
attribute :val, expects: :positive_integer
|
8
|
+
|
9
|
+
private
|
10
|
+
def valid_hrule(value)
|
11
|
+
list = %i(auto atLeast exact).include? value
|
12
|
+
message = "Invalid #{name}: must be one of #{list.join(", ")} (was #{value.inspect})"
|
13
|
+
raise ArgumentError, message unless list.include? value
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Properties
|
4
|
+
class WidthProperty < ComplexProperty
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def valid_width_type(value)
|
9
|
+
list = %i(auto dxa nil pct)
|
10
|
+
message = "Invalid #{name}: must be one of #{list.join(", ")} (was #{value.inspect})"
|
11
|
+
raise ArgumentError, message unless list.include? value
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/openxml/docx/style.rb
CHANGED
@@ -4,7 +4,7 @@ module OpenXml
|
|
4
4
|
include AttributeBuilder
|
5
5
|
include PropertyBuilder
|
6
6
|
|
7
|
-
attr_reader :paragraph, :character, :type
|
7
|
+
attr_reader :paragraph, :character, :table, :type
|
8
8
|
|
9
9
|
attribute :custom, expects: :true_or_false, displays_as: :customStyle
|
10
10
|
attribute :default, expects: :true_or_false
|
@@ -53,26 +53,36 @@ module OpenXml
|
|
53
53
|
type == :paragraph
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
def character_style?
|
57
|
+
type == :character
|
58
|
+
end
|
59
|
+
|
60
|
+
VALID_STYLE_TYPES = %i(character paragraph table)
|
57
61
|
|
58
62
|
private
|
59
63
|
|
60
64
|
def install_paragraph_properties
|
61
65
|
@character = nil
|
66
|
+
@table = nil
|
62
67
|
@paragraph = OpenXml::Docx::Elements::Paragraph.new
|
63
68
|
end
|
64
69
|
|
65
70
|
def install_character_properties
|
66
71
|
@paragraph = nil
|
72
|
+
@table = nil
|
67
73
|
@character = OpenXml::Docx::Elements::Run.new
|
68
74
|
end
|
69
75
|
|
76
|
+
def install_table_properties
|
77
|
+
@character = nil
|
78
|
+
@paragraph = nil
|
79
|
+
@table = OpenXml::Docx::Elements::Table.new
|
80
|
+
end
|
81
|
+
|
70
82
|
def property_xml(xml)
|
71
|
-
if paragraph_style?
|
72
|
-
|
73
|
-
|
74
|
-
character.property_xml(xml)
|
75
|
-
end
|
83
|
+
return paragraph.property_xml(xml) if paragraph_style?
|
84
|
+
return character.property_xml(xml) if character_style?
|
85
|
+
table.property_xml(xml)
|
76
86
|
end
|
77
87
|
|
78
88
|
def valid_style_type(value)
|
data/lib/openxml/docx/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe OpenXml::Docx::Elements::GridColumn do
|
4
|
+
include ElementTestMacros
|
5
|
+
|
6
|
+
context "after creation" do
|
7
|
+
before(:each) do
|
8
|
+
@instance = described_class.new
|
9
|
+
instance.w = 1
|
10
|
+
end
|
11
|
+
|
12
|
+
it_should_output_correct_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe OpenXml::Docx::Elements::TableCell do
|
4
|
+
include ElementTestMacros
|
5
|
+
|
6
|
+
context "after creation" do
|
7
|
+
before(:each) do
|
8
|
+
@instance = described_class.new
|
9
|
+
instance.no_wrap = true
|
10
|
+
end
|
11
|
+
|
12
|
+
it_should_output_correct_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe OpenXml::Docx::Elements::TableGrid do
|
4
|
+
include ElementTestMacros
|
5
|
+
|
6
|
+
context "after creation" do
|
7
|
+
before(:each) do
|
8
|
+
@instance = described_class.new
|
9
|
+
column = OpenXml::Docx::Elements::GridColumn.new
|
10
|
+
column.w = 1
|
11
|
+
instance << column
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_output_correct_xml
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|