Skip to content

Commit 414ba61

Browse files
authored
Merge pull request #64 from openxml/toggle-to-onoff
Reimplement ToggleProperty in terms of OnOffProperty
2 parents 9529856 + 2284a8f commit 414ba61

48 files changed

Lines changed: 182 additions & 190 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/openxml/docx/properties.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module Properties
1414
require "openxml/docx/properties/string_property"
1515
require "openxml/docx/properties/on_off_property"
1616
require "openxml/docx/properties/toggle_property"
17-
require "openxml/docx/properties/explicit_toggle_property"
1817
require "openxml/docx/properties/string_property"
1918
require "openxml/docx/properties/container_property"
2019
require "openxml/docx/properties/transparent_container_property"

lib/openxml/docx/properties/bold.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module OpenXml
22
module Docx
33
module Properties
4-
class Bold < ExplicitToggleProperty
4+
class Bold < ToggleProperty
55
tag :b
66

77
end

lib/openxml/docx/properties/explicit_toggle_property.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/openxml/docx/properties/italics.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module OpenXml
22
module Docx
33
module Properties
4-
class Italics < ExplicitToggleProperty
4+
class Italics < ToggleProperty
55
tag :i
66

77
end

lib/openxml/docx/properties/on_off_property.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ module Properties
44
class OnOffProperty < ValueProperty
55

66
def ok_values
7-
[nil, :on, :off]
7+
[true, false, :on, :off] # :on and :off are from the Transitional Spec
88
end
99

1010
def to_xml(xml)
11-
xml["w"].public_send(tag, "w:val" => value) if value
11+
return xml["w"].public_send(tag) if value == true
12+
xml["w"].public_send(tag, "w:val" => value)
1213
end
1314

1415
end

lib/openxml/docx/properties/toggle_property.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
module OpenXml
22
module Docx
33
module Properties
4-
class ToggleProperty < ValueProperty
5-
6-
def ok_values
7-
[nil, true, false]
8-
end
9-
10-
def to_xml(xml)
11-
xml["w"].public_send(tag) if value
12-
end
13-
4+
class ToggleProperty < OnOffProperty
5+
# Toggle properties are no different in representation than on/off properties;
6+
# rather, the difference is in how they compose with one another (cf.
7+
# Section 17.7.3). It's helpful, then, to retain the concept, but entirely
8+
# unnecessary to duplicate implementation.
9+
# cf. Section A.6.9 of the spec, and Section A.7.9 of the transitional spec.
1410
end
1511
end
1612
end

spec/properties/bidi_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe OpenXml::Docx::Properties::Bidi do
44
include ValuePropertyTestMacros
55

6-
it_should_use tag: :bidi, name: "bidi"
6+
it_should_use tag: :bidi, name: "bidi", value: true
77

88
with_value(true) do
99
it_should_work
@@ -12,12 +12,11 @@
1212

1313
with_value(false) do
1414
it_should_work
15-
it_should_output ""
15+
it_should_output "<w:bidi w:val=\"false\"/>"
1616
end
1717

1818
with_value(nil) do
19-
it_should_work
20-
it_should_output ""
19+
it_should_not_work
2120
end
2221

2322
end

spec/properties/bold_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe OpenXml::Docx::Properties::Bold do
44
include ValuePropertyTestMacros
55

6-
it_should_use tag: :b, name: "bold"
6+
it_should_use tag: :b, name: "bold", value: true
77

88
with_value(true) do
99
it_should_work
@@ -16,8 +16,7 @@
1616
end
1717

1818
with_value(nil) do
19-
it_should_work
20-
it_should_output ""
19+
it_should_not_work
2120
end
2221

2322
end

spec/properties/cant_split_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe OpenXml::Docx::Properties::CantSplit do
44
include ValuePropertyTestMacros
55

6-
it_should_use tag: :cantSplit, name: "cant_split"
6+
it_should_use tag: :cantSplit, name: "cant_split", value: true
77

88
with_value(true) do
99
it_should_work
@@ -12,12 +12,11 @@
1212

1313
with_value(false) do
1414
it_should_work
15-
it_should_output ""
15+
it_should_output "<w:cantSplit w:val=\"false\"/>"
1616
end
1717

1818
with_value(nil) do
19-
it_should_work
20-
it_should_output ""
19+
it_should_not_work
2120
end
2221

2322
end

spec/properties/caps_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe OpenXml::Docx::Properties::Caps do
44
include ValuePropertyTestMacros
55

6-
it_should_use tag: :caps, name: "caps"
6+
it_should_use tag: :caps, name: "caps", value: true
77

88
with_value(true) do
99
it_should_work
@@ -12,12 +12,11 @@
1212

1313
with_value(false) do
1414
it_should_work
15-
it_should_output ""
15+
it_should_output "<w:caps w:val=\"false\"/>"
1616
end
1717

1818
with_value(nil) do
19-
it_should_work
20-
it_should_output ""
19+
it_should_not_work
2120
end
2221

2322
end

0 commit comments

Comments
 (0)