nice_partials 0.9.1 → 0.9.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a1bc9c01590139038135f1cd6856c79529485c970225a5aa4d82a35d11bc33a
4
- data.tar.gz: 19f2f3754c6c590745ee649a94e32de934ced12a2602956d0aa7fff7a8db4c74
3
+ metadata.gz: 14580892ce441161fda38b893e61d4b4733b1fd1c0130f22cf73dc7170f9ddd2
4
+ data.tar.gz: '0696801e28b1ab5f3574cca9d71bcb03a702fa76d5076a25881ef0dfaa883638'
5
5
  SHA512:
6
- metadata.gz: 99fca66a8450503cbd2348187680c0f82b995d1830515cebe35401d9fd4e1d2395ba35fceedeb18bf4bf36ffbc8a4273811344a4c5fa58d7e5981d6d0ac9b866
7
- data.tar.gz: b3215bcdb6c639faeed18ec17b57bdcaba2c71c70a738c25c48faf00201535198b5dbb56f18686a2b2a2877d5896246275012cad0555ff2e558c13684291f805
6
+ metadata.gz: 302fdc205c1c433b670bcdd22d45a0a66bccdcdc15fae841ef88ae0209079a77cd2bddff199060a17be941164a7a8e852c16d6b508674483e123eebdb8f5c892
7
+ data.tar.gz: 8b9cff626b4a6c713d274609427c6ed28dbc20a31b9825aa52b21e8670c59f37e5c1f5552460a357ff06b47aca3af7a0fd78c937882bf6779c8f0281ac2b6b0c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  ## CHANGELOG
2
2
 
3
+ ### 0.9.3
4
+
5
+ * Fixed: section predicates not respecting `local_assigns` content
6
+
7
+ Previously, when doing something like this:
8
+
9
+ ```erb
10
+ <%= render "card", title: "Hello there" %>
11
+ ```
12
+
13
+ If the inner card partial had this,
14
+
15
+ ```erb
16
+ <% if partial.title? %>
17
+ <%= partial.title %>
18
+ <% end %>
19
+ ```
20
+
21
+ The `title?` predicate would fail, because it didn't look up content from the passed `local_assigns`. Now it does.
22
+
23
+ ### 0.9.2
24
+
25
+ * Changed: view methods don't clobber section names
26
+
27
+ Previously, we'd eagerly delegate to the view context so if the view had a `label` method, `partial.label` would call the view's `label` instead of making a `label` section.
28
+
29
+ This was to support `partial.helpers` but we've changed the implementation to support the above. `partial.helpers` still works the same too.
30
+
31
+ * Changed: `partial.helpers` no longer automatically calls `partial` methods
32
+
33
+ Previously, if a user defined a partial helper like this:
34
+
35
+ ```ruby
36
+ partial.helpers do
37
+ def some_helper
38
+ some_section
39
+ end
40
+ end
41
+ ```
42
+
43
+ If `some_section` wasn't a view method, it would automatically call `partial.some_section`
44
+ thereby adding a new content section to the partial.
45
+
46
+ Now `partial.helpers` behaves exactly like view helpers — making it easier to copy code directly when migrating — so users would have to explicitly call `partial.some_section`.
47
+
48
+ ### 0.9.1
49
+
50
+ * Fix Ruby 2.7 compatibility
51
+
52
+ ### 0.9.0
53
+
3
54
  * Fix rendering with special characters in a view path.
4
55
 
5
56
  Ref: https://github.com/bullet-train-co/nice_partials/pull/70
@@ -8,7 +8,7 @@ module NicePartials::RenderingWithLocalePrefix
8
8
  end
9
9
 
10
10
  def t(key, options = {})
11
- if (prefix = @_nice_partials_t_prefix) && key.first == '.'
11
+ if (prefix = @_nice_partials_t_prefix) && key&.start_with?(".")
12
12
  key = "#{prefix}#{key}"
13
13
  end
14
14
 
@@ -4,8 +4,6 @@ module NicePartials
4
4
  autoload :Section, "nice_partials/partial/section"
5
5
  autoload :Stack, "nice_partials/partial/stack"
6
6
 
7
- delegate_missing_to :@view_context
8
-
9
7
  def initialize(view_context, local_assigns = nil)
10
8
  @view_context, @local_assigns = view_context, local_assigns
11
9
  end
@@ -19,7 +17,7 @@ module NicePartials
19
17
  end
20
18
 
21
19
  def helpers(&block)
22
- self.class.class_eval(&block)
20
+ Helpers.class_eval(&block)
23
21
  end
24
22
 
25
23
  # `translate` is a shorthand to set `content_for` with content that's run through
@@ -72,12 +70,12 @@ module NicePartials
72
70
  end
73
71
 
74
72
  def section?(name)
75
- @sections&.dig(name).present?
73
+ section_from(name).present?
76
74
  end
77
75
  alias content_for? section?
78
76
 
79
77
  def content_for(...)
80
- section(...)&.to_s
78
+ section(...).presence&.to_s
81
79
  end
82
80
 
83
81
  def slice(*keys)
@@ -94,12 +92,12 @@ module NicePartials
94
92
  @sections ||= {} and @sections[name] ||= Section.new(@view_context, @local_assigns&.dig(name))
95
93
  end
96
94
 
95
+ def respond_to_missing?(meth, include_private = false)
96
+ meth != :to_ary # Avoid creating a section when doing `*partial`.
97
+ end
98
+
97
99
  def method_missing(meth, *arguments, **keywords, &block)
98
- if @view_context.respond_to?(meth)
99
- @view_context.public_send(meth, *arguments, **keywords, &block)
100
- else
101
- define_accessor meth and public_send(meth, *arguments, **keywords, &block)
102
- end
100
+ define_accessor meth and public_send(meth, *arguments, **keywords, &block)
103
101
  end
104
102
 
105
103
  def define_accessor(name)
@@ -107,5 +105,16 @@ module NicePartials
107
105
  self.class.define_method(name) { |content = nil, **options, &block| section(name, content, **options, &block) }
108
106
  self.class.define_method("#{name}?") { section?(name) }
109
107
  end
108
+
109
+ def helpers_context
110
+ @helpers_context ||= Helpers.new(@view_context)
111
+ end
112
+
113
+ class Helpers < SimpleDelegator
114
+ def self.method_added(name)
115
+ super
116
+ NicePartials::Partial.delegate name, to: :helpers_context
117
+ end
118
+ end
110
119
  end
111
120
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NicePartials
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_partials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-01-16 00:00:00.000000000 Z
12
+ date: 2023-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionview
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.4.1
98
+ rubygems_version: 3.4.7
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: A little bit of magic to make partials perfect for components.