-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn about deprecated element methods #649
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,10 @@ def register_element(method_name, tag: nil, deprecated: false) | |
# frozen_string_literal: true | ||
|
||
def #{method_name}(**attributes, &block) | ||
if #{deprecated} | ||
Kernel.warn("`#{method_name}` and `_#{method_name}` are deprecated and will be unsupported in Phlex 2.0. This HTML element is no longer recommended. Check out MDN web docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/#{tag}.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
|
||
target = @_context.target | ||
|
||
if attributes.length > 0 # with attributes | ||
|
@@ -74,6 +78,10 @@ def register_void_element(method_name, tag: method_name.name.tr("_", "-"), depre | |
# frozen_string_literal: true | ||
|
||
def #{method_name}(**attributes) | ||
if #{deprecated} | ||
Kernel.warn("`#{method_name}` and `_#{method_name}` are deprecated and will be unsupported in Phlex 2.0. This HTML element is no longer recommended. Check out MDN web docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/#{tag}.") | ||
end | ||
|
||
target = @_context.target | ||
|
||
if attributes.length > 0 # with attributes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,4 +122,40 @@ | |
end | ||
end | ||
end | ||
|
||
describe "Elements deprecation" do | ||
deprecated_methods = %i[param] | ||
|
||
deprecated_methods.each do |method_name| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it is worth testing non deprecated elements. It would be something like: [
Phlex::HTML::StandardElements.registered_elements,
Phlex::HTML::VoidElements.registered_elements
].each do |element_group|
element_group.each do |method_name, tag|
if deprecated_methods.include?(method_name)
# tests for method_name and _method_name
... warns about deprecation
else
# tests for method_name and _method_name
... doesn't warn about deprecation
end
end
end |
||
describe "##{method_name}" do | ||
view do | ||
define_method :view_template do | ||
send(method_name.to_sym) | ||
end | ||
end | ||
|
||
it "warns about `#{method_name}` deprecation" do | ||
message = capture_stderr { view.call } | ||
deprecation_message = "`#{method_name}` and `_#{method_name}` are deprecated and will be unsupported in Phlex 2.0. This HTML element is no longer recommended. Check out MDN web docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/#{method_name}." | ||
|
||
expect(message).to be == deprecation_message | ||
end | ||
end | ||
|
||
describe "#_#{method_name}" do | ||
view do | ||
define_method :view_template do | ||
send(:"_#{method_name}") | ||
end | ||
end | ||
|
||
it "warns about `_#{method_name}` deprecation" do | ||
message = capture_stderr { view.call } | ||
deprecation_message = "`#{method_name}` and `_#{method_name}` are deprecated and will be unsupported in Phlex 2.0. This HTML element is no longer recommended. Check out MDN web docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/#{method_name}." | ||
|
||
expect(message).to be == deprecation_message | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this as a module because I think it can be useful for other deprecation tests in the future.