Class: Cocooned::Tags::Base

Inherits:
Object
  • Object
show all
Includes:
Deprecated::TagsHelper::DataAttributes, Deprecated::TagsHelper::DefaultLabel, Cocooned::TagsHelper::DataAttributes, Cocooned::TagsHelper::DefaultLabel
Defined in:
lib/cocooned/tags/base.rb

Overview

:nodoc:

Direct Known Subclasses

Add, Down, Remove, Up

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, form, **options, &block) ⇒ Base

Returns a new instance of Base.



22
23
24
25
26
27
# File 'lib/cocooned/tags/base.rb', line 22

def initialize(template, form, **options, &block)
  @template = template
  @form = form
  @options = options.dup.symbolize_keys
  @label_block = block if block
end

Class Method Details

.create(template, *args, **kwargs, &block) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/cocooned/tags/base.rb', line 13

def create(template, *args, **kwargs, &block)
  return new(template, *args, **kwargs, &block) if block
  return new(template, *args, **kwargs) unless args.first.is_a?(String)

  label = args.shift
  new(template, *args, **kwargs) { label }
end

Instance Method Details

#render(as: :link) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
# File 'lib/cocooned/tags/base.rb', line 29

def render(as: :link)
  return template.link_to('#', html_options) { label } if as == :link
  return template.button_tag(type: :button, **html_options) { label } if as == :button

  raise ArgumentError, "Unsupported value for :as. Expected :link or :button, got #{as}."
end