view_component 2.1.0 → 2.2.0
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.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +2 -2
- data/README.md +4 -9
- data/lib/rails/generators/component/component_generator.rb +3 -5
- data/lib/rails/generators/component/templates/component.rb.tt +2 -0
- data/lib/view_component/base.rb +22 -18
- data/lib/view_component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '038805cb5a61ac698697344495e23064c227e169079586e1412f43aee0a7abde'
|
4
|
+
data.tar.gz: bb53f4c2407eec96e618aba01f4f35cfa564bfc8738c709af434c16a412457d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7adf9a57806404434ad35b23d4df069dfe2a346cb35945e9103b16197e0f86c2b994d1470334c324ee38365781f5be5742a1e42369309a5d29a15f5f3e8b01c8
|
7
|
+
data.tar.gz: ce7cb220863df4567a97f472fa576fdd96b045aa7ef507c456c69616270195448204a0a6cf01889d177b7430a7fc4f59486af74ad85463927e20427bde3ad996
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
# v2.2.0
|
4
|
+
|
5
|
+
* Add support for `config.action_view.annotate_template_file_names` (coming in Rails 6.1).
|
6
|
+
|
7
|
+
*Joel Hawksley*
|
8
|
+
|
9
|
+
* Remove initializer requirement from the component.
|
10
|
+
|
11
|
+
*Vasiliy Ermolovich*
|
12
|
+
|
3
13
|
# v2.1.0
|
4
14
|
|
5
15
|
* Support rendering collections (e.g., `render(MyComponent.with_collection(@items))`).
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
view_component (2.
|
4
|
+
view_component (2.2.0)
|
5
5
|
capybara (~> 3)
|
6
6
|
|
7
7
|
GEM
|
@@ -74,7 +74,7 @@ GEM
|
|
74
74
|
parser (>= 2.4)
|
75
75
|
smart_properties
|
76
76
|
builder (3.2.4)
|
77
|
-
capybara (3.
|
77
|
+
capybara (3.32.0)
|
78
78
|
addressable
|
79
79
|
mini_mime (>= 0.1.3)
|
80
80
|
nokogiri (~> 1.8)
|
data/README.md
CHANGED
@@ -152,8 +152,6 @@ Which returns:
|
|
152
152
|
<span title="my title">Hello, World!</span>
|
153
153
|
```
|
154
154
|
|
155
|
-
`ViewComponent` requires the presence of an `initialize` method in each component.
|
156
|
-
|
157
155
|
#### Content Areas
|
158
156
|
|
159
157
|
A component can declare additional content areas to be rendered in the component. For example:
|
@@ -162,9 +160,6 @@ A component can declare additional content areas to be rendered in the component
|
|
162
160
|
```ruby
|
163
161
|
class ModalComponent < ViewComponent::Base
|
164
162
|
with_content_areas :header, :body
|
165
|
-
|
166
|
-
def initialize(*)
|
167
|
-
end
|
168
163
|
end
|
169
164
|
```
|
170
165
|
|
@@ -498,10 +493,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/github
|
|
498
493
|
|@mellowfish|@horacio|@dukex|@dark-panda|@smashwilson|
|
499
494
|
|Spring Hill, TN|Buenos Aires|São Paulo||Gambrills, MD|
|
500
495
|
|
501
|
-
|<img src="https://avatars.githubusercontent.com/blakewilliams?s=256" alt="blakewilliams" width="128" />|<img src="https://avatars.githubusercontent.com/seanpdoyle?s=256" alt="seanpdoyle" width="128" />|<img src="https://avatars.githubusercontent.com/tclem?s=256" alt="tclem" width="128"
|
502
|
-
|
503
|
-
|@blakewilliams|@seanpdoyle|@tclem|
|
504
|
-
|Boston, MA|New York, NY|San Francisco, CA|
|
496
|
+
|<img src="https://avatars.githubusercontent.com/blakewilliams?s=256" alt="blakewilliams" width="128" />|<img src="https://avatars.githubusercontent.com/seanpdoyle?s=256" alt="seanpdoyle" width="128" />|<img src="https://avatars.githubusercontent.com/tclem?s=256" alt="tclem" width="128" />|<img src="https://avatars.githubusercontent.com/nashby?s=256" alt="nashby" width="128" />
|
497
|
+
|:---:|:---:|:---:|:---:|
|
498
|
+
|@blakewilliams|@seanpdoyle|@tclem|@nashby|
|
499
|
+
|Boston, MA|New York, NY|San Francisco, CA|Minsk|
|
505
500
|
|
506
501
|
## License
|
507
502
|
|
@@ -29,11 +29,9 @@ module Rails
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def initialize_signature
|
32
|
-
if attributes.
|
33
|
-
|
34
|
-
|
35
|
-
"*"
|
36
|
-
end
|
32
|
+
return if attributes.blank?
|
33
|
+
|
34
|
+
attributes.map { |attr| "#{attr.name}:" }.join(", ")
|
37
35
|
end
|
38
36
|
|
39
37
|
def initialize_body
|
data/lib/view_component/base.rb
CHANGED
@@ -77,6 +77,10 @@ module ViewComponent
|
|
77
77
|
true
|
78
78
|
end
|
79
79
|
|
80
|
+
def self.short_identifier
|
81
|
+
@short_identifier ||= defined?(Rails.root) ? source_location.sub("#{Rails.root}/", "") : source_location
|
82
|
+
end
|
83
|
+
|
80
84
|
def initialize(*); end
|
81
85
|
|
82
86
|
def render(options = {}, args = {}, &block)
|
@@ -137,11 +141,15 @@ module ViewComponent
|
|
137
141
|
@@test_controller = "ApplicationController"
|
138
142
|
|
139
143
|
class << self
|
144
|
+
attr_accessor :source_location
|
145
|
+
|
140
146
|
def inherited(child)
|
141
147
|
if defined?(Rails)
|
142
148
|
child.include Rails.application.routes.url_helpers unless child < Rails.application.routes.url_helpers
|
143
149
|
end
|
144
150
|
|
151
|
+
child.source_location = caller_locations(1, 1)[0].absolute_path
|
152
|
+
|
145
153
|
super
|
146
154
|
end
|
147
155
|
|
@@ -153,16 +161,6 @@ module ViewComponent
|
|
153
161
|
end
|
154
162
|
end
|
155
163
|
|
156
|
-
def source_location
|
157
|
-
@source_location ||=
|
158
|
-
begin
|
159
|
-
# Require `#initialize` to be defined so that we can use `method#source_location`
|
160
|
-
# to look up the filename of the component.
|
161
|
-
initialize_method = instance_method(:initialize)
|
162
|
-
initialize_method.source_location[0] if initialize_method.owner == self
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
164
|
def compiled?
|
167
165
|
@compiled && ActionView::Base.cache_template_loading
|
168
166
|
end
|
@@ -186,8 +184,20 @@ module ViewComponent
|
|
186
184
|
return false
|
187
185
|
end
|
188
186
|
|
187
|
+
# If template name annotations are turned on, a line is dynamically
|
188
|
+
# added with a comment. In this case, we want to return a different
|
189
|
+
# starting line number so errors that are raised will point to the
|
190
|
+
# correct line in the component template.
|
191
|
+
line_number =
|
192
|
+
if ActionView::Base.respond_to?(:annotate_template_file_names) &&
|
193
|
+
ActionView::Base.annotate_template_file_names
|
194
|
+
-2
|
195
|
+
else
|
196
|
+
-1
|
197
|
+
end
|
198
|
+
|
189
199
|
templates.each do |template|
|
190
|
-
class_eval <<-RUBY, template[:path],
|
200
|
+
class_eval <<-RUBY, template[:path], line_number
|
191
201
|
def #{call_method_name(template[:variant])}
|
192
202
|
@output_buffer = ActionView::OutputBuffer.new
|
193
203
|
#{compiled_template(template[:path])}
|
@@ -252,12 +262,6 @@ module ViewComponent
|
|
252
262
|
@template_errors ||=
|
253
263
|
begin
|
254
264
|
errors = []
|
255
|
-
if source_location.nil?
|
256
|
-
# Require `#initialize` to be defined so that we can use `method#source_location`
|
257
|
-
# to look up the filename of the component.
|
258
|
-
errors << "#{self} must implement #initialize."
|
259
|
-
end
|
260
|
-
|
261
265
|
errors << "Could not find a template file for #{self}." if templates.empty?
|
262
266
|
|
263
267
|
if templates.count { |template| template[:variant].nil? } > 1
|
@@ -283,7 +287,7 @@ module ViewComponent
|
|
283
287
|
|
284
288
|
if handler.method(:call).parameters.length > 1
|
285
289
|
handler.call(self, template)
|
286
|
-
else
|
290
|
+
else
|
287
291
|
handler.call(OpenStruct.new(source: template, identifier: identifier, type: type))
|
288
292
|
end
|
289
293
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|