Skip to content

Commit

Permalink
Warn when using <param> element (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper authored Feb 19, 2024
1 parent 8bd2c7d commit a527cf9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions lib/phlex/elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ def registered_elements
# @note The methods defined by this macro depend on other methods from {SGML} so they should always be mixed into an {HTML} or {SVG} component.
# @example Register the custom element `<trix-editor>`
# register_element :trix_editor
def register_element(method_name, tag: nil, deprecated: false)
tag ||= method_name.name.tr("_", "-")
def register_element(method_name, tag: method_name.name.tr("_", "-"), deprecated: false)
if deprecated
deprecation = <<~RUBY
Kernel.warn "#{deprecated}"
RUBY
else
deprecation = ""
end

class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
# frozen_string_literal: true
def #{method_name}(**attributes, &block)
#{deprecation}
target = @_context.target
if attributes.length > 0 # with attributes
Expand Down Expand Up @@ -70,10 +77,19 @@ def #{method_name}(**attributes, &block)

# @api private
def register_void_element(method_name, tag: method_name.name.tr("_", "-"), deprecated: false)
if deprecated
deprecation = <<~RUBY
Kernel.warn "#{deprecated}"
RUBY
else
deprecation = ""
end

class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
# frozen_string_literal: true
def #{method_name}(**attributes)
#{deprecation}
target = @_context.target
if attributes.length > 0 # with attributes
Expand Down
2 changes: 1 addition & 1 deletion lib/phlex/html/void_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module Phlex::HTML::VoidElements
# Outputs a `<param>` tag.
# @return [nil]
# @see https://developer.mozilla.org/docs/Web/HTML/Element/param
register_void_element :param, deprecated: true
register_void_element :param, deprecated: "The <param> tag is deprecated. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/param"

# @!method source(**attributes, &content)
# Outputs a `<source>` tag.
Expand Down

0 comments on commit a527cf9

Please sign in to comment.