Skip to content

Commit

Permalink
Update HTML elements (#631)
Browse files Browse the repository at this point in the history
Add `<audio>`, `<base>`, `<menu>`, `<portal>`, `<search>` and `<var>`.

I also flagged `<param>` as deprecated, though I haven't updated the
method generator to do anything with this information yet.

After this, Phlex supports *all* non-deprecated HTML5 elements, so we
can update the documentation accordingly (it currently says we only
support the most popular).
  • Loading branch information
joeldrapper authored Jan 30, 2024
1 parent 125cda0 commit 72ac60e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/phlex/elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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)
def register_element(method_name, tag: nil, deprecated: false)
tag ||= method_name.name.tr("_", "-")

class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
Expand Down Expand Up @@ -69,7 +69,7 @@ def #{method_name}(**attributes, &block)
end

# @api private
def register_void_element(method_name, tag: method_name.name.tr("_", "-"))
def register_void_element(method_name, tag: method_name.name.tr("_", "-"), deprecated: false)
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
# frozen_string_literal: true
Expand Down
44 changes: 43 additions & 1 deletion lib/phlex/html/standard_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,27 @@ module Phlex::HTML::StandardElements
# @see https://developer.mozilla.org/docs/Web/HTML/Element/aside
register_element :aside, tag: "aside"

# @!method audio(**attributes, &content)
# Outputs an `<audio>` tag.
# @return [nil]
# @yieldparam component [self]
# @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
register_element :audio, tag: "audio"

# @!method b(**attributes, &content)
# Outputs a `<b>` tag.
# @return [nil]
# @yieldparam component [self]
# @see https://developer.mozilla.org/docs/Web/HTML/Element/b
register_element :b, tag: "b"

# @!method base(**attributes, &content)
# Outputs a `<base>` tag.
# @return [nil]
# @yieldparam component [self]
# @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
register_element :base, tag: "base"

# @!method bdi(**attributes, &content)
# Outputs a `<bdi>` tag.
# @return [nil]
Expand Down Expand Up @@ -368,6 +382,13 @@ module Phlex::HTML::StandardElements
# @see https://developer.mozilla.org/docs/Web/HTML/Element/mark
register_element :mark, tag: "mark"

# @!method menu(**attributes, &content)
# Outputs a `<menu>` tag.
# @return [nil]
# @yieldparam component [self]
# @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/menu
register_element :menu, tag: "menu"

# @!method meter(**attributes, &content)
# Outputs a `<meter>` tag.
# @return [nil]
Expand Down Expand Up @@ -438,6 +459,13 @@ module Phlex::HTML::StandardElements
# @see https://developer.mozilla.org/docs/Web/HTML/Element/picture
register_element :picture, tag: "picture"

# @!method portal(**attributes, &content)
# Outputs a `<portal>` tag. (Experimental)
# @return [nil]
# @yieldparam component [self]
# @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/portal
register_element :portal, tag: "portal"

# @!method pre(**attributes, &content)
# Outputs a `<pre>` tag.
# @return [nil]
Expand Down Expand Up @@ -474,7 +502,7 @@ module Phlex::HTML::StandardElements
register_element :rt, tag: "rt"

# @!method ruby(**attributes, &content)
# Outputs a `<ruby>` tag.
# Outputs a `<ruby>` tag. (The best tag ever!)
# @return [nil]
# @yieldparam component [self]
# @see https://developer.mozilla.org/docs/Web/HTML/Element/ruby
Expand All @@ -501,6 +529,13 @@ module Phlex::HTML::StandardElements
# @see https://developer.mozilla.org/docs/Web/HTML/Element/script
register_element :script, tag: "script"

# @!method search(**attributes, &content)
# Outputs a `<search>` tag.
# @return [nil]
# @yieldparam component [self]
# @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/search
register_element :search, tag: "search"

# @!method section(**attributes, &content)
# Outputs a `<section>` tag.
# @return [nil]
Expand Down Expand Up @@ -669,6 +704,13 @@ module Phlex::HTML::StandardElements
# @see https://developer.mozilla.org/docs/Web/HTML/Element/ul
register_element :ul, tag: "ul"

# @!method var(**attributes, &content)
# Outputs a `<var>` tag.
# @return [nil]
# @yieldparam component [self]
# @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/var
register_element :var, tag: "var"

# @!method video(**attributes, &content)
# Outputs a `<video>` tag.
# @return [nil]
Expand Down
14 changes: 7 additions & 7 deletions lib/phlex/html/void_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ module Phlex::HTML::VoidElements
# @see https://developer.mozilla.org/docs/Web/HTML/Element/br
register_void_element :br, tag: "br"

# @!method col(**attributes, &content)
# Outputs a `<col>` tag.
# @return [nil]
# @see https://developer.mozilla.org/docs/Web/HTML/Element/col
register_void_element :col, tag: "col"

# @!method embed(**attributes, &content)
# Outputs an `<embed>` tag.
# @return [nil]
Expand Down Expand Up @@ -56,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, tag: "param"
register_void_element :param, tag: "param", deprecated: true

# @!method source(**attributes, &content)
# Outputs a `<source>` tag.
Expand All @@ -69,10 +75,4 @@ module Phlex::HTML::VoidElements
# @return [nil]
# @see https://developer.mozilla.org/docs/Web/HTML/Element/track
register_void_element :track, tag: "track"

# @!method col(**attributes, &content)
# Outputs a `<col>` tag.
# @return [nil]
# @see https://developer.mozilla.org/docs/Web/HTML/Element/col
register_void_element :col, tag: "col"
end

0 comments on commit 72ac60e

Please sign in to comment.