view_component 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of view_component might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f6cbdc740d6c9175742269ff9b13a759e28b188d2abcdda03d85bafff44ac7a
4
- data.tar.gz: a00eff317e112a844e65fb196e6a2e7832e0ff7b5ede73ba47196131d92f9d65
3
+ metadata.gz: '038805cb5a61ac698697344495e23064c227e169079586e1412f43aee0a7abde'
4
+ data.tar.gz: bb53f4c2407eec96e618aba01f4f35cfa564bfc8738c709af434c16a412457d8
5
5
  SHA512:
6
- metadata.gz: 68ac701e9c6814d9f6384e393b0ac9ac18a2646b85bef1e972a092bd252f7e573c4c5c6aea73056d75a6597d71076fb43e40ba6edd4eb1a73c88618881fc9705
7
- data.tar.gz: '099f69cfb27e52b9e337328c204fc512e1c151b562a22e94783a58ed99952856994575a9b5556f4a0ebf5c7b54012bfab55330956fc67478f19057784090894e'
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.1.0)
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.31.0)
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.present?
33
- attributes.map { |attr| "#{attr.name}:" }.join(", ")
34
- else
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
@@ -1,5 +1,7 @@
1
1
  class <%= class_name %>Component < <%= parent_class %>
2
+ <%- if initialize_signature -%>
2
3
  def initialize(<%= initialize_signature %>)
3
4
  <%= initialize_body %>
4
5
  end
6
+ <%- end -%>
5
7
  end
@@ -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], -1
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 # remove before upstreaming into Rails
290
+ else
287
291
  handler.call(OpenStruct.new(source: template, identifier: identifier, type: type))
288
292
  end
289
293
  end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 1
6
+ MINOR = 2
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
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.1.0
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-27 00:00:00.000000000 Z
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara