Skip to content

Commit

Permalink
Update CI (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper authored Nov 26, 2024
1 parent 0604701 commit 2484d5b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions fixtures/sgml_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/phlex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/phlex/kit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 7 additions & 11 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion phlex.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 6 additions & 10 deletions quickdraw/kit.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) == %(<article><h1>Hi Joel</h1><h1>Hi Joel</h1>Inside</article><article><h1>Hi Will</h1>Inside</article>)
end
test "defines methods for its components" do
expect(Example.new.call) == %(<article><h1>Hi Joel</h1><h1>Hi Joel</h1>Inside</article><article><h1>Hi Will</h1>Inside</article>)
end

0 comments on commit 2484d5b

Please sign in to comment.