diff --git a/lib/phlex/elements.rb b/lib/phlex/elements.rb index 50e3c3c4..4a5e1bd3 100644 --- a/lib/phlex/elements.rb +++ b/lib/phlex/elements.rb @@ -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 `` # 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 @@ -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 diff --git a/lib/phlex/html/void_elements.rb b/lib/phlex/html/void_elements.rb index c237cce2..2a7d21c8 100644 --- a/lib/phlex/html/void_elements.rb +++ b/lib/phlex/html/void_elements.rb @@ -62,7 +62,7 @@ module Phlex::HTML::VoidElements # Outputs a `` 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 tag is deprecated. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/param" # @!method source(**attributes, &content) # Outputs a `` tag.