nice_partials 0.9.0 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/lib/nice_partials/partial/section.rb +7 -3
- data/lib/nice_partials/partial.rb +18 -9
- data/lib/nice_partials/version.rb +1 -1
- metadata +3 -4
- data/nice_partials.gemspec +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8c2fc27ad0c01eda3e489191c6ba385498ec49580f38400f8447600ee8d0488
|
4
|
+
data.tar.gz: e138bd379b7f805e0be27054d6a689e31d58169e27ad118bec43a3538b24c9f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -24,7 +24,6 @@ class NicePartials::Partial::Section < NicePartials::Partial::Content
|
|
24
24
|
# <% partial.title.h2 ", appended" %> # => <h2 class="xl">Some title content, appended</h2>
|
25
25
|
#
|
26
26
|
# Note that NicePartials don't support deep merging attributes out of the box.
|
27
|
-
# For that, bundle https://github.com/seanpdoyle/attributes_and_token_lists
|
28
27
|
def method_missing(meth, *arguments, **keywords, &block)
|
29
28
|
if meth != :p && @view_context.respond_to?(meth)
|
30
29
|
append @view_context.public_send(meth, *arguments, **keywords, &block)
|
@@ -32,7 +31,10 @@ class NicePartials::Partial::Section < NicePartials::Partial::Content
|
|
32
31
|
@view_context.tag.public_send(meth, @content + arguments.first.to_s, **options.merge(keywords), &block)
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
34
|
+
|
35
|
+
def respond_to_missing?(...)
|
36
|
+
@view_context.respond_to?(...)
|
37
|
+
end
|
36
38
|
|
37
39
|
private
|
38
40
|
|
@@ -44,5 +46,7 @@ class NicePartials::Partial::Section < NicePartials::Partial::Content
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
def chunks
|
49
|
+
def chunks
|
50
|
+
@chunks ||= []
|
51
|
+
end
|
48
52
|
end
|
@@ -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
|
-
|
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
|
-
|
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
|
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.
|
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-
|
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.
|
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.
|
data/nice_partials.gemspec
DELETED
@@ -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
|