lib/live/view.rb in live-0.8.1 vs lib/live/view.rb in live-0.9.0

- old
+ new

@@ -7,33 +7,43 @@ require 'xrb/builder' module Live # Represents a single division of content on the page an provides helpers for rendering the content. class View < Element + def script(code, **options) + rpc(:script, @id, code, options) + end + # Update the content of the client-side element by rendering this view. def update!(**options) rpc(:update, @id, self.to_html, options) end # 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. # @parameter selector [String] The CSS selector to remove. def remove(selector, **options)