Skip to content

Commit

Permalink
Be a little more opinionated about replace, prepend and append
Browse files Browse the repository at this point in the history
…fragment generation.
  • Loading branch information
ioquatix committed May 6, 2024
1 parent fbc2a9d commit c649e6c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/live/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ def update!(**options)
# Replace the content of the client-side element by rendering this view.
# @parameter selector [String] The CSS selector to replace.
# @parameter node [String] The HTML to replace.
def replace(selector, node, **options)
rpc(:replace, selector, node.to_s, options)
def replace(selector, fragment = nil, **options, &block)
fragment ||= XRB::Builder.fragment(&block)

rpc(:replace, selector, fragment.to_s, options)
end

# Prepend to the content of the client-side element by appending the specified element.
# @parameter selector [String] The CSS selector to prepend to.
# @parameter node [String] The HTML to prepend.
def prepend(selector, node, **options)
rpc(:prepend, selector, node.to_s, options)
def prepend(selector, fragment = nil, **options, &block)
fragment ||= XRB::Builder.fragment(&block)

rpc(:prepend, selector, fragment.to_s, options)
end

# Append to the content of the client-side element by appending the specified element.
# @parameter selector [String] The CSS selector to append to.
# @parameter node [String] The HTML to prepend.
def append(selector, node, **options)
rpc(:append, selector, node.to_s, options)
def append(selector, fragment = nil, **options, &block)
fragment ||= XRB::Builder.fragment(&block)

rpc(:append, selector, fragment.to_s, options)
end

# Remove the specified element from the client-side element.
Expand Down

0 comments on commit c649e6c

Please sign in to comment.