rocx 0.5.6

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.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +48 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +34 -0
  7. data/Rakefile +9 -0
  8. data/lib/rocx.rb +8 -0
  9. data/lib/rocx/elements.rb +10 -0
  10. data/lib/rocx/elements/base_container.rb +65 -0
  11. data/lib/rocx/elements/base_element.rb +91 -0
  12. data/lib/rocx/elements/break.rb +10 -0
  13. data/lib/rocx/elements/paragraph.rb +31 -0
  14. data/lib/rocx/elements/run.rb +12 -0
  15. data/lib/rocx/elements/symbol.rb +10 -0
  16. data/lib/rocx/elements/text.rb +21 -0
  17. data/lib/rocx/package.rb +33 -0
  18. data/lib/rocx/parts.rb +8 -0
  19. data/lib/rocx/parts/base_part.rb +29 -0
  20. data/lib/rocx/parts/content_types.rb +46 -0
  21. data/lib/rocx/parts/document.rb +51 -0
  22. data/lib/rocx/parts/global_rels.rb +24 -0
  23. data/lib/rocx/parts/rels.rb +48 -0
  24. data/lib/rocx/parts/settings.rb +21 -0
  25. data/lib/rocx/parts/styles.rb +49 -0
  26. data/lib/rocx/properties.rb +12 -0
  27. data/lib/rocx/properties/alignment.rb +27 -0
  28. data/lib/rocx/properties/auto_adjust_right_indent.rb +15 -0
  29. data/lib/rocx/properties/auto_space_de.rb +15 -0
  30. data/lib/rocx/properties/auto_space_dn.rb +15 -0
  31. data/lib/rocx/properties/base_property.rb +35 -0
  32. data/lib/rocx/properties/bidi.rb +6 -0
  33. data/lib/rocx/properties/bold.rb +11 -0
  34. data/lib/rocx/properties/boolean_property.rb +15 -0
  35. data/lib/rocx/properties/conditional_formatting.rb +62 -0
  36. data/lib/rocx/properties/contextual_spacing.rb +6 -0
  37. data/lib/rocx/properties/div_id.rb +23 -0
  38. data/lib/rocx/properties/indentation.rb +31 -0
  39. data/lib/rocx/properties/italics.rb +11 -0
  40. data/lib/rocx/properties/keep_lines.rb +6 -0
  41. data/lib/rocx/properties/keep_next.rb +6 -0
  42. data/lib/rocx/properties/kinsoku.rb +6 -0
  43. data/lib/rocx/properties/mirror_indent.rb +6 -0
  44. data/lib/rocx/properties/on_off_property.rb +15 -0
  45. data/lib/rocx/properties/outline_level.rb +23 -0
  46. data/lib/rocx/properties/overflow_punctuation.rb +15 -0
  47. data/lib/rocx/properties/page_break_before.rb +6 -0
  48. data/lib/rocx/properties/snap_to_grid.rb +6 -0
  49. data/lib/rocx/properties/supress_auto_hyphens.rb +6 -0
  50. data/lib/rocx/properties/supress_line_numbers.rb +6 -0
  51. data/lib/rocx/properties/supress_overlap.rb +6 -0
  52. data/lib/rocx/properties/toggle_property.rb +15 -0
  53. data/lib/rocx/properties/widow_control.rb +6 -0
  54. data/lib/rocx/properties/word_wrap.rb +6 -0
  55. data/lib/rocx/style.rb +38 -0
  56. data/lib/rocx/version.rb +3 -0
  57. data/rocx.gemspec +30 -0
  58. data/test/data/elements/break_element.xml +4 -0
  59. data/test/data/elements/break_with_attributes_element.xml +4 -0
  60. data/test/data/elements/paragraph_element.xml +8 -0
  61. data/test/data/elements/paragraph_with_runs_element.xml +14 -0
  62. data/test/data/elements/run_element.xml +8 -0
  63. data/test/data/elements/symbol_element.xml +4 -0
  64. data/test/data/elements/text_element.xml +4 -0
  65. data/test/data/parts/content_types_part.xml +1 -0
  66. data/test/data/parts/document_with_children_part.xml +1 -0
  67. data/test/data/parts/empty_document_part.xml +1 -0
  68. data/test/data/parts/global_rels_part.xml +1 -0
  69. data/test/data/parts/rels_part.xml +1 -0
  70. data/test/data/parts/settings_part.xml +1 -0
  71. data/test/data/parts/styles_part.xml +1 -0
  72. data/test/data/parts/styles_with_custom_style_part.xml +1 -0
  73. data/test/data/styles/character_styles.xml +15 -0
  74. data/test/data/styles/paragraph_styles.xml +11 -0
  75. data/test/elements/break_test.rb +54 -0
  76. data/test/elements/paragraph_test.rb +37 -0
  77. data/test/elements/run_test.rb +18 -0
  78. data/test/elements/symbol_test.rb +23 -0
  79. data/test/elements/text_test.rb +26 -0
  80. data/test/package_test.rb +48 -0
  81. data/test/parts/content_types_test.rb +37 -0
  82. data/test/parts/document_test.rb +31 -0
  83. data/test/parts/global_rels_test.rb +13 -0
  84. data/test/parts/rels_test.rb +48 -0
  85. data/test/parts/settings_test.rb +13 -0
  86. data/test/parts/styles_test.rb +29 -0
  87. data/test/properties/auto_adjust_right_indent_test.rb +50 -0
  88. data/test/properties/auto_space_de_test.rb +50 -0
  89. data/test/properties/auto_space_dn_test.rb +50 -0
  90. data/test/properties/bidi_test.rb +50 -0
  91. data/test/properties/bold_test.rb +50 -0
  92. data/test/properties/conditional_formatting_test.rb +46 -0
  93. data/test/properties/contextual_spacing_test.rb +50 -0
  94. data/test/properties/div_id_test.rb +38 -0
  95. data/test/properties/italics_test.rb +50 -0
  96. data/test/properties/keep_lines_test.rb +50 -0
  97. data/test/properties/keep_next_test.rb +50 -0
  98. data/test/properties/kinsoku_test.rb +50 -0
  99. data/test/properties/mirror_indent_test.rb +50 -0
  100. data/test/properties/outline_level_test.rb +46 -0
  101. data/test/properties/overflow_punctuation_test.rb +50 -0
  102. data/test/properties/page_break_before_test.rb +50 -0
  103. data/test/properties/snap_to_grid_test.rb +50 -0
  104. data/test/properties/supress_auto_hyphens_test.rb +50 -0
  105. data/test/properties/supress_line_numbers_test.rb +50 -0
  106. data/test/properties/supress_overlap_test.rb +50 -0
  107. data/test/properties/widow_control_test.rb +50 -0
  108. data/test/properties/word_wrap_test.rb +50 -0
  109. data/test/style_test.rb +54 -0
  110. data/test/test_helper.rb +55 -0
  111. metadata +315 -0
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class BidiTest < PropertyTest
4
+ attr_reader :bidi
5
+
6
+ context "always" do
7
+ setup do
8
+ @bidi = Rocx::Properties::Bidi.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :bidi, bidi.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "bidi", bidi.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @bidi = Rocx::Properties::Bidi.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:bidi/>", xml(bidi)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @bidi = Rocx::Properties::Bidi.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(bidi)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @bidi = Rocx::Properties::Bidi.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(bidi)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class BoldTest < PropertyTest
4
+ attr_reader :bold
5
+
6
+ context "always" do
7
+ setup do
8
+ @bold = Rocx::Properties::Bold.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :b, bold.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "bold", bold.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @bold = Rocx::Properties::Bold.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:b/>", xml(bold)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @bold = Rocx::Properties::Bold.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(bold)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @bold = Rocx::Properties::Bold.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(bold)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,46 @@
1
+ require "test_helper"
2
+
3
+ class ConditionalFormattingTest < PropertyTest
4
+ attr_reader :cnf_style
5
+
6
+ context "always" do
7
+ setup do
8
+ @cnf_style = Rocx::Properties::ConditionalFormatting.new
9
+ end
10
+
11
+ should "have the correct tag" do
12
+ assert_equal :cnfStyle, cnf_style.tag
13
+ end
14
+
15
+ should "have the correct name" do
16
+ assert_equal "conditional_formatting", cnf_style.name
17
+ end
18
+ end
19
+
20
+ context "trying to set an invalid property" do
21
+ should "raise an error" do
22
+ assert_raises ArgumentError do
23
+ @cnf_style = Rocx::Properties::ConditionalFormatting.new(bad: true)
24
+ end
25
+ end
26
+ end
27
+
28
+ context "trying to set an invalid value to a valid property" do
29
+ should "raise an error" do
30
+ assert_raises ArgumentError do
31
+ @cnf_style = Rocx::Properties::ConditionalFormatting.new(even_v: :bad)
32
+ end
33
+ end
34
+ end
35
+
36
+ context "with valid properties and values, it" do
37
+ setup do
38
+ @cnf_style = Rocx::Properties::ConditionalFormatting.new(first_row: true, first_column: true, first_row_first_column: true)
39
+ end
40
+
41
+ should "render the correct XML" do
42
+ assert_equal "<w:cnfStyle w:first_column=\"true\" w:first_row=\"true\" w:first_row_first_column=\"true\"/>", xml(cnf_style)
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class ContextualSpacingTest < PropertyTest
4
+ attr_reader :contextual_spacing
5
+
6
+ context "always" do
7
+ setup do
8
+ @contextual_spacing = Rocx::Properties::ContextualSpacing.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :contextualSpacing, contextual_spacing.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "contextual_spacing", contextual_spacing.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @contextual_spacing = Rocx::Properties::ContextualSpacing.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:contextualSpacing/>", xml(contextual_spacing)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @contextual_spacing = Rocx::Properties::ContextualSpacing.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(contextual_spacing)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @contextual_spacing = Rocx::Properties::ContextualSpacing.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(contextual_spacing)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+
3
+ class DivIdTest < PropertyTest
4
+ attr_reader :div_id
5
+
6
+ context "always" do
7
+ setup do
8
+ @div_id = Rocx::Properties::DivId.new(0)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :divId, div_id.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "div_id", div_id.name
17
+ end
18
+ end
19
+
20
+ context "with non-integer values, it" do
21
+ should "raise an error" do
22
+ assert_raises ArgumentError do
23
+ @div_id = Rocx::Properties::DivId.new(:big)
24
+ end
25
+ end
26
+ end
27
+
28
+ context "with valid value, it" do
29
+ setup do
30
+ @div_id = Rocx::Properties::DivId.new(2)
31
+ end
32
+
33
+ should "return the proper XML" do
34
+ assert_equal "<w:divId w:val=\"2\"/>", xml(div_id)
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class ItalicsTest < PropertyTest
4
+ attr_reader :italics
5
+
6
+ context "always" do
7
+ setup do
8
+ @italics = Rocx::Properties::Italics.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :i, italics.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "italics", italics.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @italics = Rocx::Properties::Italics.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:i/>", xml(italics)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @italics = Rocx::Properties::Italics.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(italics)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @italics = Rocx::Properties::Italics.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(italics)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class KeepLinesTest < PropertyTest
4
+ attr_reader :keep_lines
5
+
6
+ context "always" do
7
+ setup do
8
+ @keep_lines = Rocx::Properties::KeepLines.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :keepLines, keep_lines.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "keep_lines", keep_lines.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @keep_lines = Rocx::Properties::KeepLines.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:keepLines/>", xml(keep_lines)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @keep_lines = Rocx::Properties::KeepLines.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(keep_lines)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @keep_lines = Rocx::Properties::KeepLines.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(keep_lines)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class KeepNextTest < PropertyTest
4
+ attr_reader :keep_next
5
+
6
+ context "always" do
7
+ setup do
8
+ @keep_next = Rocx::Properties::KeepNext.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :keepNext, keep_next.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "keep_next", keep_next.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @keep_next = Rocx::Properties::KeepNext.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:keepNext/>", xml(keep_next)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @keep_next = Rocx::Properties::KeepNext.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(keep_next)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @keep_next = Rocx::Properties::KeepNext.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(keep_next)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class KinsokuTest < PropertyTest
4
+ attr_reader :kinsoku
5
+
6
+ context "always" do
7
+ setup do
8
+ @kinsoku = Rocx::Properties::Kinsoku.new(:on)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :kinsoku, kinsoku.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "kinsoku", kinsoku.name
17
+ end
18
+ end
19
+
20
+ context "when the value is on, it" do
21
+ setup do
22
+ @kinsoku = Rocx::Properties::Kinsoku.new(:on)
23
+ end
24
+
25
+ should "return XML to that effect" do
26
+ assert_equal "<w:kinsoku w:val=\"on\"/>", xml(kinsoku)
27
+ end
28
+ end
29
+
30
+ context "when the value is off, it" do
31
+ setup do
32
+ @kinsoku = Rocx::Properties::Kinsoku.new(:off)
33
+ end
34
+
35
+ should "return XML to that effect" do
36
+ assert_equal "<w:kinsoku w:val=\"off\"/>", xml(kinsoku)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @kinsoku = Rocx::Properties::Kinsoku.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(kinsoku)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class MirrorIndentTest < PropertyTest
4
+ attr_reader :mirror_indent
5
+
6
+ context "always" do
7
+ setup do
8
+ @mirror_indent = Rocx::Properties::MirrorIndent.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :mirrorIndent, mirror_indent.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "mirror_indent", mirror_indent.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @mirror_indent = Rocx::Properties::MirrorIndent.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:mirrorIndent/>", xml(mirror_indent)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @mirror_indent = Rocx::Properties::MirrorIndent.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(mirror_indent)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @mirror_indent = Rocx::Properties::MirrorIndent.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(mirror_indent)
47
+ end
48
+ end
49
+
50
+ end