diff --git a/Gemfile b/Gemfile index 0ddf5e3..bb94df8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true source "https://rubygems.org" -gemspec \ No newline at end of file +gemspec diff --git a/Gemfile.lock b/Gemfile.lock index a2f35bd..6fe2a7a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: phlexy_ui (0.1.22) - phlex (>= 1.10) + phlex (>= 2.0.0.rc1) zeitwerk (~> 2.6) GEM @@ -24,7 +24,7 @@ GEM parser (3.3.4.0) ast (~> 2.4.1) racc - phlex (1.11.0) + phlex (2.0.0.rc1) psych (5.1.2) stringio racc (1.8.1) diff --git a/lib/phlexy_ui/collapsible_sub_menu.rb b/lib/phlexy_ui/collapsible_sub_menu.rb index 444379b..74277c4 100644 --- a/lib/phlexy_ui/collapsible_sub_menu.rb +++ b/lib/phlexy_ui/collapsible_sub_menu.rb @@ -3,14 +3,14 @@ module PhlexyUI # @private class CollapsibleSubMenu < Base - include Phlex::DeferredRender - def initialize(*, **) super @items ||= [] end def view_template(&) + yield(self) if block_given? + attributes = generate_attributes(base_modifiers, options, ATTRIBUTES_MAP) generate_classes!( diff --git a/lib/phlexy_ui/sub_menu.rb b/lib/phlexy_ui/sub_menu.rb index 476a0ee..8819902 100644 --- a/lib/phlexy_ui/sub_menu.rb +++ b/lib/phlexy_ui/sub_menu.rb @@ -3,14 +3,14 @@ module PhlexyUI # @private class SubMenu < Base - include Phlex::DeferredRender - def initialize(*, **) super @items ||= [] end def view_template(&) + yield(self) if block_given? + if @title div do render @title diff --git a/lib/phlexy_ui/tab.rb b/lib/phlexy_ui/tab.rb index 3249a16..0ea7afc 100644 --- a/lib/phlexy_ui/tab.rb +++ b/lib/phlexy_ui/tab.rb @@ -3,14 +3,14 @@ module PhlexyUI # @private class Tab < Base - include Phlex::DeferredRender - def initialize(*, id: nil, **) super(*, **) @id = id end def view_template(&) + yield(self) if block_given? + if @content render TabWithContent.new( *base_modifiers, diff --git a/phlexy_ui.gemspec b/phlexy_ui.gemspec index bcdd9b8..a397e1e 100644 --- a/phlexy_ui.gemspec +++ b/phlexy_ui.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 3.2" - s.add_dependency "phlex", ">= 1.10" + s.add_dependency "phlex", ">= 2.0.0.rc1" s.add_dependency "zeitwerk", "~> 2.6" s.add_development_dependency "standard", "~> 1.39.2" diff --git a/spec/lib/phlexy_ui/button_spec.rb b/spec/lib/phlexy_ui/button_spec.rb index d636911..e2d629d 100644 --- a/spec/lib/phlexy_ui/button_spec.rb +++ b/spec/lib/phlexy_ui/button_spec.rb @@ -215,8 +215,8 @@ render described_class.new( :neutral, class: "my-class", - modal: :my_modal_1, - data: {my: :modals} + modal: "my_modal_1", + data: {my: "modals"} ) do "Click me" end @@ -226,8 +226,8 @@ expected_html = html <<~HTML + onclick="my_modal_1.showModal()" + data-my="modals">Click me HTML expect(output).to eq(expected_html) @@ -247,44 +247,6 @@ end end - # TODO: Not needed once Phlex 2.0 is released. - context "when passing malicious code via the block" do - subject(:output) do - render described_class.new(:neutral, modal: :my_modal_1) do - "" - end - end - - it "escapes the code" do - expected_html = html <<~HTML - - HTML - - expect(output).to eq(expected_html) - end - end - - # TODO: Not needed once Phlex 2.0 is released. - context "when passing malicious code via the onclick option" do - subject(:output) do - render described_class.new( - :neutral, - :modal => :my_modal_1, - "onclick" => "" - ) - end - - it "escapes the code" do - expected_html = "" - - expect(output).to eq(expected_html) - end - end - context "when passing malicious code via the modal option" do subject(:output) do render described_class.new(:neutral, modal: %(" onclick="alert('XSS') //;)) @@ -301,24 +263,5 @@ expect(output).to eq(expected_html) end end - - # TODO: Not needed once Phlex 2.0 is released. - context "when passing malicious code via the class option" do - subject(:output) do - render described_class.new( - :neutral, - modal: :my_modal_1, - class: %(" onclick="alert('XSS');) - ) - end - - it "escapes the code" do - expected_html = "" - - expect(output).to eq(expected_html) - end - end end end diff --git a/spec/lib/phlexy_ui/drawer_spec.rb b/spec/lib/phlexy_ui/drawer_spec.rb index ae98c9e..4ce0099 100644 --- a/spec/lib/phlexy_ui/drawer_spec.rb +++ b/spec/lib/phlexy_ui/drawer_spec.rb @@ -184,7 +184,7 @@ let(:component) do Class.new(Phlex::HTML) do def view_template(&) - render PhlexyUI::Drawer.new(:end, id: :my_drawer) do |drawer| + render PhlexyUI::Drawer.new(:end, id: "my_drawer") do |drawer| drawer.toggle(class: "my-toggle", data: {my: "toggles"}) drawer.content(class: "my-content", data: {my: "contents"}) do drawer.button(:primary, class: "my-button", data: {my: "buttons"}) do diff --git a/spec/lib/phlexy_ui/menu_spec.rb b/spec/lib/phlexy_ui/menu_spec.rb index 5d7915f..c6236d6 100644 --- a/spec/lib/phlexy_ui/menu_spec.rb +++ b/spec/lib/phlexy_ui/menu_spec.rb @@ -279,7 +279,7 @@ def view_template(&) end menu.item do |item| - item.submenu :collapsible, :open, :primary, class: "rounded-t-none", data: {my: :collapsible_menus} do |submenu| + item.submenu :collapsible, :open, :primary, class: "rounded-t-none", data: {my: "collapsible_menus"} do |submenu| submenu.title do "Parent 1" end diff --git a/spec/lib/phlexy_ui/modal_spec.rb b/spec/lib/phlexy_ui/modal_spec.rb index 7e3b1be..e8edf3d 100644 --- a/spec/lib/phlexy_ui/modal_spec.rb +++ b/spec/lib/phlexy_ui/modal_spec.rb @@ -11,7 +11,7 @@ def view_template(&) "Open Modal" end - render PhlexyUI::Modal.new(id: :my_modal_1) do |modal| + render PhlexyUI::Modal.new(id: "my_modal_1") do |modal| modal.body do h3 do "Hello!" @@ -64,7 +64,7 @@ def view_template(&) "Open Modal" end - render PhlexyUI::Modal.new(:tap_outside_to_close, id: :my_modal_1) do |modal| + render PhlexyUI::Modal.new(:tap_outside_to_close, id: "my_modal_1") do |modal| modal.body do h3 do "Hello!" @@ -109,7 +109,7 @@ def view_template(&) "Open Modal" end - render PhlexyUI::Modal.new(id: :my_modal_1) do |modal| + render PhlexyUI::Modal.new(id: "my_modal_1") do |modal| modal.body do modal.close_button :sm, :circle, :ghost, class: "absolute right-2 top-2" do "✕" diff --git a/spec/lib/phlexy_ui/radial_progress_spec.rb b/spec/lib/phlexy_ui/radial_progress_spec.rb index 641c435..ccec50c 100644 --- a/spec/lib/phlexy_ui/radial_progress_spec.rb +++ b/spec/lib/phlexy_ui/radial_progress_spec.rb @@ -95,7 +95,7 @@ def view_template(&) style: "background-color: red;", as: :section, data: { - my: :radial_progress + my: "radial_progress" } ) do "50%" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index acf6ff2..49c2706 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,7 @@ Bundler.setup require "phlexy_ui" -require "phlex/testing/view_helper" +require "phlex/testing" Dir["./spec/support/**/*.rb"].each do |f| require f diff --git a/spec/support/phlex_helpers.rb b/spec/support/phlex_helpers.rb index 98c60e3..85b765b 100644 --- a/spec/support/phlex_helpers.rb +++ b/spec/support/phlex_helpers.rb @@ -10,6 +10,16 @@ def phlex_context(&) end end +module Phlex + module Testing + module ViewHelper + include Phlex::Testing::SGML + + alias_method :render, :render_to_string + end + end +end + RSpec.configure do |config| config.include Phlex::Testing::ViewHelper config.include PhlexHelpers