Skip to content

Commit

Permalink
Bump Phlex to 2.0.0.rc (#2)
Browse files Browse the repository at this point in the history
* chore(deps): bump phlex to 2.0.0.rc

* fix: prefer yield self over before vanish

* fix: update specs to work with 2.0

* fix: lint'em hard
  • Loading branch information
mhenrixon authored Dec 3, 2024
1 parent 53f5358 commit 75f6d1d
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

source "https://rubygems.org"
gemspec
gemspec
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
phlexy_ui (0.1.22)
phlex (>= 1.10)
phlex (>= 2.0.0.rc1)
zeitwerk (~> 2.6)

GEM
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/phlexy_ui/collapsible_sub_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
4 changes: 2 additions & 2 deletions lib/phlexy_ui/sub_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/phlexy_ui/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion phlexy_ui.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
65 changes: 4 additions & 61 deletions spec/lib/phlexy_ui/button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -226,8 +226,8 @@
expected_html = html <<~HTML
<button
class="btn btn-neutral my-class"
data-my="modals"
onclick="my_modal_1.showModal()">Click me</button>
onclick="my_modal_1.showModal()"
data-my="modals">Click me</button>
HTML

expect(output).to eq(expected_html)
Expand All @@ -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
"<script>alert('XSS');</script>"
end
end

it "escapes the code" do
expected_html = html <<~HTML
<button
class="btn btn-neutral"
onclick="my_modal_1.showModal()">&lt;script&gt;alert(&#39;XSS&#39;);&lt;/script&gt;</button>
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" => "<script>alert('XSS');</script>"
)
end

it "escapes the code" do
expected_html = "<button class=\"btn btn-neutral\" " \
"onclick=\"&lt;script&gt;alert(&#39;XSS&#39;);&lt;/script&gt;\" " \
"onclick=\"my_modal_1.showModal()\"></button>"

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') //;))
Expand All @@ -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 = "<button class=\"btn btn-neutral &quot; " \
"onclick=&quot;alert(&#39;XSS&#39;);\" " \
"onclick=\"my_modal_1.showModal()\"></button>"

expect(output).to eq(expected_html)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/phlexy_ui/drawer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/phlexy_ui/menu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/phlexy_ui/modal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down Expand Up @@ -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!"
Expand Down Expand Up @@ -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
"✕"
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/phlexy_ui/radial_progress_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def view_template(&)
style: "background-color: red;",
as: :section,
data: {
my: :radial_progress
my: "radial_progress"
}
) do
"50%"
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/support/phlex_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 75f6d1d

Please sign in to comment.