Module: ViewComponent::ContentAreas

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/view_component/content_areas.rb

Instance Method Summary collapse

Instance Method Details

#with(area, content = nil, &block) ⇒ Object

Assign the provided content to the content area accessor



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/view_component/content_areas.rb', line 15

def with(area, content = nil, &block)
  unless content_areas.include?(area)
    raise ArgumentError.new(
      "Unknown content_area '#{area}' for #{self} - expected one of '#{content_areas}'.\n\n" \
      "To fix this issue, add `with_content_area :#{area}` to #{self} or reference " \
      "a valid content area."
    )
  end

  if block_given?
    content = view_context.capture(&block)
  end

  instance_variable_set("@#{area}".to_sym, content)
  nil
end