diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e32606d..c870cd63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,8 +11,11 @@ jobs: matrix: os: ["ubuntu-latest", "macos-latest"] ruby-version: + - "3.2" - "3.3" - "head" + - "truffleruby" + - "truffleruby-head" runs-on: ${{ matrix.os }} steps: @@ -33,7 +36,7 @@ jobs: run: bundle exec sus - name: Quickdraw Tests - run: bundle exec qt + run: bundle exec qt -t 1 rubocop: runs-on: "ubuntu-latest" diff --git a/.rubocop.yml b/.rubocop.yml index e3e24805..5e4514fc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_from: - "https://www.goodcop.style/tabs.yml" AllCops: - TargetRubyVersion: 3.3.1 + TargetRubyVersion: 3.2 # We need to disable this cop because it’s not compatible with TruffleRuby 23.1, which still needs a `require "set"` Lint/RedundantRequireStatement: diff --git a/fixtures/sgml_helper.rb b/fixtures/sgml_helper.rb index e66afc1b..a76b2e53 100644 --- a/fixtures/sgml_helper.rb +++ b/fixtures/sgml_helper.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module SGMLHelper - def phlex(component = Phlex::HTML, *, **, &) - component.new(*, **).call do |e| + def phlex(component = Phlex::HTML, *a, **k, &) + component.new(*a, **k).call do |e| e.instance_exec(&) end end diff --git a/lib/phlex.rb b/lib/phlex.rb index 29b931a5..e733b7ec 100644 --- a/lib/phlex.rb +++ b/lib/phlex.rb @@ -22,7 +22,6 @@ module Phlex Escape = ERB::Escape ATTRIBUTE_CACHE = FIFO.new - SUPPORTS_FIBER_STORAGE = RUBY_ENGINE == "ruby" Null = Object.new.freeze CACHED_FILES = Set.new diff --git a/lib/phlex/kit.rb b/lib/phlex/kit.rb index 7a13da3a..b66c7187 100644 --- a/lib/phlex/kit.rb +++ b/lib/phlex/kit.rb @@ -60,7 +60,7 @@ def const_added(name) end define_singleton_method(name) do |*args, **kwargs, &block| - if (component = Fiber[:__phlex_component__]) + if (component = Thread.current[:__phlex_component__]) component.instance_exec do constant = me.const_get(name) render(constant.new(*args, **kwargs), &block) diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index e8f37b0f..e7baf112 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -19,9 +19,9 @@ def call(...) # Create a new instance of the component. # @note The block will not be delegated {#initialize}. Instead, it will be sent to {#template} when rendering. - def new(*, **, &block) + def new(*a, **k, &block) if block - object = super(*, **, &nil) + object = super(*a, **k, &nil) object.instance_exec { @_content_block = block } object else @@ -70,10 +70,7 @@ def call(buffer = +"", context: {}, view_context: nil, parent: nil, fragments: n return "" unless render? - if !parent && Phlex::SUPPORTS_FIBER_STORAGE - original_fiber_storage = Fiber[:__phlex_component__] - Fiber[:__phlex_component__] = self - end + Thread.current[:__phlex_component__] = self phlex_context.around_render do before_template(&block) @@ -96,11 +93,10 @@ def call(buffer = +"", context: {}, view_context: nil, parent: nil, fragments: n end unless parent - if Phlex::SUPPORTS_FIBER_STORAGE - Fiber[:__phlex_component__] = original_fiber_storage - end buffer << phlex_context.buffer end + ensure + Thread.current[:__phlex_component__] = parent end protected def __context__ = @_context @@ -287,13 +283,13 @@ def __yield_content_with_no_args__ nil end - def __yield_content_with_args__(*) + def __yield_content_with_args__(*a) return unless block_given? buffer = @_context.buffer original_length = buffer.bytesize - content = yield(*) + content = yield(*a) __implicit_output__(content) if original_length == buffer.bytesize nil diff --git a/phlex.gemspec b/phlex.gemspec index 27baece2..666e4285 100644 --- a/phlex.gemspec +++ b/phlex.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.description = "A high-performance view framework optimised for fun." spec.homepage = "https://www.phlex.fun" spec.license = "MIT" - spec.required_ruby_version = ">= 3.3.1" + spec.required_ruby_version = ">= 3.2" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/phlex-ruby/phlex" diff --git a/quickdraw/kit.test.rb b/quickdraw/kit.test.rb index 599dc4cc..c707b567 100644 --- a/quickdraw/kit.test.rb +++ b/quickdraw/kit.test.rb @@ -11,16 +11,12 @@ def view_template end end -# This feature is only supported in Ruby 3.2 or later. -if Phlex::SUPPORTS_FIBER_STORAGE - # this test is flaky - test "raises when you try to render a component outside of a rendering context" do - expect { Components::SayHi() }.to_raise(RuntimeError) do |error| - expect(error.message) == "You can't call `SayHi' outside of a Phlex rendering context." - end +test "raises when you try to render a component outside of a rendering context" do + expect { Components::SayHi("Joel") }.to_raise(RuntimeError) do |error| + expect(error.message) == "You can't call `SayHi' outside of a Phlex rendering context." end +end - test "defines methods for its components" do - expect(Example.new.call) == %(

Hi Joel

Hi Joel

Inside

Hi Will

Inside
) - end +test "defines methods for its components" do + expect(Example.new.call) == %(

Hi Joel

Hi Joel

Inside

Hi Will

Inside
) end