Skip to content

Commit e32fdf0

Browse files
authored
Merge pull request #79 from mvz/add-hyperlink-element
Add Hyperlink element
2 parents 10eb016 + 800549a commit e32fdf0

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class OpenXml::Docx::Elements::Hyperlink < OpenXml::Docx::Element
2+
include OpenXml::HasChildren
3+
4+
tag :hyperlink
5+
6+
with_namespace :r do
7+
attribute :id
8+
end
9+
end

spec/elements/hyperlink_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require "spec_helper"
2+
3+
describe OpenXml::Docx::Elements::Hyperlink do
4+
include ElementTestMacros
5+
6+
it_should_use tag: :hyperlink, name: "hyperlink"
7+
8+
with_no_attributes_set do
9+
it_should_output "<w:hyperlink/>", assign: false
10+
end
11+
12+
for_attribute(:id) do
13+
with_value(23) do
14+
it_should_assign_successfully
15+
it_should_output "<w:hyperlink r:id=\"23\"/>"
16+
end
17+
end
18+
19+
context "with children" do
20+
before do
21+
@instance = described_class.new
22+
text = OpenXml::Docx::Elements::Text.new("Smucker's Preserves")
23+
run = OpenXml::Docx::Elements::Run.new
24+
run << text
25+
instance << run
26+
instance.id = 7346
27+
end
28+
29+
it_should_output <<~XML.chomp, assign: false
30+
<w:hyperlink r:id="7346">
31+
<w:r>
32+
<w:t>Smucker's Preserves</w:t>
33+
</w:r>
34+
</w:hyperlink>
35+
XML
36+
end
37+
end

0 commit comments

Comments
 (0)