rocx 0.5.6 → 0.5.7
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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile.lock +1 -1
- data/lib/rocx.rb +1 -1
- data/lib/rocx/elements/base_container.rb +17 -2
- data/lib/rocx/elements/paragraph.rb +33 -21
- data/lib/rocx/elements/run.rb +2 -2
- data/lib/rocx/elements/style.rb +19 -0
- data/lib/rocx/parts/base_part.rb +4 -0
- data/lib/rocx/parts/content_types.rb +2 -6
- data/lib/rocx/parts/document.rb +2 -3
- data/lib/rocx/parts/global_rels.rb +2 -3
- data/lib/rocx/parts/rels.rb +2 -3
- data/lib/rocx/parts/settings.rb +2 -3
- data/lib/rocx/parts/styles.rb +2 -3
- data/lib/rocx/properties/alignment.rb +1 -1
- data/lib/rocx/properties/attribute_builder.rb +283 -0
- data/lib/rocx/properties/base_property.rb +4 -0
- data/lib/rocx/properties/border.rb +32 -0
- data/lib/rocx/properties/borders.rb +48 -0
- data/lib/rocx/properties/compress_punctuation.rb +11 -0
- data/lib/rocx/properties/frame.rb +70 -0
- data/lib/rocx/properties/indentation.rb +1 -1
- data/lib/rocx/properties/numbering.rb +28 -0
- data/lib/rocx/properties/shading.rb +75 -0
- data/lib/rocx/properties/spacing.rb +38 -0
- data/lib/rocx/properties/tab.rb +77 -0
- data/lib/rocx/properties/tabs.rb +55 -0
- data/lib/rocx/properties/text_direction.rb +15 -0
- data/lib/rocx/properties/textbox_tight_wrap.rb +15 -0
- data/lib/rocx/properties/vertical_alignment.rb +19 -0
- data/lib/rocx/version.rb +1 -1
- data/rocx.gemspec +1 -0
- data/test/package_test.rb +6 -6
- data/test/properties/auto_adjust_right_indent_test.rb +4 -4
- data/test/properties/auto_space_de_test.rb +4 -4
- data/test/properties/auto_space_dn_test.rb +4 -4
- data/test/properties/bidi_test.rb +4 -4
- data/test/properties/bold_test.rb +4 -4
- data/test/properties/border_test.rb +216 -0
- data/test/properties/borders_test.rb +95 -0
- data/test/properties/compress_punctuation_test.rb +50 -0
- data/test/properties/conditional_formatting_test.rb +4 -4
- data/test/properties/contextual_spacing_test.rb +4 -4
- data/test/properties/div_id_test.rb +3 -3
- data/test/properties/frame_test.rb +497 -0
- data/test/properties/italics_test.rb +4 -4
- data/test/properties/keep_lines_test.rb +4 -4
- data/test/properties/keep_next_test.rb +4 -4
- data/test/properties/kinsoku_test.rb +4 -4
- data/test/properties/mirror_indent_test.rb +4 -4
- data/test/properties/numbering_test.rb +86 -0
- data/test/properties/outline_level_test.rb +4 -4
- data/test/properties/overflow_punctuation_test.rb +4 -4
- data/test/properties/page_break_before_test.rb +4 -4
- data/test/properties/shading_test.rb +225 -0
- data/test/properties/snap_to_grid_test.rb +4 -4
- data/test/properties/spacing_test.rb +248 -0
- data/test/properties/style_test.rb +30 -0
- data/test/properties/supress_auto_hyphens_test.rb +4 -4
- data/test/properties/supress_line_numbers_test.rb +4 -4
- data/test/properties/supress_overlap_test.rb +4 -4
- data/test/properties/tab_test.rb +63 -0
- data/test/properties/tabs_test.rb +54 -0
- data/test/properties/text_direction_test.rb +100 -0
- data/test/properties/textbox_tight_wrap_test.rb +88 -0
- data/test/properties/vertical_alignment_test.rb +88 -0
- data/test/properties/widow_control_test.rb +4 -4
- data/test/properties/word_wrap_test.rb +4 -4
- data/test/test_helper.rb +2 -5
- metadata +45 -3
@@ -0,0 +1,32 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
class Border
|
4
|
+
include AttributeBuilder
|
5
|
+
|
6
|
+
attr_reader :tag
|
7
|
+
|
8
|
+
attribute :color, expects: :hex_color
|
9
|
+
attribute :frame, expects: :true_or_false
|
10
|
+
attribute :shadow, expects: :true_or_false
|
11
|
+
attribute :size, expects: :positive_integer, displays_as: :sz
|
12
|
+
attribute :space, expects: :positive_integer
|
13
|
+
attribute :theme_color, expects: :valid_theme_color, displays_as: :themeColor
|
14
|
+
attribute :theme_shade, expects: :hex_digit, displays_as: :themeShade
|
15
|
+
attribute :theme_tint, expects: :hex_digit, displays_as: :themeTint
|
16
|
+
attribute :type, expects: :valid_type, displays_as: :val
|
17
|
+
|
18
|
+
def initialize(tag)
|
19
|
+
@tag = tag
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
"border"
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_xml(xml)
|
27
|
+
xml["w"].public_send(tag, xml_attributes)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
class Borders
|
4
|
+
attr_reader :left, :right, :top, :bottom, :between, :bar
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@left = new_border :left
|
8
|
+
@right = new_border :right
|
9
|
+
@top = new_border :top
|
10
|
+
@bottom = new_border :bottom
|
11
|
+
@between = new_border :between
|
12
|
+
@bar = new_border :bar
|
13
|
+
end
|
14
|
+
|
15
|
+
def tag
|
16
|
+
:pBdr
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
"borders"
|
21
|
+
end
|
22
|
+
|
23
|
+
def render?
|
24
|
+
!renderable_borders.length.zero?
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_xml(xml)
|
28
|
+
return unless render?
|
29
|
+
xml["w"].public_send(tag) { render_borders_xml(xml) }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def render_borders_xml(xml)
|
35
|
+
renderable_borders.each { |border| border.to_xml(xml) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def renderable_borders
|
39
|
+
[@left, @right, @top, @bottom, @between, @bar].select(&:render?)
|
40
|
+
end
|
41
|
+
|
42
|
+
def new_border(direction)
|
43
|
+
Rocx::Properties::Border.new direction
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
class Frame
|
4
|
+
include AttributeBuilder
|
5
|
+
|
6
|
+
VALID_ANCHORS = %i(margin page text)
|
7
|
+
VALID_DROP_CAPS = %i(drop margin none)
|
8
|
+
VALID_HEIGHT_RULES = %i(atLeast auto exact)
|
9
|
+
VALID_RELATIVE_HORIZONTAL_POSITIONS = %i(center inside left outside right)
|
10
|
+
VALID_RELATIVE_VERTICAL_POSITIONS = %i(bottom center inline inside outside top)
|
11
|
+
VALID_WRAPS = %i(around auto none notBeside through tight)
|
12
|
+
|
13
|
+
attribute :anchor_lock, expects: :true_or_false, displays_as: :anchorLock
|
14
|
+
attribute :drop_cap, expects: :valid_drop_cap, displays_as: :dropCap
|
15
|
+
attribute :height, expects: :positive_integer, displays_as: :h
|
16
|
+
attribute :height_rule, expects: :valid_height_rule, displays_as: :hRule
|
17
|
+
attribute :horizontal_anchor, expects: :valid_anchor, displays_as: :hAnchor
|
18
|
+
attribute :horizontal_padding, expects: :positive_integer, displays_as: :hSpace
|
19
|
+
attribute :horizontal_position, expects: :integer, displays_as: :x
|
20
|
+
attribute :lines, expects: :positive_integer
|
21
|
+
attribute :relative_horizontal_position, expects: :valid_relative_horizontal_position, displays_as: :xAlign
|
22
|
+
attribute :relative_vertical_position, expects: :valid_relative_vertical_position, displays_as: :yAlign
|
23
|
+
attribute :vertical_anchor, expects: :valid_anchor, displays_as: :vAnchor
|
24
|
+
attribute :vertical_padding, expects: :positive_integer, displays_as: :vSpace
|
25
|
+
attribute :vertical_position, expects: :integer, displays_as: :y
|
26
|
+
attribute :width, expects: :positive_integer, displays_as: :w
|
27
|
+
attribute :wrap, expects: :valid_wrap
|
28
|
+
|
29
|
+
def tag
|
30
|
+
:framePr
|
31
|
+
end
|
32
|
+
|
33
|
+
def name
|
34
|
+
"frame"
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_xml(xml)
|
38
|
+
return if xml_attributes.empty?
|
39
|
+
xml["w"].public_send(tag, xml_attributes)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def valid_drop_cap(value)
|
45
|
+
valid_in? value, VALID_DROP_CAPS
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid_anchor(value)
|
49
|
+
valid_in? value, VALID_ANCHORS
|
50
|
+
end
|
51
|
+
|
52
|
+
def valid_height_rule(value)
|
53
|
+
valid_in? value, VALID_HEIGHT_RULES
|
54
|
+
end
|
55
|
+
|
56
|
+
def valid_relative_horizontal_position(value)
|
57
|
+
valid_in? value, VALID_RELATIVE_HORIZONTAL_POSITIONS
|
58
|
+
end
|
59
|
+
|
60
|
+
def valid_relative_vertical_position(value)
|
61
|
+
valid_in? value, VALID_RELATIVE_VERTICAL_POSITIONS
|
62
|
+
end
|
63
|
+
|
64
|
+
def valid_wrap(value)
|
65
|
+
valid_in? value, VALID_WRAPS
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
class Numbering
|
4
|
+
include AttributeBuilder
|
5
|
+
|
6
|
+
attribute :level, expects: :positive_integer, displays_as: :ilvl
|
7
|
+
attribute :id, expects: :positive_integer, displays_as: :numId
|
8
|
+
|
9
|
+
def name
|
10
|
+
"numbering"
|
11
|
+
end
|
12
|
+
|
13
|
+
def tag
|
14
|
+
:numPr
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_xml(xml)
|
18
|
+
return if xml_attributes.empty?
|
19
|
+
xml["w"].public_send(tag) {
|
20
|
+
xml_attributes.each do |tag_name, value|
|
21
|
+
xml.public_send(tag_name, "w:val" => value)
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
class Shading
|
4
|
+
include AttributeBuilder
|
5
|
+
|
6
|
+
VALID_SHADING_PATTERNS = %i(clear
|
7
|
+
diagCross
|
8
|
+
diagStripe
|
9
|
+
horzCross
|
10
|
+
horzStripe
|
11
|
+
nil
|
12
|
+
pct10
|
13
|
+
pct12
|
14
|
+
pct15
|
15
|
+
pct20
|
16
|
+
pct25
|
17
|
+
pct30
|
18
|
+
pct35
|
19
|
+
pct37
|
20
|
+
pct45
|
21
|
+
pct5
|
22
|
+
pct50
|
23
|
+
pct55
|
24
|
+
pct60
|
25
|
+
pct62
|
26
|
+
pct65
|
27
|
+
pct70
|
28
|
+
pct75
|
29
|
+
pct80
|
30
|
+
pct85
|
31
|
+
pct87
|
32
|
+
pct90
|
33
|
+
pct95
|
34
|
+
reverseDiagStripe
|
35
|
+
solid
|
36
|
+
thinDiagCross
|
37
|
+
thinDiagStripe
|
38
|
+
thinHorzCross
|
39
|
+
thinHorzStripe
|
40
|
+
thinReverseDiagStripe
|
41
|
+
thinVertStripe
|
42
|
+
vertStripe)
|
43
|
+
|
44
|
+
attribute :color, expects: :hex_color
|
45
|
+
attribute :fill, expects: :hex_color
|
46
|
+
attribute :theme_color, expects: :valid_theme_color, displays_as: :themeColor
|
47
|
+
attribute :theme_fill, expects: :valid_theme_color, displays_as: :themeFill
|
48
|
+
attribute :theme_fill_shade, expects: :hex_digit, displays_as: :themeFillShade
|
49
|
+
attribute :theme_fill_tint, expects: :hex_digit, displays_as: :themeFillTint
|
50
|
+
attribute :theme_shade, expects: :hex_digit, displays_as: :themeShade
|
51
|
+
attribute :theme_tint, expects: :hex_digit, displays_as: :themeTint
|
52
|
+
attribute :pattern, expects: :shading_pattern, displays_as: :val
|
53
|
+
|
54
|
+
def name
|
55
|
+
"shading"
|
56
|
+
end
|
57
|
+
|
58
|
+
def tag
|
59
|
+
:shd
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_xml(xml)
|
63
|
+
return if xml_attributes.empty?
|
64
|
+
xml["w"].public_send(tag, xml_attributes)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def shading_pattern(value)
|
70
|
+
valid_in? value, VALID_SHADING_PATTERNS
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
class Spacing
|
4
|
+
include AttributeBuilder
|
5
|
+
|
6
|
+
VALID_LINE_RULES = %i(atLeast auto exact)
|
7
|
+
|
8
|
+
attribute :after, expects: :positive_integer
|
9
|
+
attribute :after_auto, expects: :on_or_off, displays_as: :afterAutospacing
|
10
|
+
attribute :after_lines, expects: :integer, displays_as: :afterLines
|
11
|
+
attribute :before, expects: :positive_integer
|
12
|
+
attribute :before_auto, expects: :on_or_off, displays_as: :beforeAutospacing
|
13
|
+
attribute :before_lines, expects: :integer, displays_as: :beforeLines
|
14
|
+
attribute :line, expects: :integer
|
15
|
+
attribute :line_rule, expects: :valid_line_rule, displays_as: :lineRule
|
16
|
+
|
17
|
+
def name
|
18
|
+
"spacing"
|
19
|
+
end
|
20
|
+
|
21
|
+
def tag
|
22
|
+
:spacing
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_xml(xml)
|
26
|
+
return if xml_attributes.empty?
|
27
|
+
xml["w"].public_send(tag, xml_attributes)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def valid_line_rule(value)
|
33
|
+
valid_in? value, VALID_LINE_RULES
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
class Tab
|
4
|
+
attr_reader :position, :type, :leader
|
5
|
+
|
6
|
+
VALID_TYPES = %i(bar center clear decimal end num start)
|
7
|
+
VALID_LEADERS = [nil, :dot, :heavy, :hyphen, :middleDot, :none, :underscore]
|
8
|
+
|
9
|
+
def initialize(position, type, leader=nil)
|
10
|
+
self.position = position
|
11
|
+
self.type = type
|
12
|
+
self.leader = leader
|
13
|
+
end
|
14
|
+
|
15
|
+
def position=(value)
|
16
|
+
raise ArgumentError, invalid_position_message unless valid_position?(value)
|
17
|
+
@position = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def type=(value)
|
21
|
+
raise ArgumentError, invalid_type_message unless valid_type?(value)
|
22
|
+
@type = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def leader=(value)
|
26
|
+
raise ArgumentError, invalid_leader_message unless valid_leader?(value)
|
27
|
+
@leader = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_xml(xml)
|
31
|
+
xml["w"].public_send(tag, xml_attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
def tag
|
35
|
+
:tab
|
36
|
+
end
|
37
|
+
|
38
|
+
def name
|
39
|
+
"tab"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def xml_attributes
|
45
|
+
attrs = { "w:pos" => position,
|
46
|
+
"w:val" => type}
|
47
|
+
attrs["w:leader"] = leader if leader
|
48
|
+
attrs
|
49
|
+
end
|
50
|
+
|
51
|
+
def invalid_position_message
|
52
|
+
"Invalid position: must be an integer"
|
53
|
+
end
|
54
|
+
|
55
|
+
def valid_position?(value)
|
56
|
+
value.is_a?(Integer)
|
57
|
+
end
|
58
|
+
|
59
|
+
def invalid_type_message
|
60
|
+
"Invalid type: must be one of: #{VALID_TYPES.join(", ")}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def valid_type?(value)
|
64
|
+
VALID_TYPES.member? value
|
65
|
+
end
|
66
|
+
|
67
|
+
def invalid_leader_message
|
68
|
+
"Invalid leader: must be one of: #{VALID_LEADERS.join(", ")}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def valid_leader?(value)
|
72
|
+
VALID_LEADERS.member? value
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
class Tabs
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@tabs = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(tab)
|
11
|
+
raise ArgumentError, invalid_tab_message unless valid_tab?(tab)
|
12
|
+
tabs << tab
|
13
|
+
end
|
14
|
+
|
15
|
+
def each(*args, &block)
|
16
|
+
tabs.each *args, &block
|
17
|
+
end
|
18
|
+
|
19
|
+
def render?
|
20
|
+
!tabs.length.zero?
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_xml(xml)
|
24
|
+
return unless render?
|
25
|
+
|
26
|
+
xml["w"].public_send(tag) {
|
27
|
+
each { |tab| tab.to_xml(xml) }
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def name
|
32
|
+
"tabs"
|
33
|
+
end
|
34
|
+
|
35
|
+
def tag
|
36
|
+
:tabs
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
attr_reader :tabs
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def invalid_tab_message
|
46
|
+
"Tabs must be instances of Rocx::Properties::Tab"
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid_tab?(tab)
|
50
|
+
tab.is_a?(Rocx::Properties::Tab)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|