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,37 @@
1
+ require "test_helper"
2
+
3
+ class ParagraphTest < Test::Unit::TestCase
4
+ attr_reader :paragraph
5
+
6
+ context "with runs, it" do
7
+ setup do
8
+ @paragraph = Rocx::Elements::Paragraph.new
9
+ paragraph.indentation = {start: 720, end: -1440}
10
+ run = Rocx::Elements::Run.new
11
+ run << Rocx::Elements::Text.new("Hey Run 1")
12
+ paragraph << run
13
+ run = Rocx::Elements::Run.new
14
+ run << Rocx::Elements::Text.new("Hey Run 2")
15
+ paragraph << run
16
+ end
17
+
18
+ should "generate the proper XML" do
19
+ paragraph_xml = build_xml { |xml| paragraph.to_xml(xml) }
20
+ assert_equal element_xml("paragraph_with_runs"), paragraph_xml
21
+ end
22
+ end
23
+
24
+ context "without runs, it" do
25
+ setup do
26
+ @paragraph = Rocx::Elements::Paragraph.new
27
+ paragraph.alignment = :center
28
+ end
29
+
30
+ should "also generate the proper XML" do
31
+ paragraph_xml = build_xml { |xml| paragraph.to_xml(xml) }
32
+
33
+ assert_equal element_xml("paragraph"), paragraph_xml
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ class RunTest < Test::Unit::TestCase
4
+ attr_reader :run_node
5
+
6
+ context "after creation, it" do
7
+ setup do
8
+ @run_node = Rocx::Elements::Run.new
9
+ run_node.italics = true
10
+ end
11
+
12
+ should "render properties in the properties XML" do
13
+ run_xml = build_xml { |xml| run_node.to_xml(xml) }
14
+ assert_equal element_xml("run"), run_xml
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+ class SymbolTest < Test::Unit::TestCase
4
+ attr_reader :symbol
5
+
6
+ should "require that its char property be 4 hexadecimal characters" do
7
+ @symbol = Rocx::Elements::Symbol.new
8
+ assert_raises ArgumentError do
9
+ symbol.char = "not valid"
10
+ end
11
+
12
+ assert_nothing_raised do
13
+ symbol.char = "43fd"
14
+ end
15
+ end
16
+
17
+ should "output the right XML" do
18
+ @symbol = Rocx::Elements::Symbol.new(char: "43fd", font: "Wingdings")
19
+ xml = build_xml { |xml| symbol.to_xml(xml) }
20
+ assert_equal element_xml("symbol"), xml
21
+ end
22
+
23
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+
3
+ class TextTest < Test::Unit::TestCase
4
+ attr_reader :text
5
+
6
+ should "require space to be :preserve or nil" do
7
+ assert_nothing_raised do
8
+ @text = Rocx::Elements::Text.new("Banana", space: :preserve)
9
+ end
10
+
11
+ assert_nothing_raised do
12
+ @text = Rocx::Elements::Text.new("Banana")
13
+ end
14
+
15
+ assert_raises ArgumentError do
16
+ @text = Rocx::Elements::Text.new("Banana", space: :the_final_frontier)
17
+ end
18
+ end
19
+
20
+ should "generate the proper XML" do
21
+ @text = Rocx::Elements::Text.new("Banana", space: :preserve)
22
+ text_xml = build_xml { |xml| text.to_xml(xml) }
23
+ assert_equal element_xml("text"), text_xml
24
+ end
25
+
26
+ end
@@ -0,0 +1,48 @@
1
+ require "test_helper"
2
+
3
+ class PackageTest < Test::Unit::TestCase
4
+ attr_reader :package
5
+
6
+ context "when starting a new package, it" do
7
+ setup do
8
+ @package = Rocx::Package.new
9
+ end
10
+
11
+ should "create the content types part" do
12
+ assert_is_a Rocx::Parts::ContentTypes, package.content_types
13
+ end
14
+
15
+ should "create the document part" do
16
+ assert_is_a Rocx::Parts::Document, package.document
17
+ end
18
+
19
+ should "create the global rels part" do
20
+ assert_is_a Rocx::Parts::GlobalRels, package.global_rels
21
+ end
22
+
23
+ should "create the _rels part" do
24
+ assert_is_a Rocx::Parts::Rels, package.rels
25
+ end
26
+
27
+ should "create the settings part" do
28
+ assert_is_a Rocx::Parts::Settings, package.settings
29
+ end
30
+
31
+ should "create the styles part" do
32
+ assert_is_a Rocx::Parts::Styles, package.styles
33
+ end
34
+ end
35
+
36
+ context "when saving a package, it" do
37
+ setup do
38
+ @package = Rocx::Package.new
39
+ end
40
+
41
+ should "write to a OpenXmlPackage" do
42
+ path = "some_file.docx"
43
+ mock.instance_of(OpenXmlPackage).write_to(path)
44
+ package.save(path)
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,37 @@
1
+ require "test_helper"
2
+
3
+ class ContentTypesTest < Test::Unit::TestCase
4
+ attr_reader :content_types
5
+
6
+ context "when first creating the content types, it" do
7
+ setup do
8
+ @content_types = Rocx::Parts::ContentTypes.new
9
+ end
10
+
11
+ should "install the preset defaults" do
12
+ assert_equal 3, content_types.defaults.length, "Expected the number of defaults generated to match the number of preset defaults"
13
+ end
14
+
15
+ should "install the preset overrides" do
16
+ assert_equal 2, content_types.overrides.length, "Expected the number of overrides generated to match the number of preset overrides"
17
+ end
18
+ end
19
+
20
+ context "after initially creating the content types, it" do
21
+ setup do
22
+ @content_types = Rocx::Parts::ContentTypes.new
23
+ end
24
+
25
+ should "be able to add additional defaults" do
26
+ content_types.default "coolml", "text/coolml"
27
+ assert content_types.defaults.member?({"Extension" => "coolml", "ContentType" => "text/coolml"})
28
+ end
29
+ end
30
+
31
+ context "transforming to XML" do
32
+ should "output the correct XML" do
33
+ @content_types = Rocx::Parts::ContentTypes.new
34
+ assert_equal part_xml('content_types').strip, content_types.read
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ require "test_helper"
2
+
3
+ class DocumentTest < Test::Unit::TestCase
4
+ attr_reader :document
5
+
6
+ context "with child elements, it" do
7
+ setup do
8
+ @document = Rocx::Parts::Document.new
9
+ paragraph = Rocx::Elements::Paragraph.new
10
+ first_run = Rocx::Elements::Run.new
11
+ first_run << Rocx::Elements::Text.new("This is just a test run.")
12
+ paragraph << first_run
13
+ second_run = Rocx::Elements::Run.new
14
+ second_run << Rocx::Elements::Text.new("But this isn't!")
15
+ paragraph << second_run
16
+ document << paragraph
17
+ end
18
+
19
+ should "output the correct XML" do
20
+ assert_equal part_xml("document_with_children").strip, document.read
21
+ end
22
+ end
23
+
24
+ context "transforming to XML" do
25
+ should "output the correct XML" do
26
+ @document = Rocx::Parts::Document.new
27
+ assert_equal part_xml("empty_document").strip, document.read
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class GlobalRelsTest < Test::Unit::TestCase
4
+ attr_reader :global_rels
5
+
6
+ context "transforming to XML" do
7
+ should "output the correct XML" do
8
+ @global_rels = Rocx::Parts::GlobalRels.new
9
+ assert_equal part_xml('global_rels').strip, global_rels.read
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,48 @@
1
+ require "test_helper"
2
+
3
+ class RelsTest < Test::Unit::TestCase
4
+ attr_reader :rels
5
+
6
+ context "when initially setting up the rels, it" do
7
+ setup do
8
+ @rels = Rocx::Parts::Rels.new
9
+ end
10
+
11
+ should "automatically create the relationship to the settings file" do
12
+ expected_relation = { "Type" => "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
13
+ "Target" => "/word/settings.xml",
14
+ "Id" => "R1efaa81aac7a4831" }
15
+ assert rels.relationships.member?(expected_relation), "Expected the default settings relation to be present"
16
+ end
17
+
18
+ should "automatically create the relationship to the styles file" do
19
+ expected_relation = { "Type" => "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
20
+ "Target" => "/word/styles.xml",
21
+ "Id" => "Rf06246a95c004384" }
22
+ assert rels.relationships.member?(expected_relation), "Expected the default styles relation to be present"
23
+ end
24
+ end
25
+
26
+ context "after setting up the rels, it" do
27
+ setup do
28
+ @rels = Rocx::Parts::Rels.new
29
+ end
30
+
31
+ should "be possible to add additional relationships" do
32
+ new_relationship = { "Type" => "http://coolml.org/coolDocument",
33
+ "Target" => "/cool/cool.xml",
34
+ "Id" => "123456789"
35
+ }
36
+ rels.relationship *new_relationship.values
37
+ assert rels.relationships.member?(new_relationship), "Expected the new relationship to have been added"
38
+ end
39
+ end
40
+
41
+ context "transforming to XML" do
42
+ should "output the correct XML" do
43
+ @rels = Rocx::Parts::Rels.new
44
+ assert_equal part_xml('rels').strip, rels.read
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class SettingsTest < Test::Unit::TestCase
4
+ attr_reader :settings
5
+
6
+ context "transforming to XML" do
7
+ should "output the correct XML" do
8
+ @settings = Rocx::Parts::Settings.new
9
+ assert_equal part_xml('settings').strip, settings.read
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class StylesTest < Test::Unit::TestCase
4
+ attr_reader :styles
5
+
6
+ context "adding a custom style" do
7
+ setup do
8
+ paragraph_styles = {
9
+ "w:ind" => {"w:firstLine" => "0", "w:left" => "0", "w:right" => "0"},
10
+ "w:jc" => {"w:val" => "left"}
11
+ }
12
+ style = Rocx::Style.new("coolStyle", "paragraph", {}, paragraph_styles)
13
+ @styles = Rocx::Parts::Styles.new
14
+ styles << style
15
+ end
16
+
17
+ should "output the style in the generated XML" do
18
+ assert_equal part_xml("styles_with_custom_style").strip, styles.read
19
+ end
20
+ end
21
+
22
+ context "transforming to XML" do
23
+ should "output the correct XML" do
24
+ @styles = Rocx::Parts::Styles.new
25
+ assert_equal part_xml('styles').strip, styles.read
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class AutoAdjustRightIndentTest < PropertyTest
4
+ attr_reader :auto_adjust_right_ind
5
+
6
+ context "always" do
7
+ setup do
8
+ @auto_adjust_right_ind = Rocx::Properties::AutoAdjustRightIndent.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :adjustRightInd, auto_adjust_right_ind.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "auto_adjust_right_ind", auto_adjust_right_ind.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @auto_adjust_right_ind = Rocx::Properties::AutoAdjustRightIndent.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:adjustRightInd w:val=\"true\"/>", xml(auto_adjust_right_ind)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @auto_adjust_right_ind = Rocx::Properties::AutoAdjustRightIndent.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(auto_adjust_right_ind)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @auto_adjust_right_ind = Rocx::Properties::AutoAdjustRightIndent.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(auto_adjust_right_ind)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class AutoSpaceDeTest < PropertyTest
4
+ attr_reader :auto_space_de
5
+
6
+ context "always" do
7
+ setup do
8
+ @auto_space_de = Rocx::Properties::AutoSpaceDe.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :autoSpaceDE, auto_space_de.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "auto_space_de", auto_space_de.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @auto_space_de = Rocx::Properties::AutoSpaceDe.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:autoSpaceDE w:val=\"true\"/>", xml(auto_space_de)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @auto_space_de = Rocx::Properties::AutoSpaceDe.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(auto_space_de)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @auto_space_de = Rocx::Properties::AutoSpaceDe.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(auto_space_de)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class AutoSpaceDnTest < PropertyTest
4
+ attr_reader :auto_space_dn
5
+
6
+ context "always" do
7
+ setup do
8
+ @auto_space_dn = Rocx::Properties::AutoSpaceDn.new(false)
9
+ end
10
+
11
+ should "have the right tag" do
12
+ assert_equal :autoSpaceDN, auto_space_dn.tag
13
+ end
14
+
15
+ should "have the right name" do
16
+ assert_equal "auto_space_dn", auto_space_dn.name
17
+ end
18
+ end
19
+
20
+ context "when the value is true, it" do
21
+ setup do
22
+ @auto_space_dn = Rocx::Properties::AutoSpaceDn.new(true)
23
+ end
24
+
25
+ should "return XML" do
26
+ assert_equal "<w:autoSpaceDN w:val=\"true\"/>", xml(auto_space_dn)
27
+ end
28
+ end
29
+
30
+ context "when the value is false, it" do
31
+ setup do
32
+ @auto_space_dn = Rocx::Properties::AutoSpaceDn.new(false)
33
+ end
34
+
35
+ should "not return XML" do
36
+ assert_equal "", xml(auto_space_dn)
37
+ end
38
+ end
39
+
40
+ context "when the value is nil, it" do
41
+ setup do
42
+ @auto_space_dn = Rocx::Properties::AutoSpaceDn.new(nil)
43
+ end
44
+
45
+ should "not return XML" do
46
+ assert_equal "", xml(auto_space_dn)
47
+ end
48
+ end
49
+
50
+ end