Class: Alchemy::Ingredients::TextView

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

Instance Attribute Summary collapse

Attributes inherited from BaseView

#html_options, #ingredient

Instance Method Summary collapse

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.



12
13
14
15
# File 'app/components/alchemy/ingredients/text_view.rb', line 12

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.



4
5
6
# File 'app/components/alchemy/ingredients/text_view.rb', line 4

def disable_link
  @disable_link
end

Instance Method Details

#callObject



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

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 == "blank") ? "_blank" : nil),
      data: {link_target: link_target}
    }.merge(html_options))
  end
end