Class: Alchemy::Ingredients::TextView

Inherits:
BaseView
  • Object
show all
Includes:
LinkTarget
Defined in:
app/components/alchemy/ingredients/text_view.rb

Constant Summary

Constants included from LinkTarget

LinkTarget::BLANK_VALUE, LinkTarget::REL_VALUE

Instance Attribute Summary collapse

Attributes inherited from BaseView

#html_options, #ingredient

Instance Method Summary collapse

Methods included from LinkTarget

#link_rel_value, #link_target_value

Methods inherited from BaseView

#render?

Constructor Details

#initialize(ingredient, disable_link: nil, html_options: {}) ⇒ TextView

Returns a new instance of TextView.

Parameters:

  • ingredient (Alchemy::Ingredient)
  • disable_link (Boolean) (defaults to: nil)

    (false) Whether to disable the link even if the picture has a link.

  • html_options (Hash) (defaults to: {})

    Options that will be passed to the a tag.



14
15
16
17
# File 'app/components/alchemy/ingredients/text_view.rb', line 14

def initialize(ingredient, disable_link: nil, html_options: {})
  super(ingredient, html_options: html_options)
  @disable_link = settings_value(:disable_link, value: disable_link, default: false)
end

Instance Attribute Details

Returns the value of attribute disable_link.



6
7
8
# File 'app/components/alchemy/ingredients/text_view.rb', line 6

def disable_link
  @disable_link
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/components/alchemy/ingredients/text_view.rb', line 19

def call
  if disable_link?
    dom_id.present? ? anchor : value
  else
    link_to(value, url_for(link), {
      id: dom_id.presence,
      title: link_title,
      target: link_target_value(link_target),
      rel: link_rel_value(link_target)
    }.merge(html_options))
  end.html_safe
end