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,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class ContextualSpacing < ToggleProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ module Rocx
2
+ module Properties
3
+ class DivId < BaseProperty
4
+
5
+ def valid?
6
+ value.is_a?(Integer)
7
+ end
8
+
9
+ def invalid_message
10
+ "Invalid value for #{name}; acceptable values are integers"
11
+ end
12
+
13
+ def tag
14
+ :divId
15
+ end
16
+
17
+ def to_xml(xml)
18
+ xml["w"].public_send(tag, "w:val" => value)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ module Rocx
2
+ module Properties
3
+ class Indentation
4
+ attr_reader :value
5
+
6
+ OK_KEYS = [:end, :endChars, :firstLine, :firstLineChars, :hanging, :hangingChars, :start, :startChars]
7
+
8
+ def initialize(value)
9
+ @value = value
10
+ raise ArgumentError invalid_message unless valid?
11
+ end
12
+
13
+ def invalid_message
14
+ "Invalid value for indentation"
15
+ end
16
+
17
+ def valid?
18
+ value.keys.all?(&OK_KEYS.method(:member?))
19
+ end
20
+
21
+ def to_xml(xml)
22
+ return unless value.length > 0
23
+ namespaced_values = value.each_with_object({}) do |(prop, value), values|
24
+ values["w:#{prop}"] = value
25
+ end
26
+ xml["w"].ind(namespaced_values) if value
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ module Rocx
2
+ module Properties
3
+ class Italics < ToggleProperty
4
+
5
+ def tag
6
+ :i
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class KeepLines < ToggleProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class KeepNext < ToggleProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class Kinsoku < OnOffProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class MirrorIndent < ToggleProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ module Rocx
2
+ module Properties
3
+ class OnOffProperty < BaseProperty
4
+
5
+ def ok_values
6
+ [nil, :on, :off]
7
+ end
8
+
9
+ def to_xml(xml)
10
+ xml["w"].public_send(tag, "w:val" => value) if value
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Rocx
2
+ module Properties
3
+ class OutlineLevel < BaseProperty
4
+
5
+ def valid?
6
+ value.is_a?(Integer) && value >= 0
7
+ end
8
+
9
+ def invalid_message
10
+ "Invalid value for #{name}; acceptable values are integers greater than or equal to 0"
11
+ end
12
+
13
+ def tag
14
+ :outlineLvl
15
+ end
16
+
17
+ def to_xml(xml)
18
+ xml["w"].public_send(tag, "w:val" => value)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module Rocx
2
+ module Properties
3
+ class OverflowPunctuation < BooleanProperty
4
+
5
+ def name
6
+ "overflow_punctuation"
7
+ end
8
+
9
+ def tag
10
+ :overflowPunct
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class PageBreakBefore < ToggleProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class SnapToGrid < OnOffProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class SupressAutoHyphens < ToggleProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class SupressLineNumbers < ToggleProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class SupressOverlap < ToggleProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ module Rocx
2
+ module Properties
3
+ class ToggleProperty < BaseProperty
4
+
5
+ def ok_values
6
+ [nil, true, false]
7
+ end
8
+
9
+ def to_xml(xml)
10
+ xml["w"].public_send(tag) if value
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class WidowControl < OnOffProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rocx
2
+ module Properties
3
+ class WordWrap < OnOffProperty
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ module Rocx
2
+ class Style
3
+ attr_reader :name, :type, :run, :paragraph
4
+
5
+ def initialize(name, type, run={}, paragraph={})
6
+ @name = name
7
+ @type = type
8
+ @run = run
9
+ @paragraph = paragraph
10
+ end
11
+
12
+ def build_xml(xml)
13
+ xml["w"].style("w:styleId" => name, "w:type" => type) {
14
+ xml["w"].name("w:val" => name)
15
+ paragraph_as_xml(xml)
16
+ run_as_xml(xml)
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def paragraph_as_xml(xml)
23
+ xml["w"].pPr { xml_properties(xml, paragraph) }
24
+ end
25
+
26
+ def run_as_xml(xml)
27
+ xml["w"].rPr { xml_properties(xml, run) }
28
+ end
29
+
30
+ def xml_properties(xml, properties)
31
+ properties.each do |property, options|
32
+ namespace, tag = property.split(":")
33
+ xml[namespace].send(tag, options)
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Rocx
2
+ VERSION = "0.5.6"
3
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rocx/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rocx"
8
+ gem.version = Rocx::VERSION
9
+ gem.authors = ["Gene Doyel"]
10
+ gem.email = ["gene.doyel@cph.org"]
11
+ gem.description = %q{Create Microsoft Word (.docx) files.}
12
+ gem.summary = %q{Using a simple API, create docx files programmatically, including bullet points, titles, headings, page breaks and tables!}
13
+ gem.homepage = "https://github.com/genebot/rocx"
14
+ gem.required_ruby_version = "~> 2.0"
15
+
16
+ gem.add_dependency "nokogiri"
17
+ gem.add_dependency "open_xml_package"
18
+
19
+ gem.add_development_dependency "pry"
20
+ gem.add_development_dependency "turn"
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rr"
23
+ gem.add_development_dependency "shoulda-context"
24
+ gem.add_development_dependency "simplecov"
25
+ gem.add_development_dependency "timecop"
26
+
27
+ gem.files = `git ls-files`.split($/)
28
+ gem.test_files = Dir.glob('test/**/*_test.rb')
29
+ gem.require_paths = ["lib"]
30
+ end
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <root xmlns:w="http://wnamespace.org">
3
+ <w:br/>
4
+ </root>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <root xmlns:w="http://wnamespace.org">
3
+ <w:br w:type="page" w:clear="left"/>
4
+ </root>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0"?>
2
+ <root xmlns:w="http://wnamespace.org">
3
+ <w:p>
4
+ <w:pPr>
5
+ <w:jc w:val="center"/>
6
+ </w:pPr>
7
+ </w:p>
8
+ </root>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0"?>
2
+ <root xmlns:w="http://wnamespace.org">
3
+ <w:p>
4
+ <w:pPr>
5
+ <w:ind w:start="720" w:end="-1440"/>
6
+ </w:pPr>
7
+ <w:r>
8
+ <w:t>Hey Run 1</w:t>
9
+ </w:r>
10
+ <w:r>
11
+ <w:t>Hey Run 2</w:t>
12
+ </w:r>
13
+ </w:p>
14
+ </root>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0"?>
2
+ <root xmlns:w="http://wnamespace.org">
3
+ <w:r>
4
+ <w:rPr>
5
+ <w:i/>
6
+ </w:rPr>
7
+ </w:r>
8
+ </root>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <root xmlns:w="http://wnamespace.org">
3
+ <w:sym w:font="Wingdings" w:char="43fd"/>
4
+ </root>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <root xmlns:w="http://wnamespace.org">
3
+ <w:t xml:space="preserve">Banana</w:t>
4
+ </root>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="png" ContentType="image/png"/><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/><Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"/></Types>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8"?><w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="w14 wp14"><w:body><w:p><w:r><w:t>This is just a test run.</w:t></w:r><w:r><w:t>But this isn't!</w:t></w:r></w:p></w:body></w:document>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8"?><w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="w14 wp14"><w:body/></w:document>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="/word/document.xml" Id="R08806881ac3c45ac"/></Relationships>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="/word/styles.xml" Id="Rf06246a95c004384"/><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="/word/settings.xml" Id="R1efaa81aac7a4831"/></Relationships>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="yes"?><w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"/>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="yes"?><w:styles xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:docDefaults><w:rPrDefault><w:rPr><w:lang w:bidi="ar-SA" w:eastAsia="en-US" w:val="en-US"/></w:rPr></w:rPrDefault><w:pPrDefault><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr></w:pPrDefault></w:docDefaults></w:styles>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="yes"?><w:styles xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:docDefaults><w:rPrDefault><w:rPr><w:lang w:bidi="ar-SA" w:eastAsia="en-US" w:val="en-US"/></w:rPr></w:rPrDefault><w:pPrDefault><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr></w:pPrDefault></w:docDefaults><w:style w:styleId="coolStyle" w:type="paragraph"><w:name w:val="coolStyle"/><w:pPr><w:ind w:firstLine="0" w:left="0" w:right="0"/><w:jc w:val="left"/></w:pPr><w:rPr/></w:style></w:styles>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+ <styleFoo xmlns:w="http://wnamespace.com">
3
+ <w:style w:styleId="anotherCoolStyle" w:type="character">
4
+ <w:name w:val="anotherCoolStyle"/>
5
+ <w:pPr/>
6
+ <w:rPr>
7
+ <w:rFonts w:ascii="Times New Roman" w:cs="Times New Roman" w:hAnsi="Times New Roman"/>
8
+ <w:color w:val="FF0000"/>
9
+ <w:sz w:val="20"/>
10
+ <w:b w:val="0"/>
11
+ <w:i w:val="0"/>
12
+ <w:u w:val="none"/>
13
+ </w:rPr>
14
+ </w:style>
15
+ </styleFoo>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0"?>
2
+ <styleFoo xmlns:w="http://wnamespace.com">
3
+ <w:style w:styleId="coolStyle" w:type="paragraph">
4
+ <w:name w:val="coolStyle"/>
5
+ <w:pPr>
6
+ <w:ind w:firstLine="0" w:left="0" w:right="0"/>
7
+ <w:jc w:val="left"/>
8
+ </w:pPr>
9
+ <w:rPr/>
10
+ </w:style>
11
+ </styleFoo>
@@ -0,0 +1,54 @@
1
+ require "test_helper"
2
+
3
+ class BreakTest < Test::Unit::TestCase
4
+ attr_reader :break_node
5
+
6
+ context "when creating a new break, it" do
7
+ should "not accept invalid values for the clear property" do
8
+ assert_raises ArgumentError do
9
+ @break_node = Rocx::Elements::Break.new(clear: :obviouslyInvalid)
10
+ end
11
+ end
12
+
13
+ should "not accept invalid values for the break_type property" do
14
+ assert_raises ArgumentError do
15
+ @break_node = Rocx::Elements::Break.new(break_type: :invalidType)
16
+ end
17
+ end
18
+ end
19
+
20
+ context "after initial creation, it" do
21
+ should "still not accept invalid values for the clear property" do
22
+ assert_raises ArgumentError do
23
+ @break_node = Rocx::Elements::Break.new
24
+ break_node.clear = :invalid
25
+ end
26
+ end
27
+
28
+ should "still not accept invalid values for the break_type property" do
29
+ assert_raises ArgumentError do
30
+ @break_node = Rocx::Elements::Break.new
31
+ break_node.break_type :weird
32
+ end
33
+ end
34
+ end
35
+
36
+ context "when generating XML" do
37
+ context "and both property is nil, it" do
38
+ should "omit the attributes" do
39
+ @break_node = Rocx::Elements::Break.new
40
+ break_xml = build_xml { |xml| break_node.to_xml(xml) }
41
+ assert_equal element_xml("break"), break_xml
42
+ end
43
+ end
44
+
45
+ context "and a property isn't nil, it" do
46
+ should "include that attribute" do
47
+ @break_node = Rocx::Elements::Break.new(break_type: :page, clear: :left)
48
+ break_xml = build_xml { |xml| break_node.to_xml(xml) }
49
+ assert_equal element_xml("break_with_attributes"), break_xml
50
+ end
51
+ end
52
+ end
53
+
54
+ end