Skip to content

Commit

Permalink
raise error when component_wrapper is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
jjabari-op committed Aug 1, 2023
1 parent 48096f3 commit 33028c7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/components/concerns/op_turbo/streamable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def render_as_turbo_stream(view_context:, action: :update)
raise "Unsupported action #{action}"
end

unless @component_wrapper_used
raise "You need to wrap your component in a `component_wrapper` block in order to use the turbo-stream methods"
end

OpTurbo::StreamWrapperComponent.new(
action:,
target: wrapper_key,
Expand All @@ -58,14 +62,21 @@ def render_as_turbo_stream(view_context:, action: :update)
end

def insert_as_turbo_stream(component:, view_context:, action: :append)
template = component.render_in(view_context)

unless @component_wrapper_used
raise "You need to wrap your component in a `component_wrapper` block in order to use the turbo-stream methods"
end

OpTurbo::StreamWrapperComponent.new(
action:,
target: insert_target_modified? ? insert_target_modifier_id : wrapper_key,
template: component.render_in(view_context)
template:
).render_in(view_context)
end

def component_wrapper(tag: "div", class: nil, data: nil, style: nil, &block)
@component_wrapper_used = true
if inner_html_only?
capture(&block)
else
Expand Down

0 comments on commit 33028c7

Please sign in to comment.