Skip to content

Commit

Permalink
Provide a better error for positional content
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Oct 10, 2022
1 parent 4b92089 commit 74c95bb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/phlex/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ def register_element(element, tag: element.name.tr("_", "-"))
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
# frozen_string_literal: true
def #{element}(**attributes, &block)
def #{element}(content = nil, **attributes, &block)
if content
raise ArgumentError, %(👋 You can no longer pass content to #{element} as a positional argument.\n Instead, you can pass it as a block, e.g. #{element} { "Hello" })
end
if attributes.length > 0
if block_given?
@_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] || _attributes(attributes)) << ">"
Expand Down

0 comments on commit 74c95bb

Please sign in to comment.