Class: DraftjsExporter::Entities::TargetBlankLink

Inherits:
Object
  • Object
show all
Defined in:
app/models/draftjs_exporter/entities/target_blank_link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = { className: nil }) ⇒ TargetBlankLink

Returns a new instance of TargetBlankLink.



4
5
6
# File 'app/models/draftjs_exporter/entities/target_blank_link.rb', line 4

def initialize(configuration = { className: nil })
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



2
3
4
# File 'app/models/draftjs_exporter/entities/target_blank_link.rb', line 2

def configuration
  @configuration
end

Instance Method Details

#call(parent_element, data) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'app/models/draftjs_exporter/entities/target_blank_link.rb', line 8

def call(parent_element, data)
  args = { href: data.fetch(:data, {}).fetch(:url) }
  args[:class] = configuration.fetch(:className) if configuration[:className]
  args[:target] = '_blank'

  element = parent_element.document.create_element('a', args)
  parent_element.add_child(element)
  element
end