rocx 0.5.8 → 0.6.0
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/Gemfile.lock +1 -1
- data/README.md +55 -22
- data/Rakefile +1 -0
- data/lib/rocx.rb +1 -0
- data/lib/rocx/attribute_builder.rb +296 -0
- data/lib/rocx/elements.rb +3 -2
- data/lib/rocx/elements/absolute_position_tab.rb +29 -0
- data/lib/rocx/elements/bidi_embed.rb +17 -0
- data/lib/rocx/elements/bidi_override.rb +17 -0
- data/lib/rocx/elements/break.rb +19 -5
- data/lib/rocx/elements/carriage_return.rb +8 -0
- data/lib/rocx/elements/{base_container.rb → container.rb} +21 -16
- data/lib/rocx/elements/content_part.rb +8 -0
- data/lib/rocx/elements/control.rb +10 -0
- data/lib/rocx/elements/deleted_text.rb +8 -0
- data/lib/rocx/elements/dirty.rb +6 -0
- data/lib/rocx/elements/element.rb +62 -0
- data/lib/rocx/elements/last_rendered_page_break.rb +6 -0
- data/lib/rocx/elements/long_day.rb +8 -0
- data/lib/rocx/elements/long_month.rb +8 -0
- data/lib/rocx/elements/long_year.rb +8 -0
- data/lib/rocx/elements/nonbreaking_hyphen.rb +7 -0
- data/lib/rocx/elements/optional_hyphen.rb +8 -0
- data/lib/rocx/elements/page_number.rb +7 -0
- data/lib/rocx/elements/paragraph.rb +2 -4
- data/lib/rocx/elements/ruby.rb +46 -0
- data/lib/rocx/elements/run.rb +2 -4
- data/lib/rocx/elements/short_day.rb +8 -0
- data/lib/rocx/elements/short_month.rb +8 -0
- data/lib/rocx/elements/short_year.rb +8 -0
- data/lib/rocx/elements/symbol.rb +6 -5
- data/lib/rocx/elements/tab.rb +6 -0
- data/lib/rocx/elements/text.rb +14 -7
- data/lib/rocx/properties/border.rb +0 -2
- data/lib/rocx/properties/color.rb +0 -2
- data/lib/rocx/properties/complex_property.rb +1 -0
- data/lib/rocx/properties/conditional_formatting.rb +0 -2
- data/lib/rocx/properties/east_asian_layout.rb +2 -4
- data/lib/rocx/properties/font.rb +0 -2
- data/lib/rocx/properties/frame.rb +7 -9
- data/lib/rocx/properties/indentation.rb +0 -2
- data/lib/rocx/properties/language.rb +1 -2
- data/lib/rocx/properties/manual_width.rb +1 -2
- data/lib/rocx/properties/numbering.rb +0 -2
- data/lib/rocx/properties/phonetic_guide_alignment.rb +13 -0
- data/lib/rocx/properties/phonetic_guide_base_font_size.rb +8 -0
- data/lib/rocx/properties/phonetic_guide_font_size.rb +8 -0
- data/lib/rocx/properties/phonetic_guide_font_size_raise.rb +8 -0
- data/lib/rocx/properties/phonetic_guide_language.rb +17 -0
- data/lib/rocx/properties/shading.rb +0 -2
- data/lib/rocx/properties/spacing.rb +0 -2
- data/lib/rocx/properties/underline.rb +0 -2
- data/lib/rocx/properties/value_property.rb +1 -1
- data/lib/rocx/version.rb +1 -1
- data/spec/elements/absolute_position_tab_spec.rb +84 -0
- data/spec/elements/bidi_embed_spec.rb +31 -0
- data/spec/elements/bidi_override_spec.rb +31 -0
- data/spec/elements/break_spec.rb +32 -24
- data/spec/elements/carriage_return_spec.rb +12 -0
- data/spec/elements/content_part_spec.rb +18 -0
- data/spec/elements/control_spec.rb +41 -0
- data/spec/elements/deleted_text_spec.rb +24 -0
- data/spec/elements/dirty_spec.rb +12 -0
- data/spec/elements/last_rendered_page_break_spec.rb +12 -0
- data/spec/elements/long_day_spec.rb +12 -0
- data/spec/elements/long_month_spec.rb +12 -0
- data/spec/elements/long_year_spec.rb +12 -0
- data/spec/elements/nonbreaking_hyphen_spec.rb +12 -0
- data/spec/elements/optional_hyphen_spec.rb +12 -0
- data/spec/elements/page_number_spec.rb +12 -0
- data/spec/elements/paragraph_spec.rb +9 -7
- data/spec/elements/ruby_spec.rb +66 -0
- data/spec/elements/run_spec.rb +2 -2
- data/spec/elements/short_day_spec.rb +12 -0
- data/spec/elements/short_month_spec.rb +12 -0
- data/spec/elements/short_year_spec.rb +12 -0
- data/spec/elements/symbol_spec.rb +20 -10
- data/spec/elements/tab_spec.rb +12 -0
- data/spec/elements/text_spec.rb +12 -11
- data/spec/properties/phonetic_guide_alignment_spec.rb +42 -0
- data/spec/properties/phonetic_guide_base_font_size_spec.rb +25 -0
- data/spec/properties/phonetic_guide_font_size_raise_spec.rb +25 -0
- data/spec/properties/phonetic_guide_font_size_spec.rb +25 -0
- data/spec/properties/phonetic_guide_language_spec.rb +12 -0
- data/spec/support/element_test_macros.rb +135 -4
- metadata +55 -5
- data/lib/rocx/elements/base_element.rb +0 -91
- data/lib/rocx/properties/attribute_builder.rb +0 -289
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Elements
|
3
|
+
class BidiEmbed < Container
|
4
|
+
tag :dir
|
5
|
+
attribute :direction, expects: :valid_direction, displays_as: :val
|
6
|
+
|
7
|
+
VALID_DIRECTIONS = %i(rtl ltr)
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def valid_direction(value)
|
12
|
+
valid_in? value, VALID_DIRECTIONS
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Elements
|
3
|
+
class BidiOverride < Container
|
4
|
+
tag :bdo
|
5
|
+
attribute :direction, expects: :valid_direction, displays_as: :val
|
6
|
+
|
7
|
+
VALID_DIRECTIONS = %i(rtl ltr)
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def valid_direction(value)
|
12
|
+
valid_in? value, VALID_DIRECTIONS
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rocx/elements/break.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
module Rocx
|
2
2
|
module Elements
|
3
|
-
class Break <
|
4
|
-
|
5
|
-
|
6
|
-
attribute :
|
7
|
-
attribute :
|
3
|
+
class Break < Element
|
4
|
+
tag :br
|
5
|
+
|
6
|
+
attribute :clear, expects: :valid_clear
|
7
|
+
attribute :type, expects: :valid_break_type
|
8
|
+
|
9
|
+
VALID_CLEARS = %i(all left none right)
|
10
|
+
VALID_BREAK_TYPES = %i(column page textWrapping)
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def valid_clear(value)
|
15
|
+
valid_in? value, VALID_CLEARS
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid_break_type(value)
|
19
|
+
valid_in? value, VALID_BREAK_TYPES
|
20
|
+
end
|
21
|
+
|
8
22
|
end
|
9
23
|
end
|
10
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Rocx
|
2
2
|
module Elements
|
3
|
-
class
|
3
|
+
class Container < Element
|
4
4
|
attr_reader :children
|
5
5
|
|
6
6
|
class << self
|
@@ -9,24 +9,28 @@ module Rocx
|
|
9
9
|
@properties_tag
|
10
10
|
end
|
11
11
|
|
12
|
-
def value_property(name)
|
12
|
+
def value_property(name, as: nil)
|
13
13
|
attr_reader name
|
14
14
|
|
15
|
+
properties[name] = (as || name).to_s
|
16
|
+
|
15
17
|
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
16
18
|
def #{name}=(value)
|
17
|
-
|
19
|
+
property_key = "#{name}".to_sym
|
20
|
+
class_name = properties[property_key].split("_").map(&:capitalize).join
|
18
21
|
prop_class = Rocx::Properties.const_get class_name
|
19
22
|
instance_variable_set "@#{name}", prop_class.new(value)
|
20
23
|
end
|
21
24
|
CODE
|
22
|
-
|
23
|
-
properties << name
|
24
25
|
end
|
25
26
|
|
26
|
-
def property(name)
|
27
|
+
def property(name, as: nil)
|
28
|
+
properties[name] = (as || name).to_s
|
29
|
+
|
27
30
|
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
28
31
|
def #{name}
|
29
|
-
|
32
|
+
property_key = "#{name}".to_sym
|
33
|
+
class_name = properties[property_key].split("_").map(&:capitalize).join
|
30
34
|
prop_class = Rocx::Properties.const_get class_name
|
31
35
|
|
32
36
|
if instance_variable_get("@#{name}").nil?
|
@@ -36,18 +40,15 @@ module Rocx
|
|
36
40
|
instance_variable_get "@#{name}"
|
37
41
|
end
|
38
42
|
CODE
|
39
|
-
|
40
|
-
properties << name
|
41
43
|
end
|
42
44
|
|
43
45
|
def properties
|
44
|
-
@properties ||=
|
46
|
+
@properties ||= {}
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
def initialize
|
50
|
+
def initialize
|
49
51
|
@children = []
|
50
|
-
super args
|
51
52
|
end
|
52
53
|
|
53
54
|
def <<(child)
|
@@ -55,16 +56,16 @@ module Rocx
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def to_xml(xml)
|
58
|
-
|
59
|
+
xml[namespace].public_send(tag, xml_attributes) {
|
59
60
|
property_xml(xml)
|
60
61
|
children.each { |child| child.to_xml(xml) }
|
61
62
|
}
|
62
63
|
end
|
63
64
|
|
64
|
-
|
65
|
+
private
|
65
66
|
|
66
67
|
def property_xml(xml)
|
67
|
-
props = properties.map(&method(:send)).compact
|
68
|
+
props = properties.keys.map(&method(:send)).compact
|
68
69
|
return if props.none?(&:render?)
|
69
70
|
xml[namespace].public_send(properties_tag) {
|
70
71
|
props.each { |prop| prop.to_xml(xml) }
|
@@ -76,7 +77,11 @@ module Rocx
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def properties_tag
|
79
|
-
self.class.properties_tag
|
80
|
+
self.class.properties_tag || default_properties_tag
|
81
|
+
end
|
82
|
+
|
83
|
+
def default_properties_tag
|
84
|
+
:"#{tag}Pr"
|
80
85
|
end
|
81
86
|
|
82
87
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Elements
|
3
|
+
class Element
|
4
|
+
include AttributeBuilder
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_reader :property_name
|
8
|
+
|
9
|
+
def tag(*args)
|
10
|
+
@tag = args.first if args.any?
|
11
|
+
@tag
|
12
|
+
end
|
13
|
+
|
14
|
+
def name(*args)
|
15
|
+
@property_name = args.first if args.any?
|
16
|
+
@name
|
17
|
+
end
|
18
|
+
|
19
|
+
def namespace(*args)
|
20
|
+
@namespace = args.first if args.any?
|
21
|
+
@namespace
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def tag
|
27
|
+
self.class.tag || default_tag
|
28
|
+
end
|
29
|
+
|
30
|
+
def name
|
31
|
+
self.class.property_name || default_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def namespace
|
35
|
+
self.class.namespace || default_namespace
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_xml(xml)
|
39
|
+
xml["w"].public_send(tag, xml_attributes)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def default_tag
|
45
|
+
(class_name[0, 1].downcase + class_name[1..-1]).to_sym
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_name
|
49
|
+
class_name.gsub(/(.)([A-Z])/, '\1_\2').downcase
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_namespace
|
53
|
+
:w
|
54
|
+
end
|
55
|
+
|
56
|
+
def class_name
|
57
|
+
self.class.to_s.split(/::/).last
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Rocx
|
2
|
+
module Elements
|
3
|
+
class Ruby < Container
|
4
|
+
attr_reader :base, :ruby
|
5
|
+
|
6
|
+
value_property :alignment, as: :phonetic_guide_alignment
|
7
|
+
value_property :base_font_size, as: :phonetic_guide_base_font_size
|
8
|
+
value_property :font_size, as: :phonetic_guide_font_size
|
9
|
+
value_property :font_size_raise, as: :phonetic_guide_font_size_raise
|
10
|
+
value_property :language, as: :phonetic_guide_language
|
11
|
+
|
12
|
+
def base=(other)
|
13
|
+
raise ArgumentError unless other.is_a?(Rocx::Elements::Run)
|
14
|
+
@base = other
|
15
|
+
end
|
16
|
+
|
17
|
+
def ruby=(other)
|
18
|
+
raise ArgumentError unless other.is_a?(Rocx::Elements::Run)
|
19
|
+
@ruby = other
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_xml(xml)
|
23
|
+
xml[namespace].public_send(tag, xml_attributes) {
|
24
|
+
property_xml(xml)
|
25
|
+
ruby_text_xml(xml)
|
26
|
+
base_text_xml(xml)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def ruby_text_xml(xml)
|
33
|
+
xml["w"].rt {
|
34
|
+
ruby.to_xml(xml) if ruby
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def base_text_xml(xml)
|
39
|
+
xml["w"].rubyBase {
|
40
|
+
base.to_xml(xml) if base
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/rocx/elements/run.rb
CHANGED