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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ebac9d8d2e707e65cf407ccc36232723b714808
|
4
|
+
data.tar.gz: 31d5f1ddbf1b278ffd9e7f28a615bd53e58c5f05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff8b3600a3cb1319f49cfc4abef91b0494973f21f4cf3b8c958d860bf61c2223fdb32fe7b4f6bd959096fe5198cb10349ffb4d15417b24f48d067055deb5258d
|
7
|
+
data.tar.gz: 2227d88abf6fe8c3829fce89535b371af53302c0c761b63569fbd9d0b0831bc7acc80f383f09e3a0d7cf80ae1c2afa90978f14ba543f9f11330693aa1b2ec175
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
data/lib/rocx.rb
CHANGED
@@ -9,7 +9,7 @@ module Rocx
|
|
9
9
|
@properties_tag
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def value_property(name)
|
13
13
|
attr_reader name
|
14
14
|
|
15
15
|
define_method "#{name}=" do |value|
|
@@ -21,6 +21,21 @@ module Rocx
|
|
21
21
|
properties << name
|
22
22
|
end
|
23
23
|
|
24
|
+
def property(name)
|
25
|
+
define_method "#{name}" do
|
26
|
+
class_name = name.to_s.split("_").map(&:capitalize).join
|
27
|
+
prop_class = Rocx::Properties.const_get class_name
|
28
|
+
|
29
|
+
if instance_variable_get("@#{name}").nil?
|
30
|
+
instance_variable_set "@#{name}", prop_class.new
|
31
|
+
end
|
32
|
+
|
33
|
+
instance_variable_get "@#{name}"
|
34
|
+
end
|
35
|
+
|
36
|
+
properties << name
|
37
|
+
end
|
38
|
+
|
24
39
|
def properties
|
25
40
|
@properties ||= []
|
26
41
|
end
|
@@ -46,7 +61,7 @@ module Rocx
|
|
46
61
|
|
47
62
|
def property_xml(xml)
|
48
63
|
props = properties.map(&method(:send)).compact
|
49
|
-
return if props.
|
64
|
+
return if props.none?(&:render?)
|
50
65
|
xml[namespace].public_send(properties_tag) {
|
51
66
|
props.each { |prop| prop.to_xml(xml) }
|
52
67
|
}
|
@@ -5,27 +5,39 @@ module Rocx
|
|
5
5
|
namespace :w
|
6
6
|
properties_tag :pPr
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
8
|
+
value_property :alignment
|
9
|
+
value_property :auto_adjust_right_indent
|
10
|
+
value_property :auto_space_de
|
11
|
+
value_property :auto_space_dn
|
12
|
+
value_property :bidi
|
13
|
+
value_property :compress_punctuation
|
14
|
+
value_property :conditional_formatting
|
15
|
+
value_property :contextual_spacing
|
16
|
+
value_property :div_id
|
17
|
+
value_property :keep_lines
|
18
|
+
value_property :keep_next
|
19
|
+
value_property :indentation
|
20
|
+
value_property :mirror_indent
|
21
|
+
value_property :outline_level
|
22
|
+
value_property :overflow_punctuation
|
23
|
+
value_property :page_break_before
|
24
|
+
value_property :snap_to_grid
|
25
|
+
value_property :style
|
26
|
+
value_property :supress_auto_hyphens
|
27
|
+
value_property :supress_line_numbers
|
28
|
+
value_property :supress_overlap
|
29
|
+
value_property :textbox_tight_wrap
|
30
|
+
value_property :text_direction
|
31
|
+
value_property :vertical_alignment
|
32
|
+
value_property :widow_control
|
33
|
+
value_property :word_wrap
|
34
|
+
|
35
|
+
property :borders
|
36
|
+
property :frame
|
37
|
+
property :numbering
|
38
|
+
property :shading
|
39
|
+
property :spacing
|
40
|
+
property :tabs
|
29
41
|
end
|
30
42
|
end
|
31
43
|
end
|
data/lib/rocx/elements/run.rb
CHANGED
data/lib/rocx/parts/base_part.rb
CHANGED
@@ -28,19 +28,15 @@ module Rocx
|
|
28
28
|
overrides << {"PartName" => part_name, "ContentType" => content_type}
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
|
31
|
+
def to_xml
|
32
|
+
build_xml do |xml|
|
33
33
|
xml.Types(xmlns: "http://schemas.openxmlformats.org/package/2006/content-types") {
|
34
34
|
defaults.each { |default| xml.Default(default) }
|
35
35
|
overrides.each { |override| xml.Override(override) }
|
36
36
|
}
|
37
37
|
end
|
38
|
-
strip_whitespace(xml)
|
39
38
|
end
|
40
39
|
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
data/lib/rocx/parts/document.rb
CHANGED
@@ -11,8 +11,8 @@ module Rocx
|
|
11
11
|
children << child
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def to_xml
|
15
|
+
build_xml do |xml|
|
16
16
|
xml.document(root_namespaces) {
|
17
17
|
xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == 'w' }
|
18
18
|
xml['w'].body {
|
@@ -20,7 +20,6 @@ module Rocx
|
|
20
20
|
}
|
21
21
|
}
|
22
22
|
end
|
23
|
-
strip_whitespace(xml)
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
@@ -2,13 +2,12 @@ module Rocx
|
|
2
2
|
module Parts
|
3
3
|
class GlobalRels < BasePart
|
4
4
|
|
5
|
-
def
|
6
|
-
|
5
|
+
def to_xml
|
6
|
+
build_xml do |xml|
|
7
7
|
xml.Relationships(xmlns: "http://schemas.openxmlformats.org/package/2006/relationships") {
|
8
8
|
xml.Relationship(document_relation_attributes)
|
9
9
|
}
|
10
10
|
end
|
11
|
-
strip_whitespace(xml)
|
12
11
|
end
|
13
12
|
|
14
13
|
private
|
data/lib/rocx/parts/rels.rb
CHANGED
@@ -21,15 +21,14 @@ module Rocx
|
|
21
21
|
relationships << {"Type" => type, "Target" => target, "Id" => id}
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
24
|
+
def to_xml
|
25
|
+
build_xml do |xml|
|
26
26
|
xml.Relationships(xmlns: "http://schemas.openxmlformats.org/package/2006/relationships") {
|
27
27
|
relationships.each do |rel|
|
28
28
|
xml.Relationship(rel)
|
29
29
|
end
|
30
30
|
}
|
31
31
|
end
|
32
|
-
strip_whitespace(xml)
|
33
32
|
end
|
34
33
|
|
35
34
|
private
|
data/lib/rocx/parts/settings.rb
CHANGED
@@ -7,13 +7,12 @@ module Rocx
|
|
7
7
|
@settings = []
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def to_xml
|
11
|
+
build_standalone_xml do |xml|
|
12
12
|
xml.settings("xmlns:w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main") {
|
13
13
|
xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == "w" }
|
14
14
|
}
|
15
15
|
end
|
16
|
-
strip_whitespace(xml)
|
17
16
|
end
|
18
17
|
|
19
18
|
end
|
data/lib/rocx/parts/styles.rb
CHANGED
@@ -11,15 +11,14 @@ module Rocx
|
|
11
11
|
@styles << style
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def to_xml
|
15
|
+
build_standalone_xml do |xml|
|
16
16
|
xml.styles(root_namespaces) {
|
17
17
|
xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == "w" }
|
18
18
|
add_default_styles(xml)
|
19
19
|
styles.each { |style| style.build_xml(xml) }
|
20
20
|
}
|
21
21
|
end
|
22
|
-
strip_whitespace(xml)
|
23
22
|
end
|
24
23
|
|
25
24
|
private
|
@@ -0,0 +1,283 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Properties
|
3
|
+
module AttributeBuilder
|
4
|
+
|
5
|
+
VALID_THEME_COLORS = %i(accent1 accent2 accent3 accent4 accent5 accent6 background1 background2 dark1 dark2 followedHyperlink hyperlink light1 light2 none text1 text2)
|
6
|
+
|
7
|
+
VALID_TYPES = %i(apples
|
8
|
+
archedScallops
|
9
|
+
babyPacifier
|
10
|
+
babyRattle
|
11
|
+
balloons3Colors
|
12
|
+
balloonsHotAir
|
13
|
+
basicBlackDashes
|
14
|
+
basicBlackDots
|
15
|
+
basicBlackSquares
|
16
|
+
basicThinLines
|
17
|
+
basicWhiteDashes
|
18
|
+
basicWhiteDots
|
19
|
+
basicWhiteSquares
|
20
|
+
basicWideInline
|
21
|
+
basicWideMidline
|
22
|
+
basicWideOutline
|
23
|
+
bats
|
24
|
+
birds
|
25
|
+
birdsFlight
|
26
|
+
cabins
|
27
|
+
cakeSlice
|
28
|
+
candyCorn
|
29
|
+
celticKnotwork
|
30
|
+
certificateBanner
|
31
|
+
chainLink
|
32
|
+
champagneBottle
|
33
|
+
checkedBarBlack
|
34
|
+
checkedBarColor
|
35
|
+
checkered
|
36
|
+
christmasTree
|
37
|
+
circlesLines
|
38
|
+
circlesRectangles
|
39
|
+
classicalWave
|
40
|
+
clocks
|
41
|
+
compass
|
42
|
+
confetti
|
43
|
+
confettiGrays
|
44
|
+
confettiOutlines
|
45
|
+
confettiStreamers
|
46
|
+
confettiWhite
|
47
|
+
cornerTriangles
|
48
|
+
couponCutoutDashes
|
49
|
+
couponCutoutDots
|
50
|
+
crazyMaze
|
51
|
+
creaturesButterfly
|
52
|
+
creaturesFish
|
53
|
+
creaturesInsects
|
54
|
+
creaturesLadyBug
|
55
|
+
crossStitch
|
56
|
+
cup
|
57
|
+
custom
|
58
|
+
dashDotStroked
|
59
|
+
dashed
|
60
|
+
dashSmallGap
|
61
|
+
decoArch
|
62
|
+
decoArchColor
|
63
|
+
decoBlocks
|
64
|
+
diamondsGray
|
65
|
+
dotDash
|
66
|
+
dotDotDash
|
67
|
+
dotted
|
68
|
+
double
|
69
|
+
doubleD
|
70
|
+
doubleDiamonds
|
71
|
+
doubleWave
|
72
|
+
earth1
|
73
|
+
earth2
|
74
|
+
earth3
|
75
|
+
eclipsingSquares1
|
76
|
+
eclipsingSquares2
|
77
|
+
eggsBlack
|
78
|
+
fans
|
79
|
+
film
|
80
|
+
firecrackers
|
81
|
+
flowersBlockPrint
|
82
|
+
flowersDaisies
|
83
|
+
flowersModern1
|
84
|
+
flowersModern2
|
85
|
+
flowersPansy
|
86
|
+
flowersRedRose
|
87
|
+
flowersRoses
|
88
|
+
flowersTeacup
|
89
|
+
flowersTiny
|
90
|
+
gems
|
91
|
+
gingerbreadMan
|
92
|
+
gradient
|
93
|
+
handmade1
|
94
|
+
handmade2
|
95
|
+
heartBalloon
|
96
|
+
heartGray
|
97
|
+
hearts
|
98
|
+
heebieJeebies
|
99
|
+
holly
|
100
|
+
houseFunky
|
101
|
+
hypnotic
|
102
|
+
iceCreamCones
|
103
|
+
inset
|
104
|
+
lightBulb
|
105
|
+
lightning1
|
106
|
+
lightning2
|
107
|
+
mapleLeaf
|
108
|
+
mapleMuffins
|
109
|
+
mapPins
|
110
|
+
marquee
|
111
|
+
marqueeToothed
|
112
|
+
moons
|
113
|
+
mosaic
|
114
|
+
musicNotes
|
115
|
+
nil
|
116
|
+
none
|
117
|
+
northwest
|
118
|
+
outset
|
119
|
+
ovals
|
120
|
+
packages
|
121
|
+
palmsBlack
|
122
|
+
palmsColor
|
123
|
+
paperClips
|
124
|
+
papyrus
|
125
|
+
partyFavor
|
126
|
+
partyGlass
|
127
|
+
pencils
|
128
|
+
people
|
129
|
+
peopleHats
|
130
|
+
peopleWaving
|
131
|
+
poinsettias
|
132
|
+
postageStamp
|
133
|
+
pumpkin1
|
134
|
+
pushPinNote1
|
135
|
+
pushPinNote2
|
136
|
+
pyramids
|
137
|
+
pyramidsAbove
|
138
|
+
quadrants
|
139
|
+
rings
|
140
|
+
safari
|
141
|
+
sawtooth
|
142
|
+
sawtoothGray
|
143
|
+
scaredCat
|
144
|
+
seattle
|
145
|
+
shadowedSquares
|
146
|
+
shapes1
|
147
|
+
shapes2
|
148
|
+
sharksTeeth
|
149
|
+
shorebirdTracks
|
150
|
+
single
|
151
|
+
skyrocket
|
152
|
+
snowflakeFancy
|
153
|
+
snowflaskes
|
154
|
+
sombrero
|
155
|
+
southwest
|
156
|
+
stars
|
157
|
+
stars3d
|
158
|
+
starsBlack
|
159
|
+
starsShadowed
|
160
|
+
starsTop
|
161
|
+
sun
|
162
|
+
swirligig
|
163
|
+
thick
|
164
|
+
thickThinLargeGap
|
165
|
+
thickThinMediumGap
|
166
|
+
thickThinSmallGap
|
167
|
+
thinThickLargeGap
|
168
|
+
thinThickMediumGap
|
169
|
+
thinThickSmallGap
|
170
|
+
thinThickThinLargeGap
|
171
|
+
thinThickThinMediumGap
|
172
|
+
thinThickThinSmallGap
|
173
|
+
threeDEmboss
|
174
|
+
threeDEngrave
|
175
|
+
tornPaper
|
176
|
+
tornPaperBlack
|
177
|
+
trees
|
178
|
+
triangle1
|
179
|
+
triangle2
|
180
|
+
triangleCircle1
|
181
|
+
triangleCircle2
|
182
|
+
triangleParty
|
183
|
+
triangle
|
184
|
+
triple
|
185
|
+
twistedLines1
|
186
|
+
twistedLines2
|
187
|
+
vine
|
188
|
+
wave
|
189
|
+
waveline
|
190
|
+
weavingAngles
|
191
|
+
weavingBraid
|
192
|
+
weavingRibbon
|
193
|
+
weavingStrips
|
194
|
+
whiteFlowers
|
195
|
+
woodwork
|
196
|
+
xIllusions
|
197
|
+
zanyTriangles
|
198
|
+
zigZag
|
199
|
+
zigZagStitch)
|
200
|
+
|
201
|
+
def self.included(base)
|
202
|
+
base.extend(ClassMethods)
|
203
|
+
end
|
204
|
+
|
205
|
+
module ClassMethods
|
206
|
+
def attribute(name, expects: nil, displays_as: nil)
|
207
|
+
attr_reader name
|
208
|
+
|
209
|
+
define_method "#{name}=" do |value|
|
210
|
+
send(expects, value)
|
211
|
+
instance_variable_set "@#{name}", value
|
212
|
+
end
|
213
|
+
|
214
|
+
attributes[name] = displays_as || name
|
215
|
+
end
|
216
|
+
|
217
|
+
def attributes
|
218
|
+
@attributes ||= {}
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def render?
|
223
|
+
attributes.keys.map(&method(:send)).any?
|
224
|
+
end
|
225
|
+
|
226
|
+
def attributes
|
227
|
+
self.class.attributes
|
228
|
+
end
|
229
|
+
|
230
|
+
private
|
231
|
+
|
232
|
+
def xml_attributes
|
233
|
+
attributes.each_with_object({}) do |(name, display), attrs|
|
234
|
+
value = send(name)
|
235
|
+
attrs["w:#{display}"] = value if value
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def true_or_false(value)
|
240
|
+
message = "Invalid #{name}: frame must be true or false"
|
241
|
+
raise ArgumentError, message unless [true, false].member? value
|
242
|
+
end
|
243
|
+
|
244
|
+
def hex_color(value)
|
245
|
+
message = "Invalid #{name}: must be :auto or a hex color, e.g. 4F1B8C"
|
246
|
+
raise ArgumentError, message unless value == :auto || value =~ /[0-9A-F]{6}/
|
247
|
+
end
|
248
|
+
|
249
|
+
def hex_digit(value)
|
250
|
+
message = "Invalid #{name}: must be a two-digit hex number, e.g. BF"
|
251
|
+
raise ArgumentError, message unless value =~ /[0-9A-F]{2}/
|
252
|
+
end
|
253
|
+
|
254
|
+
def integer(value)
|
255
|
+
message = "Invalid #{name}: must be an integer"
|
256
|
+
raise ArgumentError, message unless value.is_a?(Integer)
|
257
|
+
end
|
258
|
+
|
259
|
+
def positive_integer(value)
|
260
|
+
message = "Invalid #{name}: must be a positive integer"
|
261
|
+
raise ArgumentError, message unless value.is_a?(Integer) && value >= 0
|
262
|
+
end
|
263
|
+
|
264
|
+
def on_or_off(value)
|
265
|
+
valid_in? value, [:on, :off]
|
266
|
+
end
|
267
|
+
|
268
|
+
def valid_theme_color(value)
|
269
|
+
valid_in? value, VALID_THEME_COLORS
|
270
|
+
end
|
271
|
+
|
272
|
+
def valid_type(value)
|
273
|
+
valid_in? value, VALID_TYPES
|
274
|
+
end
|
275
|
+
|
276
|
+
def valid_in?(value, list)
|
277
|
+
message = "Invalid #{name}: must be one of #{list.join(", ")}"
|
278
|
+
raise ArgumentError, message unless list.member?(value)
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|