By using reverse merge and passing in the entire options to the content tag (or to content tag to be used in partials), we can glob all things like data or aria or whatever else is passed into options correctly while still providing defaults, including merging tailwind classes with custom classes provided. As opposed to:
def render_table(caption = nil, **options, &block)
options[:class] = tw("w-full text-sm border-b", options[:class])
content_tag :table, class: options[:class] do
if caption.present?
content_tag :caption, caption, class: "mt-4 text-sm text-muted-foreground " do
capture(&block)
end
else
capture(&block)
end
end
end
Here by explicitly only handling the class of options, something like data: {controller:} would be missed.
By using reverse merge and passing in the entire options to the content tag (or to content tag to be used in partials), we can glob all things like
data
oraria
or whatever else is passed into options correctly while still providing defaults, including merging tailwind classes with custom classes provided. As opposed to:Here by explicitly only handling the
class
of options, something likedata: {controller:}
would be missed.