Skip to content

Commit 49aaa2f

Browse files
committed
update gemspec/readme
1 parent 0baf505 commit 49aaa2f

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# docx
22

3-
a ruby library/gem for interacting with `.docx` files
3+
a ruby library/gem for interacting with `.docx` files. currently capabilities include reading paragraphs/bookmarks, inserting text at bookmarks, and saving the document.
44

55
## usage
66

@@ -10,15 +10,33 @@ requires ruby (only tested with 1.9.3 so far)
1010

1111
gem install docx
1212

13-
### basic
13+
### reading
1414

1515
``` ruby
1616
require 'docx'
1717

1818
d = Docx::Document.open('example.docx')
19-
d.each_paragraph do |p|
19+
# Array of paragraphs
20+
d.paragraphs.each do |p|
2021
puts d
2122
end
23+
24+
# Hash of Bookmarks. Bookmark names as keys correspond to bookmark objects.
25+
d.bookmarks.each_pair do |bookmark_name, bookmark_object|
26+
puts bookmark_name
27+
end
28+
```
29+
30+
### writing
31+
32+
``` ruby
33+
require 'docx'
34+
35+
d = Docx::Document.open('example.docx')
36+
# Insert a single line after a bookmark
37+
d.bookmarks['example_bookmark'].insert_after("Hello world.")
38+
# Each value in array is put on a separate line
39+
d.bookmarks['example_bookmark'].insert_multiple_lines_after(['Hello', 'World', 'foo'])
2240
```
2341

2442
### advanced
@@ -27,15 +45,16 @@ end
2745
require 'docx'
2846

2947
d = Docx::Document.open('example.docx')
30-
d.each_paragraph do |p|
31-
p.each_text_run do |run|
32-
run.italicized?
33-
run.bolded?
34-
run.underlined?
35-
run.formatting
36-
run.text
37-
end
48+
49+
# The Nokogiri node on which an element is based can be accessed using #node
50+
d.paragraphs.each do |p|
51+
puts p.node.inspect
3852
end
53+
54+
# The #xpath and #at_xpath are delegated to the node from the element, saving a step
55+
p_element = d.paragraphs.first
56+
p_children = p_element.xpath("//child::*") # selects all children
57+
p_child = p_element.at_xpath("//child::*") # selects first child
3958
```
4059

4160
## Development

docx.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
66
s.version = Docx::VERSION
77
s.summary = 'a ruby library/gem for interacting with .docx files'
88
s.description = s.summary
9-
s.author = 'Marcus Ortiz'
10-
s.email = 'mportiz08@gmail.com'
11-
s.homepage = 'https://github.com/mportiz08/docx'
9+
s.authors = ['Christopher Hunt', 'Marcus Ortiz']
10+
s.email = ['chrahunt@gmail.com']
11+
s.homepage = 'https://github.com/chrahunt/docx'
1212
s.files = Dir["README.md", "LICENSE.md", "lib/**/*.rb"]
1313

1414
s.add_dependency 'nokogiri', '~> 1.5'

0 commit comments

Comments
 (0)