From f59e2b36d715f32491e4455ff32745eb6c444d21 Mon Sep 17 00:00:00 2001 From: Joel Drapper Date: Fri, 13 Sep 2024 16:56:35 +0200 Subject: [PATCH] Consistent private methods (#782) Make private method names consistent. --- lib/phlex/csv.rb | 6 +++--- lib/phlex/elements.rb | 34 +++++---------------------------- lib/phlex/error.rb | 1 + lib/phlex/fifo.rb | 1 + lib/phlex/html/void_elements.rb | 22 ++++++++++----------- lib/phlex/sgml.rb | 23 +++++++--------------- quickdraw/html/elements.test.rb | 4 ++-- test/phlex/view/svg_tags.rb | 2 +- 8 files changed, 31 insertions(+), 62 deletions(-) diff --git a/lib/phlex/csv.rb b/lib/phlex/csv.rb index 8d9dbc69..38354bfa 100644 --- a/lib/phlex/csv.rb +++ b/lib/phlex/csv.rb @@ -73,12 +73,12 @@ def content_type def column(header = nil, value) if @_first - @_headers << escape(header) + @_headers << __escape__(header) elsif header != @_headers[@_current_column_index] raise "Inconsistent header." end - @_current_row << escape(value) + @_current_row << __escape__(value) @_current_column_index += 1 end @@ -109,7 +109,7 @@ def helpers @_view_context end - def escape(value) + def __escape__(value) value = trim_whitespace? ? value.to_s.strip : value.to_s first_char = value[0] last_char = value[-1] diff --git a/lib/phlex/elements.rb b/lib/phlex/elements.rb index 238a268a..6c41280d 100644 --- a/lib/phlex/elements.rb +++ b/lib/phlex/elements.rb @@ -1,33 +1,10 @@ # frozen_string_literal: true -# Extending this module provides the {register_element} macro for registering your own custom elements. It's already extended by {HTML} and {SVG}. -# @example -# module MyCustomElements -# extend Phlex::Elements -# -# register_element :trix_editor -# end -# -# class MyComponent < Phlex::HTML -# include MyCustomElements -# -# def view_template -# trix_editor -# end -# end module Phlex::Elements - # @api private - def registered_elements - @registered_elements ||= {} + def __registered_elements__ + @__registered_elements__ ||= {} end - # Register a custom element. This macro defines an element method for the current class and descendents only. There is no global element registry. - # @param method_name [Symbol] - # @param tag [String] the name of the tag, otherwise this will be the method name with underscores replaced with dashes. - # @return [Symbol] the name of the method created - # @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: method_name.name.tr("_", "-")) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) # frozen_string_literal: true @@ -121,13 +98,12 @@ def #{method_name}(**attributes) alias_method :_#{method_name}, :#{method_name} RUBY - registered_elements[method_name] = tag + __registered_elements__[method_name] = tag method_name 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("_", "-")) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) # frozen_string_literal: true @@ -165,7 +141,7 @@ def #{method_name}(**attributes) alias_method :_#{method_name}, :#{method_name} RUBY - registered_elements[method_name] = tag + __registered_elements__[method_name] = tag method_name end diff --git a/lib/phlex/error.rb b/lib/phlex/error.rb index a0d9de79..832b694a 100644 --- a/lib/phlex/error.rb +++ b/lib/phlex/error.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +# @api private module Phlex::Error end diff --git a/lib/phlex/fifo.rb b/lib/phlex/fifo.rb index b75db30a..aca9d1ab 100644 --- a/lib/phlex/fifo.rb +++ b/lib/phlex/fifo.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# @api private class Phlex::FIFO def initialize(max_bytesize: 2_000, max_value_bytesize: 2_000) @store = {} diff --git a/lib/phlex/html/void_elements.rb b/lib/phlex/html/void_elements.rb index b231f46e..e7ab4882 100644 --- a/lib/phlex/html/void_elements.rb +++ b/lib/phlex/html/void_elements.rb @@ -8,65 +8,65 @@ module Phlex::HTML::VoidElements # Outputs an `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/area - register_void_element :area + __register_void_element__ :area # @!method br(**attributes, &content) # Outputs a `
` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/br - register_void_element :br + __register_void_element__ :br # @!method col(**attributes, &content) # Outputs a `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/col - register_void_element :col + __register_void_element__ :col # @!method embed(**attributes, &content) # Outputs an `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/embed - register_void_element :embed + __register_void_element__ :embed # @!method hr(**attributes, &content) # Outputs an `
` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/hr - register_void_element :hr + __register_void_element__ :hr # @!method img(**attributes, &content) # Outputs an `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/img - register_void_element :img + __register_void_element__ :img # @!method input(**attributes, &content) # Outputs an `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/input - register_void_element :input + __register_void_element__ :input # @!method link(**attributes, &content) # Outputs a `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/link - register_void_element :link + __register_void_element__ :link # @!method meta(**attributes, &content) # Outputs a `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/meta - register_void_element :meta + __register_void_element__ :meta # @!method source(**attributes, &content) # Outputs a `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/source - register_void_element :source + __register_void_element__ :source # @!method track(**attributes, &content) # Outputs a `` tag. # @return [nil] # @see https://developer.mozilla.org/docs/Web/HTML/Element/track - register_void_element :track + __register_void_element__ :track end diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index 44e563ee..6b625e01 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -25,12 +25,11 @@ def new(*, **, &block) end end - # @api private def __element_method__?(method_name) if instance_methods.include?(method_name) owner = instance_method(method_name).owner - if Phlex::Elements === owner && owner.registered_elements[method_name] + if Phlex::Elements === owner && owner.__registered_elements__[method_name] true else false @@ -120,7 +119,7 @@ def call(buffer = +"", context: Phlex::Context.new, view_context: nil, parent: n else view_template do |*args| if args.length > 0 - yield_content_with_args(*args, &block) + __yield_content_with_args__(*args, &block) else yield_content(&block) end @@ -217,7 +216,7 @@ def capture(*args, &block) return "" unless block if args.length > 0 - @_context.capturing_into(+"") { yield_content_with_args(*args, &block) } + @_context.capturing_into(+"") { __yield_content_with_args__(*args, &block) } else @_context.capturing_into(+"") { yield_content(&block) } end @@ -234,7 +233,7 @@ def tag(name, ...) raise Phlex::ArgumentError.new("You can’t use the `