Class: Maglev::Content::Link

Inherits:
Base
  • Object
show all
Defined in:
app/components/maglev/content/link.rb

Instance Attribute Summary

Attributes inherited from Base

#content, #scope, #setting

Instance Method Summary collapse

Methods inherited from Base

#asset_host, #dom_data, #initialize, #tag_data, #tag_id

Constructor Details

This class inherits a constructor from Maglev::Content::Base

Instance Method Details

#hrefObject



6
7
8
# File 'app/components/maglev/content/link.rb', line 6

def href
  link[:href]
end

#open_new_window?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/components/maglev/content/link.rb', line 18

def open_new_window?
  !!link[:open_new_window]
end

#tag(view_context, options = {}, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'app/components/maglev/content/link.rb', line 30

def tag(view_context, options = {}, &block)
  captured_content = view_context.capture(&block) if block_given?
  view_context.link_to(
    captured_content || text_tag(view_context),
    href,
    {
      data: (options.delete(:data) || {}).merge(tag_data),
      target: target_blank
    }.merge(options)
  )
end

#target_blankObject



22
23
24
# File 'app/components/maglev/content/link.rb', line 22

def target_blank
  open_new_window? ? '_blank' : nil
end

#textObject



10
11
12
# File 'app/components/maglev/content/link.rb', line 10

def text
  link[:text]
end

#to_sObject



26
27
28
# File 'app/components/maglev/content/link.rb', line 26

def to_s
  href
end

#with_text?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/components/maglev/content/link.rb', line 14

def with_text?
  !!setting.options[:with_text]
end