phlex-rails 2.0.0.beta2 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 884bb8de02703c59d0756050a402a853af780a4c9bc37805483d3446b17acdb2
4
- data.tar.gz: de4bd44c31da7580ec9c158d1d004b03c3be89b419b78abc5c6eb9b67b97e1c0
3
+ metadata.gz: 82a501ef5c7c4fafcc63ec4cab4c4e2463be6dbdb467af0bb87ef03cf0bd4b10
4
+ data.tar.gz: 781b9217536035e543e9ddc9db55dbfca518faf40974804eced2b49b8b9db97e
5
5
  SHA512:
6
- metadata.gz: 20f911fd5441cbca7281b63c94b4d1f3ef8b604c88550b5e0b1c4889eab9286f827430a7e05cd35b3be8c49d9d0679f781c33ee8d0e7a6d8bdfbf3676d3a54bd
7
- data.tar.gz: 0a096db9f03bc6164b5cf951128a2b751d2de052588aea26f1a8c82a36d125798c198fbd32b06ebce2e0b6c65c52158f8d17e0d61586408307cd98808266e84b
6
+ metadata.gz: b21338b1d04ef04300133459bdbbf27d9cd07c023bbc7bdf0282c310ef214170be4d12a30fc9a1637fcc00db54329728ddd6852cd7d2d14fb047d651b37f3cee
7
+ data.tar.gz: 05f5a87850528bcf32ec8dafce55971a2dbdfaa5a17e0e7291d6a040e761da706ad83d54310562e8f0da59fb26b8cd5ed3d5642fa41bb95bf6304e187d7ad9a9
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Views::Base < Components::Base
4
- # The ApplicationView is an abstract class for all your views.
4
+ # The `Views::Base` is an abstract class for all your views.
5
5
 
6
- # By default, it inherits from `ApplicationComponent`, but you
6
+ # By default, it inherits from `Components::Base`, but you
7
7
  # can change that to `Phlex::HTML` if you want to keep views and
8
8
  # components independent.
9
9
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Phlex::Rails::Partial
4
+ def initialize(path, *args, **kwargs, &block)
5
+ @path = path
6
+ @args = args
7
+ @kwargs = kwargs
8
+ @block = block
9
+ end
10
+
11
+ def render_in(view_context, &block)
12
+ block ||= @block
13
+ view_context.render(@path, *@args, **@kwargs, &block)
14
+ end
15
+ end
@@ -10,11 +10,25 @@ module Phlex
10
10
  end
11
11
 
12
12
  module Overrides
13
+ class HelpersCalledBeforeRenderError < StandardError; end
14
+
15
+ def partial(*, **, &block)
16
+ if block
17
+ Phlex::Rails::Partial.new(*, **) { capture(&block) }
18
+ else
19
+ Phlex::Rails::Partial.new(*, **)
20
+ end
21
+ end
22
+
13
23
  def helpers
14
- if defined?(ViewComponent::Base) && ViewComponent::Base === @_view_context
15
- @_view_context.helpers
24
+ unless @_context && (view_context = @_context.view_context)
25
+ raise HelpersCalledBeforeRenderError.new("Do not use rails helpers until after the view has been rendered.") unless view_context
26
+ end
27
+
28
+ if defined?(ViewComponent::Base) && ViewComponent::Base === view_context
29
+ view_context.helpers
16
30
  else
17
- @_view_context
31
+ view_context
18
32
  end
19
33
  end
20
34
 
@@ -28,20 +42,12 @@ module Phlex
28
42
  return super if renderable < Phlex::SGML
29
43
  when Enumerable
30
44
  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
- )
40
- end
41
45
  end
42
46
 
47
+ return super if args.length == 0 && kwargs.length == 0
48
+
43
49
  output = if block
44
- @_view_context.render(*args, **kwargs) do |*yielded_args|
50
+ @_context.view_context.render(*args, **kwargs) do |*yielded_args|
45
51
  if yielded_args.length == 1 && defined?(ViewComponent::Base) && ViewComponent::Base === yielded_args[0]
46
52
  capture(Phlex::Rails::Buffered.new(yielded_args[0], view: self), &block)
47
53
  else
@@ -49,7 +55,7 @@ module Phlex
49
55
  end
50
56
  end
51
57
  else
52
- @_view_context.render(*args, **kwargs)
58
+ @_context.view_context.render(*args, **kwargs)
53
59
  end
54
60
 
55
61
  raw(output)
@@ -13,6 +13,6 @@ module Phlex::Testing::RailsContext
13
13
  end
14
14
  end
15
15
 
16
- Phlex::Testing::SGML.include(
16
+ Phlex::Testing::SGML.prepend(
17
17
  Phlex::Testing::RailsContext,
18
18
  )
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "2.0.0.beta2"
5
+ VERSION = "2.0.0.rc1"
6
6
  end
7
7
  end
data/lib/phlex/rails.rb CHANGED
@@ -12,11 +12,12 @@ module Phlex
12
12
  autoload :BufferedRadioButtonBuilder, "phlex/rails/buffered_radio_button_builder"
13
13
  autoload :CSV, "phlex/rails/csv"
14
14
  autoload :FragmentFinder, "phlex/rails/fragment_finder"
15
+ autoload :HTML, "phlex/rails/html"
15
16
  autoload :HelperFinder, "phlex/rails/helper_finder"
16
17
  autoload :HelperMacros, "phlex/rails/helper_macros"
17
18
  autoload :Helpers, "phlex/rails/helpers"
18
- autoload :HTML, "phlex/rails/html"
19
19
  autoload :Layout, "phlex/rails/layout"
20
+ autoload :Partial, "phlex/rails/partial"
20
21
  autoload :SGML, "phlex/rails/sgml"
21
22
  autoload :Streaming, "phlex/rails/streaming"
22
23
  autoload :Unbuffered, "phlex/rails/unbuffered"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta2
4
+ version: 2.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-14 00:00:00.000000000 Z
11
+ date: 2024-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0.beta2
19
+ version: 2.0.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0.beta2
26
+ version: 2.0.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '6.1'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '8'
36
+ version: '9'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '6.1'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '8'
46
+ version: '9'
47
47
  description: A high-performance view framework optimised for fun.
48
48
  email:
49
49
  - joel@drapper.me
@@ -277,6 +277,7 @@ files:
277
277
  - lib/phlex/rails/helpers/word_wrap.rb
278
278
  - lib/phlex/rails/html.rb
279
279
  - lib/phlex/rails/layout.rb
280
+ - lib/phlex/rails/partial.rb
280
281
  - lib/phlex/rails/sgml.rb
281
282
  - lib/phlex/rails/streaming.rb
282
283
  - lib/phlex/rails/testing.rb