Skip to content

Commit

Permalink
Added the #subscript helper
Browse files Browse the repository at this point in the history
  • Loading branch information
vjt committed Sep 14, 2010
1 parent 594ee20 commit ae048a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES
@@ -1,5 +1,8 @@
== CHANGES

0.3.1
* Added the #subscript helper to the CommandNode class

0.3.0
* Resolve problems on Ruby 1.9.1 with ImageNode#read_source. Peter uses IO#getc, which returns a String on Ruby 1.9.1, not a Integer, so I replaced with getbyte. [clbustos]
* Deleted duplicated definition of ImageNode#style= with attr_writer and def. [clbustos]
17 changes: 16 additions & 1 deletion lib/rtf/node.rb
Expand Up @@ -394,6 +394,21 @@ def underline
end
end

# This method provides a short cut means of creating a subscript command
# node. The method accepts a block that will be passed a single parameter
# which will be a reference to the subscript node created. After the
# block is complete the subscript node is appended to the end of the
# child nodes on the object that the method is call against.
def subscript
style = CharacterStyle.new
style.subscript = true
if block_given?
apply(style) {|node| yield node}
else
apply(style)
end
end

# This method provides a short cut means of creating a superscript command
# node. The method accepts a block that will be passed a single parameter
# which will be a reference to the superscript node created. After the
Expand Down Expand Up @@ -1662,4 +1677,4 @@ def to_rtf
text.string
end
end # End of the Document class.
end # End of the RTF module.
end # End of the RTF module.
5 changes: 5 additions & 0 deletions test/command_node_test.rb
Expand Up @@ -156,6 +156,11 @@ def test_style
assert(node.prefix == '\super')
assert(node.suffix == nil)
assert(node == root[-1])

node = root.subscript
assert(node.prefix == '\sub')
assert(node.suffix == nil)
assert(node == root[-1])
end

# Test text node addition.
Expand Down

0 comments on commit ae048a8

Please sign in to comment.