Module: Cocooned::Helpers::Containers

Defined in:
lib/cocooned/helpers/containers.rb

Overview

Cocooned containers helpers output container or item wrappers as expected by the JavaScript companion package.

Instance Method Summary collapse

Instance Method Details

#cocooned_container(*args, &block) ⇒ Object

Wrap content with the expected markup for a Cocooned container.

This is a wrapper around ‘ActionView::Base#content_tag` to automatically add default classes and data-attributes that define a Cocooned container.

Signatures

cocooned_container(*arguments, **options) do
  # Container content
end

Parameters

‘cocooned_container` supports following options:

  • ‘:limit` [Integer] Enable the limit plugin and set the accepted maximum number of items

  • ‘:reorderable` [Boolean|Hash] Enable the reorderable plugin. When a boolean, use plugin’s default. You can also pass a Hash with explicit options (ex: ‘{ startAt: 1 }`).

Any other argument or option supported by ‘ActionView::Base#content_tag` will be forwarded.



32
33
34
35
36
37
38
39
# File 'lib/cocooned/helpers/containers.rb', line 32

def cocooned_container(*args, &block)
  options = args.extract_options!.dup
  name = args.shift || :div
  defaults = cocooned_wrapper_defaults(options, %w[cocooned-container], :'cocooned-container')
  defaults[:data][:cocooned_options] = options.extract!(:limit, :reorderable).to_json

  (name, *args, **options.deep_merge(defaults), &block)
end

#cocooned_item(*args, &block) ⇒ Object

Wrap content with the expected markup for a Cocooned item.

This is a wrapper around ‘ActionView::Base#content_tag` to automatically add default classes and data-attributes that define a Cocooned item.

Signatures

cocooned_item(*arguments, **options) do
  # Item content
end

Parameters

Any argument or option supported by ‘ActionView::Base#content_tag` will be forwarded.



56
57
58
59
60
61
62
# File 'lib/cocooned/helpers/containers.rb', line 56

def cocooned_item(*args, &block)
  options = args.extract_options!.dup
  name = args.shift || :div
  defaults = cocooned_wrapper_defaults(options, %w[cocooned-item nested-fields], :'cocooned-item')

  (name, *args, **options.deep_merge(defaults), &block)
end