Class: Sablon::HTMLConverter::Hyperlink

Inherits:
Node
  • Object
show all
Defined in:
lib/sablon/html/ast.rb

Overview

Creates a clickable URL in the word document, this only supports external urls only

Constant Summary

Constants inherited from Node

Node::PROPERTIES

Instance Method Summary collapse

Methods inherited from Node

convert_style_property, node_name, process_properties, style_conversion

Constructor Details

#initialize(env, node, properties) ⇒ Hyperlink

Returns a new instance of Hyperlink.



529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/sablon/html/ast.rb', line 529

def initialize(env, node, properties)
  super
  # properties are passed directly to runs because hyperlink nodes
  # don't have a corresponding property tag like runs or paragraphs.
  @runs = ASTBuilder.html_to_ast(env, node.children, properties)
  @runs = Collection.new(@runs)
  @target = node.attributes['href'].value
  #
  rel_attr = {
    Type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
    Target: @target,
    TargetMode: 'External'
  }
  rid = env.document.add_relationship(rel_attr)
  @attributes = { 'r:id' => rid }
end

Instance Method Details

#accept(visitor) ⇒ Object



554
555
556
557
# File 'lib/sablon/html/ast.rb', line 554

def accept(visitor)
  super
  @runs.accept(visitor)
end

#inspectObject



550
551
552
# File 'lib/sablon/html/ast.rb', line 550

def inspect
  "<Hyperlink{target:#{@target}}: #{@runs.inspect}>"
end

#to_docxObject



546
547
548
# File 'lib/sablon/html/ast.rb', line 546

def to_docx
  super('w:hyperlink')
end