phlex-rails 1.2.2 → 2.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/phlex/component/component_generator.rb +1 -1
- data/lib/generators/phlex/install/install_generator.rb +31 -37
- data/lib/generators/phlex/view/view_generator.rb +1 -1
- data/lib/phlex/rails/buffered.rb +6 -7
- data/lib/phlex/rails/csv.rb +3 -3
- data/lib/phlex/rails/engine.rb +0 -1
- data/lib/phlex/rails/{html/method_missing.rb → helper_finder.rb} +1 -1
- data/lib/phlex/rails/helper_macros.rb +2 -12
- data/lib/phlex/rails/helpers/notice.rb +8 -0
- data/lib/phlex/rails/helpers/routes.rb +1 -0
- data/lib/phlex/rails/helpers/tag.rb +2 -2
- data/lib/phlex/rails/helpers/translate.rb +2 -2
- data/lib/phlex/rails/helpers/turbo_stream.rb +1 -1
- data/lib/phlex/rails/helpers.rb +11 -56
- data/lib/phlex/rails/html.rb +0 -2
- data/lib/phlex/rails/layout.rb +5 -4
- data/lib/phlex/rails/sgml.rb +35 -53
- data/lib/phlex/rails/streaming.rb +11 -9
- data/lib/phlex/rails/testing.rb +18 -0
- data/lib/phlex/rails/unbuffered.rb +50 -0
- data/lib/phlex/rails/version.rb +1 -1
- data/lib/phlex/rails.rb +6 -7
- metadata +14 -39
- data/.editorconfig +0 -13
- data/.rubocop.yml +0 -14
- data/.ruby-version +0 -1
- data/.yardopts +0 -1
- data/Appraisals +0 -15
- data/CHANGELOG.md +0 -38
- data/CODE_OF_CONDUCT.md +0 -84
- data/Gemfile +0 -17
- data/SECURITY.md +0 -5
- data/config.ru +0 -9
- data/lib/generators/phlex/component/USAGE +0 -8
- data/lib/generators/phlex/component/templates/component.rb.erb +0 -9
- data/lib/generators/phlex/install/USAGE +0 -8
- data/lib/generators/phlex/install/templates/application_component.rb +0 -12
- data/lib/generators/phlex/install/templates/application_layout.rb +0 -24
- data/lib/generators/phlex/install/templates/application_view.rb +0 -9
- data/lib/generators/phlex/view/USAGE +0 -8
- data/lib/generators/phlex/view/templates/view.rb.erb +0 -9
- data/lib/phlex/rails/unbuffered_overrides.rb +0 -30
- data/lib/phlex/testing/rails/view_helper.rb +0 -19
- data/phlex-rails.gemspec +0 -35
- data/phlex_logo.png +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eba6c0a4545578f13da48e443ca0751b5549eefd6cb9b2f866d0cfe436f5451b
|
|
4
|
+
data.tar.gz: 21695f056968e79c6f692328d2666b9933fbf63ef3def64a46eced386019faaa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cece72abf570509143731193eaf0052c4a724ee294bf022b041751dc36e832e139cb808db3eb1ffd3d77a8fb41bc22c4013ad1824b86bc3fe3455a28c41d8c3a
|
|
7
|
+
data.tar.gz: afa2c05f30141978622fb6f964d426742e2ce772bfb3c0752b470f6e44217ac7f00f6800d975f6305a4b1cd498ed98ff613fbdb8a3202c02b155554791a81ff2
|
|
@@ -5,7 +5,7 @@ module Phlex::Generators
|
|
|
5
5
|
source_root File.expand_path("templates", __dir__)
|
|
6
6
|
|
|
7
7
|
def create_view
|
|
8
|
-
@path = File.join("app/
|
|
8
|
+
@path = File.join("app/components", class_path, "#{file_name}.rb")
|
|
9
9
|
template "component.rb.erb", @path
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -5,56 +5,50 @@ module Phlex::Generators
|
|
|
5
5
|
source_root File.expand_path("templates", __dir__)
|
|
6
6
|
|
|
7
7
|
APPLICATION_CONFIGURATION_PATH = Rails.root.join("config/application.rb")
|
|
8
|
-
TAILWIND_CONFIGURATION_PATH = Rails.root.join("tailwind.config.js")
|
|
9
8
|
|
|
10
|
-
def
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
9
|
+
def configure_tailwind
|
|
10
|
+
if tailwind_configuration_path
|
|
11
|
+
insert_into_file tailwind_configuration_path, after: "content: [" do
|
|
12
|
+
"\n './app/views/**/*.rb', // Phlex views" \
|
|
13
|
+
"\n './app/components/**/*.rb', // Phlex components" \
|
|
14
|
+
end
|
|
15
|
+
end
|
|
18
16
|
end
|
|
19
17
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
inject_into_class(
|
|
24
|
-
APPLICATION_CONFIGURATION_PATH,
|
|
25
|
-
"Application",
|
|
26
|
-
%( config.autoload_paths << "\#{root}/app/views/layouts"\n)
|
|
27
|
-
)
|
|
18
|
+
def create_application_component
|
|
19
|
+
template "base_component.rb.erb", Rails.root.join("app/components/base.rb")
|
|
28
20
|
end
|
|
29
21
|
|
|
30
|
-
def
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
inject_into_class(
|
|
34
|
-
APPLICATION_CONFIGURATION_PATH,
|
|
35
|
-
"Application",
|
|
36
|
-
%( config.autoload_paths << "\#{root}/app/views"\n)
|
|
37
|
-
)
|
|
22
|
+
def create_application_view
|
|
23
|
+
template "base_view.rb.erb", Rails.root.join("app/views/base.rb")
|
|
38
24
|
end
|
|
39
25
|
|
|
40
|
-
def
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
insert_into_file TAILWIND_CONFIGURATION_PATH, after: "content: [" do
|
|
44
|
-
"\n './app/views/**/*.rb'," \
|
|
45
|
-
end
|
|
26
|
+
def create_hello_component
|
|
27
|
+
template "hello_component.rb.erb", Rails.root.join("app/components/hello.rb")
|
|
46
28
|
end
|
|
47
29
|
|
|
48
|
-
def
|
|
49
|
-
template "
|
|
30
|
+
def create_initializer
|
|
31
|
+
template "phlex.rb.erb", Rails.root.join("config/initializers/phlex.rb")
|
|
50
32
|
end
|
|
51
33
|
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def tailwind_configuration_path
|
|
37
|
+
if tailwind_configuration_files.any?
|
|
38
|
+
Pathname.new(
|
|
39
|
+
tailwind_configuration_files.first,
|
|
40
|
+
)
|
|
41
|
+
end
|
|
54
42
|
end
|
|
55
43
|
|
|
56
|
-
def
|
|
57
|
-
|
|
44
|
+
def tailwind_configuration_files
|
|
45
|
+
Dir.glob(
|
|
46
|
+
[
|
|
47
|
+
"#{Rails.root}/tailwind.config.js",
|
|
48
|
+
"#{Rails.root}/app/**/tailwind.config.js",
|
|
49
|
+
"#{Rails.root}/config/**/tailwind.config.js",
|
|
50
|
+
],
|
|
51
|
+
)
|
|
58
52
|
end
|
|
59
53
|
end
|
|
60
54
|
end
|
|
@@ -5,7 +5,7 @@ module Phlex::Generators
|
|
|
5
5
|
source_root File.expand_path("templates", __dir__)
|
|
6
6
|
|
|
7
7
|
def create_view
|
|
8
|
-
@path = File.join("app/views", class_path, "#{file_name}
|
|
8
|
+
@path = File.join("app/views", class_path, "#{file_name}.rb")
|
|
9
9
|
template "view.rb.erb", @path
|
|
10
10
|
end
|
|
11
11
|
end
|
data/lib/phlex/rails/buffered.rb
CHANGED
|
@@ -30,7 +30,7 @@ module Phlex::Rails
|
|
|
30
30
|
|
|
31
31
|
case output
|
|
32
32
|
when ::ActiveSupport::SafeBuffer
|
|
33
|
-
@view.instance_variable_get(:@_context).
|
|
33
|
+
@view.instance_variable_get(:@_context).buffer << output
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
nil
|
|
@@ -48,16 +48,15 @@ module Phlex::Rails
|
|
|
48
48
|
@object.respond_to?(...)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
def method_missing(
|
|
51
|
+
def method_missing(*, **, &block)
|
|
52
52
|
output = if block
|
|
53
|
-
@object.public_send(
|
|
53
|
+
@object.public_send(*, **) { |*a| @view.capture(*a, &block) }
|
|
54
54
|
else
|
|
55
|
-
@object.public_send(
|
|
55
|
+
@object.public_send(*, **)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@view.instance_variable_get(:@_context).target << output
|
|
58
|
+
if ::ActiveSupport::SafeBuffer === output
|
|
59
|
+
@view.instance_variable_get(:@_context).buffer << output
|
|
61
60
|
end
|
|
62
61
|
|
|
63
62
|
nil
|
data/lib/phlex/rails/csv.rb
CHANGED
|
@@ -4,11 +4,11 @@ module Phlex
|
|
|
4
4
|
module Rails
|
|
5
5
|
module CSV
|
|
6
6
|
module Overrides
|
|
7
|
-
def each_item(&
|
|
8
|
-
return super unless
|
|
7
|
+
def each_item(&)
|
|
8
|
+
return super unless ActiveRecord::Relation === collection
|
|
9
9
|
return super unless collection.arel.orders.empty?
|
|
10
10
|
|
|
11
|
-
collection.find_each(&
|
|
11
|
+
collection.find_each(&)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
data/lib/phlex/rails/engine.rb
CHANGED
|
@@ -16,12 +16,7 @@ module Phlex::Rails::HelperMacros
|
|
|
16
16
|
helpers.#{method_name}(*args, **kwargs)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
when ActiveSupport::SafeBuffer
|
|
21
|
-
@_context.target << output
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
nil
|
|
19
|
+
raw(output)
|
|
25
20
|
end
|
|
26
21
|
RUBY
|
|
27
22
|
end
|
|
@@ -63,12 +58,7 @@ module Phlex::Rails::HelperMacros
|
|
|
63
58
|
helpers.#{method_name}(*args, **kwargs)
|
|
64
59
|
end
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
when ActiveSupport::SafeBuffer
|
|
68
|
-
@_context.target << output
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
nil
|
|
61
|
+
raw(output)
|
|
72
62
|
end
|
|
73
63
|
RUBY
|
|
74
64
|
end
|
|
@@ -5,6 +5,7 @@ module Phlex::Rails::Helpers
|
|
|
5
5
|
module Routes
|
|
6
6
|
# This must be included first because it defines `url_options` rather than delegating it to the view context.
|
|
7
7
|
include Rails.application.routes.url_helpers
|
|
8
|
+
include Rails.application.routes.mounted_helpers
|
|
8
9
|
|
|
9
10
|
include URLOptions
|
|
10
11
|
include DefaultURLOptions
|
|
@@ -10,11 +10,11 @@ module Phlex::Rails::Helpers::Tag
|
|
|
10
10
|
|
|
11
11
|
case result
|
|
12
12
|
when ActiveSupport::SafeBuffer
|
|
13
|
-
@_context.
|
|
13
|
+
@_context.buffer << result
|
|
14
14
|
when ActionView::Helpers::TagHelper::TagBuilder
|
|
15
15
|
Phlex::Rails::Buffered.new(
|
|
16
16
|
result,
|
|
17
|
-
view: self
|
|
17
|
+
view: self,
|
|
18
18
|
)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -15,10 +15,10 @@ module Phlex::Rails::Helpers::Translate
|
|
|
15
15
|
base.extend(ClassMethods)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def translate(key, **
|
|
18
|
+
def translate(key, **)
|
|
19
19
|
key = "#{self.class.translation_path}#{key}" if key.start_with?(".")
|
|
20
20
|
|
|
21
|
-
helpers.t(key, **
|
|
21
|
+
helpers.t(key, **)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
alias_method :t, :translate
|
data/lib/phlex/rails/helpers.rb
CHANGED
|
@@ -12,8 +12,6 @@ module Phlex::Rails::Helpers
|
|
|
12
12
|
autoload :BuildTagValues, "phlex/rails/helpers/build_tag_values"
|
|
13
13
|
autoload :ButtonTag, "phlex/rails/helpers/button_tag"
|
|
14
14
|
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"
|
|
17
15
|
autoload :CheckBox, "phlex/rails/helpers/check_box"
|
|
18
16
|
autoload :CheckBoxTag, "phlex/rails/helpers/check_box_tag"
|
|
19
17
|
autoload :ClassNames, "phlex/rails/helpers/class_names"
|
|
@@ -29,11 +27,11 @@ module Phlex::Rails::Helpers
|
|
|
29
27
|
autoload :ContentTag, "phlex/rails/helpers/content_tag"
|
|
30
28
|
autoload :ControllerName, "phlex/rails/helpers/controller_name"
|
|
31
29
|
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"
|
|
32
32
|
autoload :CurrentCycle, "phlex/rails/helpers/current_cycle"
|
|
33
33
|
autoload :CurrentPage, "phlex/rails/helpers/current_page"
|
|
34
34
|
autoload :Cycle, "phlex/rails/helpers/cycle"
|
|
35
|
-
autoload :DOMClass, "phlex/rails/helpers/dom_class"
|
|
36
|
-
autoload :DOMID, "phlex/rails/helpers/dom_id"
|
|
37
35
|
autoload :DateField, "phlex/rails/helpers/date_field"
|
|
38
36
|
autoload :DateFieldTag, "phlex/rails/helpers/date_field_tag"
|
|
39
37
|
autoload :DateSelect, "phlex/rails/helpers/date_select"
|
|
@@ -46,6 +44,8 @@ module Phlex::Rails::Helpers
|
|
|
46
44
|
autoload :DefaultURLOptions, "phlex/rails/helpers/default_url_options"
|
|
47
45
|
autoload :DistanceOfTimeInWords, "phlex/rails/helpers/distance_of_time_in_words"
|
|
48
46
|
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"
|
|
49
49
|
autoload :EmailField, "phlex/rails/helpers/email_field"
|
|
50
50
|
autoload :EmailFieldTag, "phlex/rails/helpers/email_field_tag"
|
|
51
51
|
autoload :ErrorMessage, "phlex/rails/helpers/error_message"
|
|
@@ -55,8 +55,8 @@ module Phlex::Rails::Helpers
|
|
|
55
55
|
autoload :FaviconLinkTag, "phlex/rails/helpers/favicon_link_tag"
|
|
56
56
|
autoload :FieldID, "phlex/rails/helpers/field_id"
|
|
57
57
|
autoload :FieldName, "phlex/rails/helpers/field_name"
|
|
58
|
-
autoload :FieldSetTag, "phlex/rails/helpers/field_set_tag"
|
|
59
58
|
autoload :Fields, "phlex/rails/helpers/fields"
|
|
59
|
+
autoload :FieldSetTag, "phlex/rails/helpers/field_set_tag"
|
|
60
60
|
autoload :FieldsFor, "phlex/rails/helpers/fields_for"
|
|
61
61
|
autoload :FileField, "phlex/rails/helpers/file_field"
|
|
62
62
|
autoload :FileFieldTag, "phlex/rails/helpers/file_field_tag"
|
|
@@ -75,8 +75,8 @@ module Phlex::Rails::Helpers
|
|
|
75
75
|
autoload :ImageSubmitTag, "phlex/rails/helpers/image_submit_tag"
|
|
76
76
|
autoload :ImageTag, "phlex/rails/helpers/image_tag"
|
|
77
77
|
autoload :ImageURL, "phlex/rails/helpers/image_url"
|
|
78
|
-
autoload :JavascriptImportModuleTag, "phlex/rails/helpers/javascript_import_module_tag"
|
|
79
78
|
autoload :JavascriptImportmapTags, "phlex/rails/helpers/javascript_importmap_tags"
|
|
79
|
+
autoload :JavascriptImportModuleTag, "phlex/rails/helpers/javascript_import_module_tag"
|
|
80
80
|
autoload :JavascriptIncludeTag, "phlex/rails/helpers/javascript_include_tag"
|
|
81
81
|
autoload :JavascriptPath, "phlex/rails/helpers/javascript_path"
|
|
82
82
|
autoload :JavascriptTag, "phlex/rails/helpers/javascript_tag"
|
|
@@ -93,6 +93,7 @@ module Phlex::Rails::Helpers
|
|
|
93
93
|
autoload :MailTo, "phlex/rails/helpers/mail_to"
|
|
94
94
|
autoload :MonthField, "phlex/rails/helpers/month_field"
|
|
95
95
|
autoload :MonthFieldTag, "phlex/rails/helpers/month_field_tag"
|
|
96
|
+
autoload :Notice, "phlex/rails/helpers/notice"
|
|
96
97
|
autoload :NumberField, "phlex/rails/helpers/number_field"
|
|
97
98
|
autoload :NumberFieldTag, "phlex/rails/helpers/number_field_tag"
|
|
98
99
|
autoload :NumberToCurrency, "phlex/rails/helpers/number_to_currency"
|
|
@@ -130,7 +131,6 @@ module Phlex::Rails::Helpers
|
|
|
130
131
|
autoload :ResetCycle, "phlex/rails/helpers/reset_cycle"
|
|
131
132
|
autoload :RichTextArea, "phlex/rails/helpers/rich_text_area"
|
|
132
133
|
autoload :Routes, "phlex/rails/helpers/routes"
|
|
133
|
-
autoload :SMSTo, "phlex/rails/helpers/sms_to"
|
|
134
134
|
autoload :Sanitize, "phlex/rails/helpers/sanitize"
|
|
135
135
|
autoload :SanitizeCSS, "phlex/rails/helpers/sanitize_css"
|
|
136
136
|
autoload :SearchField, "phlex/rails/helpers/search_field"
|
|
@@ -147,6 +147,7 @@ module Phlex::Rails::Helpers
|
|
|
147
147
|
autoload :SelectTime, "phlex/rails/helpers/select_time"
|
|
148
148
|
autoload :SelectYear, "phlex/rails/helpers/select_year"
|
|
149
149
|
autoload :SimpleFormat, "phlex/rails/helpers/simple_format"
|
|
150
|
+
autoload :SMSTo, "phlex/rails/helpers/sms_to"
|
|
150
151
|
autoload :StripLinks, "phlex/rails/helpers/strip_links"
|
|
151
152
|
autoload :StripTags, "phlex/rails/helpers/strip_tags"
|
|
152
153
|
autoload :StylesheetLinkTag, "phlex/rails/helpers/stylesheet_link_tag"
|
|
@@ -173,9 +174,9 @@ module Phlex::Rails::Helpers
|
|
|
173
174
|
autoload :Truncate, "phlex/rails/helpers/truncate"
|
|
174
175
|
autoload :TurboFrameTag, "phlex/rails/helpers/turbo_frame_tag"
|
|
175
176
|
autoload :TurboIncludeTags, "phlex/rails/helpers/turbo_include_tags"
|
|
177
|
+
autoload :TurboRefreshesWith, "phlex/rails/helpers/turbo_refreshes_with"
|
|
176
178
|
autoload :TurboRefreshMethodTag, "phlex/rails/helpers/turbo_refresh_method_tag"
|
|
177
179
|
autoload :TurboRefreshScrollTag, "phlex/rails/helpers/turbo_refresh_scroll_tag"
|
|
178
|
-
autoload :TurboRefreshesWith, "phlex/rails/helpers/turbo_refreshes_with"
|
|
179
180
|
autoload :TurboStream, "phlex/rails/helpers/turbo_stream"
|
|
180
181
|
autoload :TurboStreamFrom, "phlex/rails/helpers/turbo_stream_from"
|
|
181
182
|
autoload :URLField, "phlex/rails/helpers/url_field"
|
|
@@ -193,56 +194,10 @@ module Phlex::Rails::Helpers
|
|
|
193
194
|
autoload :VideoPath, "phlex/rails/helpers/video_path"
|
|
194
195
|
autoload :VideoTag, "phlex/rails/helpers/video_tag"
|
|
195
196
|
autoload :VideoURL, "phlex/rails/helpers/video_url"
|
|
196
|
-
autoload :WeekField, "phlex/rails/helpers/week_field"
|
|
197
|
-
autoload :WeekFieldTag, "phlex/rails/helpers/week_field_tag"
|
|
198
197
|
autoload :WeekdayOptionsForSelect, "phlex/rails/helpers/weekday_options_for_select"
|
|
199
198
|
autoload :WeekdaySelect, "phlex/rails/helpers/weekday_select"
|
|
199
|
+
autoload :WeekField, "phlex/rails/helpers/week_field"
|
|
200
|
+
autoload :WeekFieldTag, "phlex/rails/helpers/week_field_tag"
|
|
200
201
|
autoload :WithOutputBuffer, "phlex/rails/helpers/with_output_buffer"
|
|
201
202
|
autoload :WordWrap, "phlex/rails/helpers/word_wrap"
|
|
202
|
-
|
|
203
|
-
DEPRECATED = {
|
|
204
|
-
Checkbox: :CheckBox,
|
|
205
|
-
CheckboxTag: :CheckBoxTag,
|
|
206
|
-
CollectionCheckboxes: :CollectionCheckBoxes,
|
|
207
|
-
DateTimeField: :DatetimeField,
|
|
208
|
-
PathToJavaScript: :PathToJavascript,
|
|
209
|
-
DateTimeFieldTag: :DatetimeFieldTag,
|
|
210
|
-
DateTimeLocalField: :DatetimeLocalField,
|
|
211
|
-
DateTimeLocalFieldTag: :DatetimeLocalFieldTag,
|
|
212
|
-
DateTimeSelect: :DatetimeSelect,
|
|
213
|
-
JavaScriptImportModuleTag: :JavascriptImportModuleTag,
|
|
214
|
-
JavaScriptImportMapTags: :JavascriptImportmapTags,
|
|
215
|
-
JavaScriptIncludeTag: :JavascriptIncludeTag,
|
|
216
|
-
JavaScriptPath: :JavascriptPath,
|
|
217
|
-
JavaScriptTag: :JavascriptTag,
|
|
218
|
-
JavaScriptURL: :JavascriptURL,
|
|
219
|
-
LinkIf: :LinkToIf,
|
|
220
|
-
PathToStyleSheet: :PathToStylesheet,
|
|
221
|
-
SanitizeCss: :SanitizeCSS,
|
|
222
|
-
SelectDateTime: :SelectDatetime,
|
|
223
|
-
StyleSheetLinkTag: :StylesheetLinkTag,
|
|
224
|
-
StyleSheetPath: :StylesheetPath,
|
|
225
|
-
StyleSheetURL: :StylesheetURL,
|
|
226
|
-
URLToJavaScript: :URLToJavascript,
|
|
227
|
-
URLToStyleSheet: :URLToStylesheet,
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
def self.const_missing(name)
|
|
231
|
-
if (helper_module_name = DEPRECATED[name])
|
|
232
|
-
message = "`Phlex::Rails::Helpers::#{name}` is deprecated. Please use `Phlex::Rails::Helpers::#{helper_module_name}` instead."
|
|
233
|
-
|
|
234
|
-
if name.to_s.downcase == helper_module_name.to_s.downcase
|
|
235
|
-
message << " Note the casing of the module name has changed to match the helper method."
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
Phlex::Rails::Deprecation.warn(message)
|
|
239
|
-
|
|
240
|
-
helper_module = const_get(helper_module_name)
|
|
241
|
-
const_set(name, helper_module)
|
|
242
|
-
|
|
243
|
-
helper_module
|
|
244
|
-
else
|
|
245
|
-
super
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
203
|
end
|
data/lib/phlex/rails/html.rb
CHANGED
data/lib/phlex/rails/layout.rb
CHANGED
|
@@ -14,11 +14,12 @@ module Phlex::Rails
|
|
|
14
14
|
include Helpers::JavascriptImportModuleTag
|
|
15
15
|
include Helpers::TurboRefreshMethodTag
|
|
16
16
|
include Helpers::TurboRefreshScrollTag
|
|
17
|
+
include Helpers::TurboRefreshesWith
|
|
17
18
|
|
|
18
19
|
# @api private
|
|
19
20
|
module Interface
|
|
20
|
-
def render(view_context, _locals, &
|
|
21
|
-
new.render(view_context, &
|
|
21
|
+
def render(view_context, _locals, &)
|
|
22
|
+
new.render(view_context, &)
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def identifier
|
|
@@ -48,7 +49,7 @@ module Phlex::Rails
|
|
|
48
49
|
if @_context
|
|
49
50
|
super
|
|
50
51
|
else
|
|
51
|
-
call(view_context:
|
|
52
|
+
call(view_context:) do |yielded|
|
|
52
53
|
case yielded
|
|
53
54
|
when Symbol
|
|
54
55
|
output = view_context.view_flow.get(yielded)
|
|
@@ -56,7 +57,7 @@ module Phlex::Rails
|
|
|
56
57
|
output = view_context.capture(&block)
|
|
57
58
|
end
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
raw output
|
|
60
61
|
end
|
|
61
62
|
end
|
|
62
63
|
end
|
data/lib/phlex/rails/sgml.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Phlex
|
|
|
11
11
|
|
|
12
12
|
module Overrides
|
|
13
13
|
def helpers
|
|
14
|
-
if defined?(ViewComponent::Base) &&
|
|
14
|
+
if defined?(ViewComponent::Base) && ViewComponent::Base === @_view_context
|
|
15
15
|
@_view_context.helpers
|
|
16
16
|
else
|
|
17
17
|
@_view_context
|
|
@@ -22,80 +22,62 @@ module Phlex
|
|
|
22
22
|
renderable = args[0]
|
|
23
23
|
|
|
24
24
|
case renderable
|
|
25
|
-
when Phlex::SGML, Proc, Method
|
|
25
|
+
when Phlex::SGML, Proc, Method, String
|
|
26
26
|
return super
|
|
27
27
|
when Class
|
|
28
28
|
return super if renderable < Phlex::SGML
|
|
29
29
|
when Enumerable
|
|
30
|
-
return super unless
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
return super unless ActiveRecord::Relation === renderable
|
|
31
|
+
when nil
|
|
32
|
+
partial = kwargs.delete(:partial)
|
|
33
|
+
|
|
34
|
+
if partial # this is a hack to get around https://github.com/rails/rails/issues/51015
|
|
35
|
+
return raw(
|
|
36
|
+
@_view_context.render(partial, **kwargs) do |*yielded_args|
|
|
37
|
+
capture(*yielded_args, &block)
|
|
38
|
+
end,
|
|
39
|
+
)
|
|
36
40
|
end
|
|
37
41
|
end
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
output = if block
|
|
44
|
+
@_view_context.render(*args, **kwargs) do |*yielded_args|
|
|
45
|
+
if yielded_args.length == 1 && defined?(ViewComponent::Base) && ViewComponent::Base === yielded_args[0]
|
|
46
|
+
capture(Phlex::Rails::Buffered.new(yielded_args[0], view: self), &block)
|
|
47
|
+
else
|
|
48
|
+
capture(*yielded_args, &block)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
@_view_context.render(*args, **kwargs)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
raw(output)
|
|
40
56
|
end
|
|
41
57
|
|
|
42
|
-
def render_in(view_context, &
|
|
58
|
+
def render_in(view_context, &erb)
|
|
43
59
|
fragments = if view_context.request && (fragment_header = view_context.request.headers["X-Fragment"])
|
|
44
60
|
fragment_header.split
|
|
45
61
|
end
|
|
46
62
|
|
|
47
|
-
if
|
|
48
|
-
call(view_context
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
output = view_context.capture(
|
|
53
|
-
args[0].unbuffered, &block
|
|
54
|
-
)
|
|
63
|
+
if erb
|
|
64
|
+
call(view_context:, fragments:) { |*args|
|
|
65
|
+
if args.length == 1 && Phlex::SGML === args[0] && !erb.source_location&.[](0)&.end_with?(".rb")
|
|
66
|
+
unbuffered = Phlex::Rails::Unbuffered.new(args[0])
|
|
67
|
+
raw(helpers.capture(unbuffered, &erb))
|
|
55
68
|
else
|
|
56
|
-
|
|
69
|
+
raw(helpers.capture(*args, &erb))
|
|
57
70
|
end
|
|
58
|
-
|
|
59
|
-
unchanged = (original_length == @_context.target.bytesize)
|
|
60
|
-
|
|
61
|
-
if unchanged
|
|
62
|
-
case output
|
|
63
|
-
when ActiveSupport::SafeBuffer
|
|
64
|
-
@_context.target << output
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end.html_safe
|
|
71
|
+
}.html_safe
|
|
68
72
|
else
|
|
69
|
-
call(view_context
|
|
73
|
+
call(view_context:, fragments:).html_safe
|
|
70
74
|
end
|
|
71
75
|
end
|
|
72
76
|
|
|
73
|
-
def capture
|
|
77
|
+
def capture(...)
|
|
74
78
|
super&.html_safe
|
|
75
79
|
end
|
|
76
80
|
|
|
77
|
-
# @api private
|
|
78
|
-
def __text__(content)
|
|
79
|
-
case content
|
|
80
|
-
when ActiveSupport::SafeBuffer
|
|
81
|
-
@_context.target << content
|
|
82
|
-
else
|
|
83
|
-
super
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# TODO: Re-introduce this when we can figure out how to test it
|
|
88
|
-
# def await(task)
|
|
89
|
-
# case task
|
|
90
|
-
# when ActiveRecord::Relation
|
|
91
|
-
# future = task.instance_variable_get(:@future_result)
|
|
92
|
-
# flush if future && future.pending?
|
|
93
|
-
# task
|
|
94
|
-
# else
|
|
95
|
-
# super
|
|
96
|
-
# end
|
|
97
|
-
# end
|
|
98
|
-
|
|
99
81
|
# Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
|
|
100
82
|
# @api private
|
|
101
83
|
def set_original_view_context(view_context)
|
|
@@ -7,17 +7,19 @@ module Phlex::Rails::Streaming
|
|
|
7
7
|
private
|
|
8
8
|
|
|
9
9
|
def stream(view, last_modified: Time.now.httpdate, filename: nil)
|
|
10
|
-
|
|
10
|
+
__phlex_set_stream_headers__(last_modified:)
|
|
11
11
|
|
|
12
12
|
case view
|
|
13
13
|
when Phlex::HTML
|
|
14
|
-
|
|
14
|
+
__phlex_stream_html__(view)
|
|
15
15
|
when Phlex::CSV
|
|
16
|
-
|
|
16
|
+
__phlex_stream_csv__(view, filename:)
|
|
17
|
+
else
|
|
18
|
+
raise Phlex::ArgumentError
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
def
|
|
22
|
+
def __phlex_set_stream_headers__(last_modified:)
|
|
21
23
|
headers.delete("Content-Length")
|
|
22
24
|
|
|
23
25
|
headers["X-Accel-Buffering"] = "no"
|
|
@@ -25,16 +27,16 @@ module Phlex::Rails::Streaming
|
|
|
25
27
|
headers["Last-Modified"] = last_modified
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
def
|
|
30
|
+
def __phlex_stream_csv__(view, filename:)
|
|
29
31
|
headers["Content-Type"] = "text/csv; charset=utf-8"
|
|
30
32
|
headers["Content-Disposition"] = "attachment; filename=\"#{filename || view.filename}\""
|
|
31
33
|
|
|
32
34
|
self.response_body = Enumerator.new do |buffer|
|
|
33
|
-
view.call(buffer, view_context:
|
|
35
|
+
view.call(buffer, view_context:)
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
def
|
|
39
|
+
def __phlex_stream_html__(view)
|
|
38
40
|
headers["Content-Type"] = "text/html; charset=utf-8"
|
|
39
41
|
|
|
40
42
|
# Ensure we have a session id.
|
|
@@ -45,13 +47,13 @@ module Phlex::Rails::Streaming
|
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
self.response_body = Enumerator.new do |buffer|
|
|
48
|
-
view.call(buffer, view_context:
|
|
50
|
+
view.call(buffer, view_context:)
|
|
49
51
|
rescue => e
|
|
50
52
|
raise(e) if Rails.env.test?
|
|
51
53
|
|
|
52
54
|
debug_middleware = ActionDispatch::DebugExceptions.new(
|
|
53
55
|
proc { |_env| raise(e) },
|
|
54
|
-
response_format: :html
|
|
56
|
+
response_format: :html,
|
|
55
57
|
)
|
|
56
58
|
|
|
57
59
|
_debug_status, _debug_headers, debug_body = debug_middleware.call(request.env)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "phlex/rails"
|
|
4
|
+
require "phlex/testing"
|
|
5
|
+
|
|
6
|
+
module Phlex::Testing::RailsContext
|
|
7
|
+
def view_context
|
|
8
|
+
controller.view_context
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def controller
|
|
12
|
+
@controller ||= ActionView::TestCase::TestController.new
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Phlex::Testing::SGML.include(
|
|
17
|
+
Phlex::Testing::RailsContext,
|
|
18
|
+
)
|