Class: Alchemy::Ingredients::LinkView

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

Constant Summary

Constants included from LinkTarget

Alchemy::Ingredients::LinkTarget::BLANK_VALUE, Alchemy::Ingredients::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, text: nil, html_options: {}) ⇒ LinkView

Returns a new instance of LinkView.

Parameters:

  • ingredient (Alchemy::Ingredient)
  • text (String) (defaults to: nil)

    The link text. If not given, the ingredient’s text setting or the value will be used.

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

    Options that will be passed to the a tag.



11
12
13
14
# File 'app/components/alchemy/ingredients/link_view.rb', line 11

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

Instance Attribute Details

Returns the value of attribute link_text.



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

def link_text
  @link_text
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
# File 'app/components/alchemy/ingredients/link_view.rb', line 16

def call
  target = ingredient.link_target.presence
  link_to(link_text, value, {
    target: link_target_value(target),
    rel: link_rel_value(target)
  }.merge(html_options)).html_safe
end