diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c295e457..05bd45c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,16 +11,11 @@ jobs: matrix: os: ["ubuntu-latest", "macos-latest"] ruby-version: - - "2.7" - - "3.0" - - "3.1" - "3.2" - "3.3" - "head" - - "truffleruby-22.2" - - "truffleruby-22.3" - - "jruby-9.4.6.0" - - "jruby-head" + - "truffleruby-23.1" + - "truffleruby-24.0" runs-on: ${{ matrix.os }} steps: diff --git a/.rubocop.yml b/.rubocop.yml index 7010023b..a3681d01 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,7 @@ inherit_from: - "https://www.goodcop.style/tabs.yml" AllCops: - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.2 Style/ExplicitBlockArgument: Enabled: false @@ -25,3 +25,9 @@ Naming/MethodName: Style/ReturnNilInPredicateMethodDefinition: Enabled: false + +Naming/BlockForwarding: + Enabled: false + +Style/ArgumentsForwarding: + Enabled: false diff --git a/fixtures/components/say_hi.rb b/fixtures/components/say_hi.rb index e74dd57b..1869ef19 100644 --- a/fixtures/components/say_hi.rb +++ b/fixtures/components/say_hi.rb @@ -6,7 +6,7 @@ def initialize(name, times: 1) @times = times end - def template + def view_template article { @times.times { h1 { "Hi #{@name}" } } yield diff --git a/lib/phlex.rb b/lib/phlex.rb index 7889b957..142b98e0 100644 --- a/lib/phlex.rb +++ b/lib/phlex.rb @@ -42,15 +42,7 @@ class NameError < ::NameError # @api private ATTRIBUTE_CACHE = {} - SUPPORTS_FIBER_STORAGE = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.2") -end - -if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0") - class Symbol - def name - to_s - end - end + SUPPORTS_FIBER_STORAGE = RUBY_ENGINE == "ruby" end def 💪 diff --git a/lib/phlex/csv.rb b/lib/phlex/csv.rb index 617ded7d..046e9d43 100644 --- a/lib/phlex/csv.rb +++ b/lib/phlex/csv.rb @@ -3,8 +3,8 @@ class Phlex::CSV include Phlex::Callable - FORMULA_PREFIXES = ["=", "+", "-", "@", "\t", "\r"].to_h { |prefix| [prefix, true] }.freeze - SPACE_CHARACTERS = [" ", "\t", "\r"].to_h { |char| [char, true] }.freeze + FORMULA_PREFIXES = Set["=", "+", "-", "@", "\t", "\r"].freeze + SPACE_CHARACTERS = Set[" ", "\t", "\r"].freeze def initialize(collection) @collection = collection @@ -92,10 +92,6 @@ def yielder(record) yield(record) end - def template(...) - nil - end - # Override and set to `false` to disable rendering headers. def render_headers? true @@ -120,11 +116,11 @@ def escape(value) first_char = value[0] last_char = value[-1] - if escape_csv_injection? && FORMULA_PREFIXES[first_char] + if escape_csv_injection? && FORMULA_PREFIXES.include?(first_char) # Prefix a single quote to prevent Excel, Google Docs, etc. from interpreting the value as a formula. # See https://owasp.org/www-community/attacks/CSV_Injection %("'#{value.gsub('"', '""')}") - elsif (!trim_whitespace? && (SPACE_CHARACTERS[first_char] || SPACE_CHARACTERS[last_char])) || value.include?('"') || value.include?(",") || value.include?("\n") + elsif (!trim_whitespace? && (SPACE_CHARACTERS.include?(first_char) || SPACE_CHARACTERS.include?(last_char))) || value.include?('"') || value.include?(",") || value.include?("\n") %("#{value.gsub('"', '""')}") else value diff --git a/lib/phlex/elements.rb b/lib/phlex/elements.rb index db56cb1b..769e6454 100644 --- a/lib/phlex/elements.rb +++ b/lib/phlex/elements.rb @@ -98,20 +98,11 @@ def #{method_name}(**attributes, &block) end # @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 - + def register_void_element(method_name, tag: method_name.name.tr("_", "-")) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) # frozen_string_literal: true def #{method_name}(**attributes) - #{deprecation} context = @_context buffer = context.buffer fragment = context.fragments diff --git a/lib/phlex/helpers.rb b/lib/phlex/helpers.rb index 0889d88f..8674ce79 100644 --- a/lib/phlex/helpers.rb +++ b/lib/phlex/helpers.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "set" - module Phlex::Helpers private diff --git a/lib/phlex/html.rb b/lib/phlex/html.rb index c42eb698..39df3580 100644 --- a/lib/phlex/html.rb +++ b/lib/phlex/html.rb @@ -7,7 +7,7 @@ class HTML < SGML autoload :VoidElements, "phlex/html/void_elements" # A list of HTML attributes that have the potential to execute unsafe JavaScript. - EVENT_ATTRIBUTES = %w[onabort onafterprint onbeforeprint onbeforeunload onblur oncanplay oncanplaythrough onchange onclick oncontextmenu oncopy oncuechange oncut ondblclick ondrag ondragend ondragenter ondragleave ondragover ondragstart ondrop ondurationchange onemptied onended onerror onfocus onhashchange oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart onmessage onmousedown onmousemove onmouseout onmouseover onmouseup onmousewheel onoffline ononline onpagehide onpageshow onpaste onpause onplay onplaying onpopstate onprogress onratechange onreset onresize onscroll onsearch onseeked onseeking onselect onstalled onstorage onsubmit onsuspend ontimeupdate ontoggle onunload onvolumechange onwaiting onwheel].to_h { [_1, true] }.freeze + EVENT_ATTRIBUTES = Set.new(%w[onabort onafterprint onbeforeprint onbeforeunload onblur oncanplay oncanplaythrough onchange onclick oncontextmenu oncopy oncuechange oncut ondblclick ondrag ondragend ondragenter ondragleave ondragover ondragstart ondrop ondurationchange onemptied onended onerror onfocus onhashchange oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart onmessage onmousedown onmousemove onmouseout onmouseover onmouseup onmousewheel onoffline ononline onpagehide onpageshow onpaste onpause onplay onplaying onpopstate onprogress onratechange onreset onresize onscroll onsearch onseeked onseeking onselect onstalled onstorage onsubmit onsuspend ontimeupdate ontoggle onunload onvolumechange onwaiting onwheel]).freeze UNBUFFERED_MUTEX = Mutex.new diff --git a/lib/phlex/html/standard_elements.rb b/lib/phlex/html/standard_elements.rb index 9f2adc22..cfce3029 100644 --- a/lib/phlex/html/standard_elements.rb +++ b/lib/phlex/html/standard_elements.rb @@ -639,7 +639,7 @@ module Phlex::HTML::StandardElements # @return [nil] # @yieldparam component [self] # @see https://developer.mozilla.org/docs/Web/HTML/Element/template - register_element :template_tag, tag: "template" + register_element :template # @!method textarea(**attributes, &content) # Outputs a `