nice_partials 0.9.1 → 0.9.2

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: 3a1bc9c01590139038135f1cd6856c79529485c970225a5aa4d82a35d11bc33a
4
- data.tar.gz: 19f2f3754c6c590745ee649a94e32de934ced12a2602956d0aa7fff7a8db4c74
3
+ metadata.gz: e8c2fc27ad0c01eda3e489191c6ba385498ec49580f38400f8447600ee8d0488
4
+ data.tar.gz: e138bd379b7f805e0be27054d6a689e31d58169e27ad118bec43a3538b24c9f9
5
5
  SHA512:
6
- metadata.gz: 99fca66a8450503cbd2348187680c0f82b995d1830515cebe35401d9fd4e1d2395ba35fceedeb18bf4bf36ffbc8a4273811344a4c5fa58d7e5981d6d0ac9b866
7
- data.tar.gz: b3215bcdb6c639faeed18ec17b57bdcaba2c71c70a738c25c48faf00201535198b5dbb56f18686a2b2a2877d5896246275012cad0555ff2e558c13684291f805
6
+ metadata.gz: 24aa6946079c6663a907b6e7eb2c6158b07105bc3cf0273a9907c2a7732fc6ba030e3b733b8beacd1221288e32c995067a0af6b30649e8a6c8ec7960e8adcd22
7
+ data.tar.gz: 70548909852322e987e7a11aafb81f927b9652ac03bef500f1ddf3b3daca915bc37d22270a537a37580ac67e0fa76ef158bc7a783bf8327c603ad108cc275a5b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  ## CHANGELOG
2
2
 
3
+ ### 0.9.2
4
+
5
+ * Changed: view methods don't clobber section names
6
+
7
+ 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.
8
+
9
+ This was to support `partial.helpers` but we've changed the implementation to support the above. `partial.helpers` still works the same too.
10
+
11
+ * Changed: `partial.helpers` no longer automatically calls `partial` methods
12
+
13
+ Previously, if a user defined a partial helper like this:
14
+
15
+ ```ruby
16
+ partial.helpers do
17
+ def some_helper
18
+ some_section
19
+ end
20
+ end
21
+ ```
22
+
23
+ If `some_section` wasn't a view method, it would automatically call `partial.some_section`
24
+ thereby adding a new content section to the partial.
25
+
26
+ 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`.
27
+
28
+ ### 0.9.1
29
+
30
+ * Fix Ruby 2.7 compatibility
31
+
32
+ ### 0.9.0
33
+
3
34
  * Fix rendering with special characters in a view path.
4
35
 
5
36
  Ref: https://github.com/bullet-train-co/nice_partials/pull/70
@@ -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
@@ -77,7 +75,7 @@ module NicePartials
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.2"
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.2
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-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionview
@@ -75,7 +75,6 @@ files:
75
75
  - lib/nice_partials/partial/section.rb
76
76
  - lib/nice_partials/partial/stack.rb
77
77
  - lib/nice_partials/version.rb
78
- - nice_partials.gemspec
79
78
  homepage: https://github.com/bullet-train-co/nice_partials
80
79
  licenses:
81
80
  - MIT
@@ -95,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
96
  requirements: []
98
- rubygems_version: 3.4.1
97
+ rubygems_version: 3.3.7
99
98
  signing_key:
100
99
  specification_version: 4
101
100
  summary: A little bit of magic to make partials perfect for components.
@@ -1,32 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__) + "/lib/nice_partials/version"
4
-
5
- Gem::Specification.new do |gem|
6
- gem.name = "nice_partials"
7
- gem.version = NicePartials::VERSION
8
- gem.summary = "A little bit of magic to make partials perfect for components."
9
- gem.description = "A little bit of magic to make partials perfect for components."
10
- gem.authors = ["Andrew Culver", "Dom Christie"]
11
- gem.email = ["andrew.culver@gmail.com", "christiedom@gmail.com"]
12
- gem.homepage = "https://github.com/bullet-train-co/nice_partials"
13
- gem.license = "MIT"
14
-
15
- # Specify which files should be added to the gem when it is released.
16
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- gem.files = Dir.chdir(__dir__) do
18
- `git ls-files -z`.split("\x0").reject do |f|
19
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
20
- end
21
- end
22
- gem.bindir = "exe"
23
- gem.executables = gem.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
24
- gem.require_paths = ["lib"]
25
-
26
- gem.required_ruby_version = ">= 2.0"
27
-
28
- gem.add_dependency "actionview", '>= 4.2.6'
29
-
30
- gem.add_development_dependency "rails"
31
- gem.add_development_dependency "standard"
32
- end