Skip to content

Commit f7131c1

Browse files
authored
Merge pull request #221 from phlex-ruby/prepare-v2
Prepare v2
2 parents 2715aae + 07b8f65 commit f7131c1

23 files changed

+125
-147
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
os: ["ubuntu-latest", "macos-latest"]
13-
ruby-version: ["2.7", "3.0", "3.1", "3.2", "3.3", "head"]
13+
ruby-version: ["3.3", "head"]
1414
runs-on: ${{ matrix.os }}
1515
steps:
1616
- uses: actions/checkout@v4

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ inherit_from:
33
- "https://www.goodcop.style/tabs.yml"
44

55
AllCops:
6-
TargetRubyVersion: 2.7
6+
TargetRubyVersion: 3.3.3
77
Exclude:
88
- "lib/phlex-rails.rb"
99
SuggestExtensions: false

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.2
1+
3.3.5

.tool-versions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby 3.3.5

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

66
gemspec
77

8-
gem "phlex", github: "phlex-ruby/phlex", branch: "1.11"
8+
gem "phlex", github: "phlex-ruby/phlex"
99
gem "rubocop"
1010
gem "solargraph"
1111
gem "view_component"

lib/phlex/rails.rb

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ module Rails
1111
autoload :BufferedLabelBuilder, "phlex/rails/buffered_label_builder"
1212
autoload :BufferedRadioButtonBuilder, "phlex/rails/buffered_radio_button_builder"
1313
autoload :CSV, "phlex/rails/csv"
14-
autoload :HTML, "phlex/rails/html"
14+
autoload :FragmentFinder, "phlex/rails/fragment_finder"
15+
autoload :HelperFinder, "phlex/rails/helper_finder"
1516
autoload :HelperMacros, "phlex/rails/helper_macros"
1617
autoload :Helpers, "phlex/rails/helpers"
18+
autoload :HTML, "phlex/rails/html"
1719
autoload :Layout, "phlex/rails/layout"
1820
autoload :SGML, "phlex/rails/sgml"
19-
autoload :UnbufferedOverrides, "phlex/rails/unbuffered_overrides"
2021
autoload :Streaming, "phlex/rails/streaming"
21-
autoload :FragmentFinder, "phlex/rails/fragment_finder"
22-
23-
Deprecation = ActiveSupport::Deprecation.new("2.0", "Phlex::Rails")
22+
autoload :Unbuffered, "phlex/rails/unbuffered"
2423
end
2524

2625
CSV.extend Phlex::Rails::HelperMacros
@@ -29,10 +28,8 @@ module Rails
2928
SGML.extend Phlex::Rails::SGML::ClassMethods
3029
SGML.extend Phlex::Rails::HelperMacros
3130
SGML.prepend Phlex::Rails::SGML::Overrides
31+
SGML.include Phlex::Rails::HelperFinder
3232

3333
HTML.extend Phlex::Rails::HTML::Format
3434
HTML.include Phlex::Rails::HTML::Format
35-
HTML.include Phlex::Rails::HTML::MethodMissing
36-
37-
Unbuffered.prepend Phlex::Rails::UnbufferedOverrides
3835
end

lib/phlex/rails/buffered.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def #{method_name}(*args, **kwargs, &block)
3030
3131
case output
3232
when ::ActiveSupport::SafeBuffer
33-
@view.instance_variable_get(:@_context).target << output
33+
@view.instance_variable_get(:@_context).buffer << output
3434
end
3535
3636
nil
@@ -48,15 +48,14 @@ def respond_to_missing?(...)
4848
@object.respond_to?(...)
4949
end
5050

51-
def method_missing(*args, **kwargs, &block)
51+
def method_missing(*, **, &block)
5252
output = if block
53-
@object.public_send(*args, **kwargs) { |*a| @view.capture(*a, &block) }
53+
@object.public_send(*, **) { |*a| @view.capture(*a, &block) }
5454
else
55-
@object.public_send(*args, **kwargs)
55+
@object.public_send(*, **)
5656
end
5757

58-
case output
59-
when ::ActiveSupport::SafeBuffer
58+
if ::ActiveSupport::SafeBuffer === output
6059
@view.instance_variable_get(:@_context).target << output
6160
end
6261

lib/phlex/rails/csv.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ module Phlex
44
module Rails
55
module CSV
66
module Overrides
7-
def each_item(&block)
8-
return super unless collection.is_a?(ActiveRecord::Relation)
7+
def each_item(&)
8+
return super unless ActiveRecord::Relation === collection
99
return super unless collection.arel.orders.empty?
1010

11-
collection.find_each(&block)
11+
collection.find_each(&)
1212
end
1313
end
1414
end

lib/phlex/rails/engine.rb

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
module Phlex
66
module Rails
7-
# @api private
87
class Engine < ::Rails::Engine
98
end
109
end

lib/phlex/rails/html/method_missing.rb lib/phlex/rails/helper_finder.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module Phlex::Rails::HTML::MethodMissing
3+
module Phlex::Rails::HelperFinder
44
def method_missing(name, *args, **kwargs, &block)
55
return super unless helpers.respond_to?(name)
66

lib/phlex/rails/helpers.rb

+10-56
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ module Phlex::Rails::Helpers
1212
autoload :BuildTagValues, "phlex/rails/helpers/build_tag_values"
1313
autoload :ButtonTag, "phlex/rails/helpers/button_tag"
1414
autoload :ButtonTo, "phlex/rails/helpers/button_to"
15-
autoload :CSPMetaTag, "phlex/rails/helpers/csp_meta_tag"
16-
autoload :CSRFMetaTags, "phlex/rails/helpers/csrf_meta_tags"
1715
autoload :CheckBox, "phlex/rails/helpers/check_box"
1816
autoload :CheckBoxTag, "phlex/rails/helpers/check_box_tag"
1917
autoload :ClassNames, "phlex/rails/helpers/class_names"
@@ -29,11 +27,11 @@ module Phlex::Rails::Helpers
2927
autoload :ContentTag, "phlex/rails/helpers/content_tag"
3028
autoload :ControllerName, "phlex/rails/helpers/controller_name"
3129
autoload :ControllerPath, "phlex/rails/helpers/controller_path"
30+
autoload :CSPMetaTag, "phlex/rails/helpers/csp_meta_tag"
31+
autoload :CSRFMetaTags, "phlex/rails/helpers/csrf_meta_tags"
3232
autoload :CurrentCycle, "phlex/rails/helpers/current_cycle"
3333
autoload :CurrentPage, "phlex/rails/helpers/current_page"
3434
autoload :Cycle, "phlex/rails/helpers/cycle"
35-
autoload :DOMClass, "phlex/rails/helpers/dom_class"
36-
autoload :DOMID, "phlex/rails/helpers/dom_id"
3735
autoload :DateField, "phlex/rails/helpers/date_field"
3836
autoload :DateFieldTag, "phlex/rails/helpers/date_field_tag"
3937
autoload :DateSelect, "phlex/rails/helpers/date_select"
@@ -46,6 +44,8 @@ module Phlex::Rails::Helpers
4644
autoload :DefaultURLOptions, "phlex/rails/helpers/default_url_options"
4745
autoload :DistanceOfTimeInWords, "phlex/rails/helpers/distance_of_time_in_words"
4846
autoload :DistanceOfTimeInWordsToNow, "phlex/rails/helpers/distance_of_time_in_words_to_now"
47+
autoload :DOMClass, "phlex/rails/helpers/dom_class"
48+
autoload :DOMID, "phlex/rails/helpers/dom_id"
4949
autoload :EmailField, "phlex/rails/helpers/email_field"
5050
autoload :EmailFieldTag, "phlex/rails/helpers/email_field_tag"
5151
autoload :ErrorMessage, "phlex/rails/helpers/error_message"
@@ -55,8 +55,8 @@ module Phlex::Rails::Helpers
5555
autoload :FaviconLinkTag, "phlex/rails/helpers/favicon_link_tag"
5656
autoload :FieldID, "phlex/rails/helpers/field_id"
5757
autoload :FieldName, "phlex/rails/helpers/field_name"
58-
autoload :FieldSetTag, "phlex/rails/helpers/field_set_tag"
5958
autoload :Fields, "phlex/rails/helpers/fields"
59+
autoload :FieldSetTag, "phlex/rails/helpers/field_set_tag"
6060
autoload :FieldsFor, "phlex/rails/helpers/fields_for"
6161
autoload :FileField, "phlex/rails/helpers/file_field"
6262
autoload :FileFieldTag, "phlex/rails/helpers/file_field_tag"
@@ -75,8 +75,8 @@ module Phlex::Rails::Helpers
7575
autoload :ImageSubmitTag, "phlex/rails/helpers/image_submit_tag"
7676
autoload :ImageTag, "phlex/rails/helpers/image_tag"
7777
autoload :ImageURL, "phlex/rails/helpers/image_url"
78-
autoload :JavascriptImportModuleTag, "phlex/rails/helpers/javascript_import_module_tag"
7978
autoload :JavascriptImportmapTags, "phlex/rails/helpers/javascript_importmap_tags"
79+
autoload :JavascriptImportModuleTag, "phlex/rails/helpers/javascript_import_module_tag"
8080
autoload :JavascriptIncludeTag, "phlex/rails/helpers/javascript_include_tag"
8181
autoload :JavascriptPath, "phlex/rails/helpers/javascript_path"
8282
autoload :JavascriptTag, "phlex/rails/helpers/javascript_tag"
@@ -131,7 +131,6 @@ module Phlex::Rails::Helpers
131131
autoload :ResetCycle, "phlex/rails/helpers/reset_cycle"
132132
autoload :RichTextArea, "phlex/rails/helpers/rich_text_area"
133133
autoload :Routes, "phlex/rails/helpers/routes"
134-
autoload :SMSTo, "phlex/rails/helpers/sms_to"
135134
autoload :Sanitize, "phlex/rails/helpers/sanitize"
136135
autoload :SanitizeCSS, "phlex/rails/helpers/sanitize_css"
137136
autoload :SearchField, "phlex/rails/helpers/search_field"
@@ -148,6 +147,7 @@ module Phlex::Rails::Helpers
148147
autoload :SelectTime, "phlex/rails/helpers/select_time"
149148
autoload :SelectYear, "phlex/rails/helpers/select_year"
150149
autoload :SimpleFormat, "phlex/rails/helpers/simple_format"
150+
autoload :SMSTo, "phlex/rails/helpers/sms_to"
151151
autoload :StripLinks, "phlex/rails/helpers/strip_links"
152152
autoload :StripTags, "phlex/rails/helpers/strip_tags"
153153
autoload :StylesheetLinkTag, "phlex/rails/helpers/stylesheet_link_tag"
@@ -174,9 +174,9 @@ module Phlex::Rails::Helpers
174174
autoload :Truncate, "phlex/rails/helpers/truncate"
175175
autoload :TurboFrameTag, "phlex/rails/helpers/turbo_frame_tag"
176176
autoload :TurboIncludeTags, "phlex/rails/helpers/turbo_include_tags"
177+
autoload :TurboRefreshesWith, "phlex/rails/helpers/turbo_refreshes_with"
177178
autoload :TurboRefreshMethodTag, "phlex/rails/helpers/turbo_refresh_method_tag"
178179
autoload :TurboRefreshScrollTag, "phlex/rails/helpers/turbo_refresh_scroll_tag"
179-
autoload :TurboRefreshesWith, "phlex/rails/helpers/turbo_refreshes_with"
180180
autoload :TurboStream, "phlex/rails/helpers/turbo_stream"
181181
autoload :TurboStreamFrom, "phlex/rails/helpers/turbo_stream_from"
182182
autoload :URLField, "phlex/rails/helpers/url_field"
@@ -194,56 +194,10 @@ module Phlex::Rails::Helpers
194194
autoload :VideoPath, "phlex/rails/helpers/video_path"
195195
autoload :VideoTag, "phlex/rails/helpers/video_tag"
196196
autoload :VideoURL, "phlex/rails/helpers/video_url"
197-
autoload :WeekField, "phlex/rails/helpers/week_field"
198-
autoload :WeekFieldTag, "phlex/rails/helpers/week_field_tag"
199197
autoload :WeekdayOptionsForSelect, "phlex/rails/helpers/weekday_options_for_select"
200198
autoload :WeekdaySelect, "phlex/rails/helpers/weekday_select"
199+
autoload :WeekField, "phlex/rails/helpers/week_field"
200+
autoload :WeekFieldTag, "phlex/rails/helpers/week_field_tag"
201201
autoload :WithOutputBuffer, "phlex/rails/helpers/with_output_buffer"
202202
autoload :WordWrap, "phlex/rails/helpers/word_wrap"
203-
204-
DEPRECATED = {
205-
Checkbox: :CheckBox,
206-
CheckboxTag: :CheckBoxTag,
207-
CollectionCheckboxes: :CollectionCheckBoxes,
208-
DateTimeField: :DatetimeField,
209-
PathToJavaScript: :PathToJavascript,
210-
DateTimeFieldTag: :DatetimeFieldTag,
211-
DateTimeLocalField: :DatetimeLocalField,
212-
DateTimeLocalFieldTag: :DatetimeLocalFieldTag,
213-
DateTimeSelect: :DatetimeSelect,
214-
JavaScriptImportModuleTag: :JavascriptImportModuleTag,
215-
JavaScriptImportMapTags: :JavascriptImportmapTags,
216-
JavaScriptIncludeTag: :JavascriptIncludeTag,
217-
JavaScriptPath: :JavascriptPath,
218-
JavaScriptTag: :JavascriptTag,
219-
JavaScriptURL: :JavascriptURL,
220-
LinkIf: :LinkToIf,
221-
PathToStyleSheet: :PathToStylesheet,
222-
SanitizeCss: :SanitizeCSS,
223-
SelectDateTime: :SelectDatetime,
224-
StyleSheetLinkTag: :StylesheetLinkTag,
225-
StyleSheetPath: :StylesheetPath,
226-
StyleSheetURL: :StylesheetURL,
227-
URLToJavaScript: :URLToJavascript,
228-
URLToStyleSheet: :URLToStylesheet,
229-
}
230-
231-
def self.const_missing(name)
232-
if (helper_module_name = DEPRECATED[name])
233-
message = "`Phlex::Rails::Helpers::#{name}` is deprecated. Please use `Phlex::Rails::Helpers::#{helper_module_name}` instead."
234-
235-
if name.to_s.downcase == helper_module_name.to_s.downcase
236-
message << " Note the casing of the module name has changed to match the helper method."
237-
end
238-
239-
Phlex::Rails::Deprecation.warn(message)
240-
241-
helper_module = const_get(helper_module_name)
242-
const_set(name, helper_module)
243-
244-
helper_module
245-
else
246-
super
247-
end
248-
end
249203
end

lib/phlex/rails/helpers/translate.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def self.included(base)
1515
base.extend(ClassMethods)
1616
end
1717

18-
def translate(key, **options)
18+
def translate(key, **)
1919
key = "#{self.class.translation_path}#{key}" if key.start_with?(".")
2020

21-
helpers.t(key, **options)
21+
helpers.t(key, **)
2222
end
2323

2424
alias_method :t, :translate

lib/phlex/rails/html.rb

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
module Phlex::Rails::HTML
4-
autoload :MethodMissing, "phlex/rails/html/method_missing"
5-
64
module Format
75
def format
86
:html

lib/phlex/rails/layout.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module Layout
1818

1919
# @api private
2020
module Interface
21-
def render(view_context, _locals, &block)
22-
new.render(view_context, &block)
21+
def render(view_context, _locals, &)
22+
new.render(view_context, &)
2323
end
2424

2525
def identifier
@@ -49,7 +49,7 @@ def render(view_context, *args, **kwargs, &block)
4949
if @_context
5050
super
5151
else
52-
call(view_context: view_context) do |yielded|
52+
call(view_context:) do |yielded|
5353
case yielded
5454
when Symbol
5555
output = view_context.view_flow.get(yielded)

lib/phlex/rails/sgml.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ def render_in(...)
1111

1212
module Overrides
1313
def helpers
14-
if defined?(ViewComponent::Base) && @_view_context.is_a?(ViewComponent::Base)
14+
if defined?(ViewComponent::Base) && ViewComponent::Base === @_view_context
1515
@_view_context.helpers
1616
else
1717
@_view_context
1818
end
1919
end
2020

21-
def render(*args, **kwargs, &block)
21+
def render(*args, **, &block)
2222
renderable = args[0]
2323

2424
case renderable
@@ -27,18 +27,18 @@ def render(*args, **kwargs, &block)
2727
when Class
2828
return super if renderable < Phlex::SGML
2929
when Enumerable
30-
return super unless renderable.is_a?(ActiveRecord::Relation)
30+
return super unless ActiveRecord::Relation === renderable
3131
else
3232
if block
33-
@_context.target << @_view_context.render(*args, **kwargs) do |*yielded_args|
33+
@_context.target << @_view_context.render(*args, **) do |*yielded_args|
3434
if yielded_args.length == 1 && defined?(ViewComponent::Base) && ViewComponent::Base === yielded_args[0]
3535
capture(Phlex::Rails::Buffered.new(yielded_args[0], view: self), &block)
3636
else
3737
capture(*yielded_args, &block)
3838
end
3939
end
4040
else
41-
@_context.target << @_view_context.render(*args, **kwargs)
41+
@_context.target << @_view_context.render(*args, **)
4242
end
4343
end
4444

@@ -51,12 +51,13 @@ def render_in(view_context, &block)
5151
end
5252

5353
if block_given?
54-
call(view_context: view_context, fragments: fragments) do |*args|
54+
call(view_context:, fragments:) do |*args|
5555
original_length = @_context.target.bytesize
5656

5757
if args.length == 1 && Phlex::SGML === args[0] && !block.source_location&.[](0)&.end_with?(".rb")
5858
output = view_context.capture(
59-
args[0].unbuffered, &block
59+
Phlex::Rails::Unbuffered.new(args[0]),
60+
&block
6061
)
6162
else
6263
output = view_context.capture(*args, &block)
@@ -72,7 +73,7 @@ def render_in(view_context, &block)
7273
end
7374
end.html_safe
7475
else
75-
call(view_context: view_context, fragments: fragments).html_safe
76+
call(view_context:, fragments:).html_safe
7677
end
7778
end
7879

0 commit comments

Comments
 (0)